mirror of
https://github.com/immich-app/immich.git
synced 2026-03-07 18:47:31 +03:00
feat(web): add archive shortcut to grid (#9499)
* feat(web): add archive shortcut to grid * Fix error * Don't unnecessarily pass parameter * Use an existing function to close the menu * Deduplicate type --------- Co-authored-by: Alex <alex.tran1502@gmail.com> Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
@@ -1,15 +1,10 @@
|
||||
<script lang="ts">
|
||||
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
|
||||
import {
|
||||
NotificationType,
|
||||
notificationController,
|
||||
} from '$lib/components/shared-components/notification/notification';
|
||||
import type { OnArchive } from '$lib/utils/actions';
|
||||
import { handleError } from '$lib/utils/handle-error';
|
||||
import { updateAssets } from '@immich/sdk';
|
||||
import { mdiArchiveArrowDownOutline, mdiArchiveArrowUpOutline, mdiTimerSand } from '@mdi/js';
|
||||
import MenuOption from '../../shared-components/context-menu/menu-option.svelte';
|
||||
import { getAssetControlContext } from '../asset-select-control-bar.svelte';
|
||||
import { archiveAssets } from '$lib/utils/asset-utils';
|
||||
import { t } from 'svelte-i18n';
|
||||
|
||||
export let onArchive: OnArchive;
|
||||
@@ -26,33 +21,14 @@
|
||||
|
||||
const handleArchive = async () => {
|
||||
const isArchived = !unarchive;
|
||||
const assets = [...getOwnedAssets()].filter((asset) => asset.isArchived !== isArchived);
|
||||
loading = true;
|
||||
|
||||
try {
|
||||
const assets = [...getOwnedAssets()].filter((asset) => asset.isArchived !== isArchived);
|
||||
const ids = assets.map(({ id }) => id);
|
||||
|
||||
if (ids.length > 0) {
|
||||
await updateAssets({ assetBulkUpdateDto: { ids, isArchived } });
|
||||
}
|
||||
|
||||
for (const asset of assets) {
|
||||
asset.isArchived = isArchived;
|
||||
}
|
||||
|
||||
const ids = await archiveAssets(assets, isArchived);
|
||||
if (ids) {
|
||||
onArchive(ids, isArchived);
|
||||
|
||||
notificationController.show({
|
||||
message: `${isArchived ? $t('archived') : $t('unarchived')} ${ids.length}`,
|
||||
type: NotificationType.Info,
|
||||
});
|
||||
|
||||
clearSelect();
|
||||
} catch (error) {
|
||||
handleError(error, `Unable to ${isArchived ? 'archive' : 'unarchive'}`);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
loading = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user