Skip to content

Commit

Permalink
fix(web): restore button in asset viewer (#8935)
Browse files Browse the repository at this point in the history
* fix(web): restore button added to trashed asset-view to restore single item

* fixed the asset-viewer menu to update upon restoration

* prettier formatting complete, testing passed

* chore: clean up

---------

Co-authored-by: Jason Rasmussen <[email protected]>
  • Loading branch information
ConnerWithAnE and jrasm91 authored Apr 20, 2024
1 parent 171b6bb commit 3abfe3c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
19 changes: 13 additions & 6 deletions web/src/lib/components/asset-viewer/asset-viewer-nav-bar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
mdiFolderDownloadOutline,
mdiHeart,
mdiHeartOutline,
mdiHistory,
mdiImageAlbum,
mdiImageMinusOutline,
mdiImageOutline,
Expand Down Expand Up @@ -52,6 +53,7 @@
type MenuItemEvent =
| 'addToAlbum'
| 'restoreAsset'
| 'addToSharedAlbum'
| 'asProfileImage'
| 'setAsAlbumCover'
Expand All @@ -70,6 +72,7 @@
delete: void;
toggleArchive: void;
addToAlbum: void;
restoreAsset: void;
addToSharedAlbum: void;
asProfileImage: void;
setAsAlbumCover: void;
Expand Down Expand Up @@ -208,12 +211,16 @@
{#if showDownloadButton}
<MenuOption icon={mdiFolderDownloadOutline} on:click={() => onMenuClick('download')} text="Download" />
{/if}
<MenuOption icon={mdiImageAlbum} on:click={() => onMenuClick('addToAlbum')} text="Add to album" />
<MenuOption
icon={mdiShareVariantOutline}
on:click={() => onMenuClick('addToSharedAlbum')}
text="Add to shared album"
/>
{#if asset.isTrashed}
<MenuOption icon={mdiHistory} on:click={() => onMenuClick('restoreAsset')} text="Restore" />
{:else}
<MenuOption icon={mdiImageAlbum} on:click={() => onMenuClick('addToAlbum')} text="Add to album" />
<MenuOption
icon={mdiShareVariantOutline}
on:click={() => onMenuClick('addToSharedAlbum')}
text="Add to shared album"
/>
{/if}

{#if isOwner}
{#if hasStackChildren}
Expand Down
18 changes: 18 additions & 0 deletions web/src/lib/components/asset-viewer/asset-viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
getActivityStatistics,
getAllAlbums,
runAssetJobs,
restoreAssets,
updateAsset,
updateAlbumInfo,
type ActivityResponseDto,
Expand Down Expand Up @@ -403,6 +404,22 @@
await handleGetAllAlbums();
};
const handleRestoreAsset = async () => {
try {
await restoreAssets({ bulkIdsDto: { ids: [asset.id] } });
asset.isTrashed = false;
dispatch('action', { type: AssetAction.RESTORE, asset });
notificationController.show({
type: NotificationType.Info,
message: `Restored asset`,
});
} catch (error) {
handleError(error, 'Error restoring asset');
}
};
const toggleArchive = async () => {
try {
const data = await updateAsset({
Expand Down Expand Up @@ -556,6 +573,7 @@
on:delete={() => trashOrDelete()}
on:favorite={toggleFavorite}
on:addToAlbum={() => openAlbumPicker(false)}
on:restoreAsset={() => handleRestoreAsset()}
on:addToSharedAlbum={() => openAlbumPicker(true)}
on:playMotionPhoto={() => (shouldPlayMotionPhoto = true)}
on:stopMotionPhoto={() => (shouldPlayMotionPhoto = false)}
Expand Down
1 change: 1 addition & 0 deletions web/src/lib/components/photos-page/asset-grid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
switch (action) {
case removeAction:
case AssetAction.TRASH:
case AssetAction.RESTORE:
case AssetAction.DELETE: {
// find the next asset to show or close the viewer
(await handleNext()) || (await handlePrevious()) || handleClose();
Expand Down
2 changes: 1 addition & 1 deletion web/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export enum AssetAction {
UNFAVORITE = 'unfavorite',
TRASH = 'trash',
DELETE = 'delete',
// RESTORE = 'restore',
RESTORE = 'restore',
ADD = 'add',
}

Expand Down

0 comments on commit 3abfe3c

Please sign in to comment.