refactor(web): asset viewer actions (#5488)

This commit is contained in:
Jason Rasmussen 2023-12-04 19:18:28 -05:00 committed by GitHub
parent 56aed8246d
commit 22d79850f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 30 deletions

View file

@ -128,13 +128,28 @@
const handleClose = () => assetViewingStore.showAssetViewer(false);
const handleAction = async (asset: AssetResponseDto, action: AssetAction) => {
if (removeAction === action) {
// find the next asset to show or close the viewer
(await handleNext()) || (await handlePrevious()) || handleClose();
const handleAction = async (action: AssetAction, asset: AssetResponseDto) => {
switch (action) {
case removeAction:
case AssetAction.TRASH:
case AssetAction.DELETE:
// find the next asset to show or close the viewer
(await handleNext()) || (await handlePrevious()) || handleClose();
// delete after find the next one
assetStore.removeAsset(asset.id);
// delete after find the next one
assetStore.removeAsset(asset.id);
break;
case AssetAction.ARCHIVE:
case AssetAction.UNARCHIVE:
case AssetAction.FAVORITE:
case AssetAction.UNFAVORITE:
assetStore.updateAsset(asset);
break;
case AssetAction.ADD:
assetStore.addAsset(asset);
break;
}
};
@ -402,11 +417,7 @@
on:previous={() => handlePrevious()}
on:next={() => handleNext()}
on:close={() => handleClose()}
on:archived={({ detail: asset }) => handleAction(asset, AssetAction.ARCHIVE)}
on:unarchived={({ detail: asset }) => handleAction(asset, AssetAction.UNARCHIVE)}
on:favorite={({ detail: asset }) => handleAction(asset, AssetAction.FAVORITE)}
on:unfavorite={({ detail: asset }) => handleAction(asset, AssetAction.UNFAVORITE)}
on:unstack={() => handleClose()}
on:action={({ detail: action }) => handleAction(action.type, action.asset)}
/>
{/if}
</Portal>