Skip to content

chore: Refactor Edit Album Modal #18653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions web/src/lib/components/album-page/albums-list.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@

let albumGroupOption: string = $state(AlbumGroupBy.None);

let albumToEdit: AlbumResponseDto | null = $state(null);
let albumToShare: AlbumResponseDto | null = $state(null);
let albumToDelete: AlbumResponseDto | null = null;

Expand Down Expand Up @@ -257,9 +256,14 @@
await deleteSelectedAlbum();
};

const handleEdit = (album: AlbumResponseDto) => {
albumToEdit = album;
const handleEdit = async (album: AlbumResponseDto) => {
closeAlbumContextMenu();
const editedAlbum = await modalManager.show(EditAlbumForm, {
album,
});
if (editedAlbum) {
successEditAlbumInfo(editedAlbum);
}
};

const deleteSelectedAlbum = async () => {
Expand Down Expand Up @@ -305,8 +309,6 @@
};

const successEditAlbumInfo = (album: AlbumResponseDto) => {
albumToEdit = null;

notificationController.show({
message: $t('album_info_updated'),
type: NotificationType.Info,
Expand Down Expand Up @@ -422,15 +424,3 @@
<MenuOption icon={mdiDeleteOutline} text={$t('delete')} onClick={() => setAlbumToDelete()} />
{/if}
</RightClickContextMenu>

{#if allowEdit}
<!-- Edit Modal -->
{#if albumToEdit}
<EditAlbumForm
album={albumToEdit}
onEditSuccess={successEditAlbumInfo}
onCancel={() => (albumToEdit = null)}
onClose={() => (albumToEdit = null)}
/>
{/if}
{/if}
10 changes: 4 additions & 6 deletions web/src/lib/components/forms/edit-album-form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@

interface Props {
album: AlbumResponseDto;
onEditSuccess?: ((album: AlbumResponseDto) => unknown) | undefined;
onCancel?: (() => unknown) | undefined;
onClose: () => void;
onClose: (album?: AlbumResponseDto) => void;
}

let { album = $bindable(), onEditSuccess = undefined, onCancel = undefined, onClose }: Props = $props();
let { album = $bindable(), onClose }: Props = $props();

let albumName = $state(album.albumName);
let description = $state(album.description);
Expand All @@ -32,7 +30,7 @@
});
album.albumName = albumName;
album.description = description;
onEditSuccess?.(album);
onClose(album);
} catch (error) {
handleError(error, $t('errors.unable_to_update_album_info'));
} finally {
Expand Down Expand Up @@ -71,7 +69,7 @@

<ModalFooter>
<div class="flex gap-2 w-full">
<Button shape="round" color="secondary" fullWidth onclick={() => onCancel?.()}>{$t('cancel')}</Button>
<Button shape="round" color="secondary" fullWidth onclick={() => onClose()}>{$t('cancel')}</Button>
<Button shape="round" type="submit" fullWidth disabled={isSubmitting} form="edit-album-form">{$t('save')}</Button>
</div>
</ModalFooter>
Expand Down