mirror of
https://github.com/immich-app/immich.git
synced 2025-12-21 01:11:16 +03:00
chore(web): cleanup promise handling (#7382)
* no-misused-promises * no-floating-promises * format * revert for now * remove load function * require-await * revert a few no-floating-promises changes that would cause no-misused-promises failures * format * fix a few more * fix most remaining errors * executor-queue * executor-queue.spec * remove duplicate comments by grouping rules * upgrade sveltekit and enforce rules * oops. move await * try this * just ignore for now since it's only a test * run in parallel * Update web/src/routes/admin/jobs-status/+page.svelte Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> * remove Promise.resolve call * rename function * remove unnecessary warning silencing * make handleError sync * fix new errors from recently merged PR to main * extract method * use handlePromiseError --------- Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
@@ -27,18 +27,22 @@
|
||||
showAlbumPicker = false;
|
||||
|
||||
const assetIds = [...getAssets()].map((asset) => asset.id);
|
||||
createAlbum({ createAlbumDto: { albumName, assetIds } }).then((response) => {
|
||||
const { id, albumName } = response;
|
||||
createAlbum({ createAlbumDto: { albumName, assetIds } })
|
||||
.then(async (response) => {
|
||||
const { id, albumName } = response;
|
||||
|
||||
notificationController.show({
|
||||
message: `Added ${assetIds.length} to ${albumName}`,
|
||||
type: NotificationType.Info,
|
||||
notificationController.show({
|
||||
message: `Added ${assetIds.length} to ${albumName}`,
|
||||
type: NotificationType.Info,
|
||||
});
|
||||
|
||||
clearSelect();
|
||||
|
||||
await goto(`${AppRoute.ALBUMS}/${id}`);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(`[add-to-album.svelte]:handleAddToNewAlbum ${error}`, error);
|
||||
});
|
||||
|
||||
clearSelect();
|
||||
|
||||
goto(`${AppRoute.ALBUMS}/${id}`);
|
||||
});
|
||||
};
|
||||
|
||||
const handleAddToAlbum = async (album: AlbumResponseDto) => {
|
||||
|
||||
@@ -80,13 +80,17 @@
|
||||
});
|
||||
}
|
||||
|
||||
const assetClickHandler = (asset: AssetResponseDto, assetsInDateGroup: AssetResponseDto[], groupTitle: string) => {
|
||||
const assetClickHandler = async (
|
||||
asset: AssetResponseDto,
|
||||
assetsInDateGroup: AssetResponseDto[],
|
||||
groupTitle: string,
|
||||
) => {
|
||||
if (isSelectionMode || $isMultiSelectState) {
|
||||
assetSelectHandler(asset, assetsInDateGroup, groupTitle);
|
||||
return;
|
||||
}
|
||||
|
||||
assetViewingStore.setAssetId(asset.id);
|
||||
await assetViewingStore.setAssetId(asset.id);
|
||||
};
|
||||
|
||||
const handleSelectGroup = (title: string, assets: AssetResponseDto[]) => dispatch('select', { title, assets });
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
import ShowShortcuts from '../shared-components/show-shortcuts.svelte';
|
||||
import AssetDateGroup from './asset-date-group.svelte';
|
||||
import DeleteAssetDialog from './delete-asset-dialog.svelte';
|
||||
import { handlePromiseError } from '$lib/utils';
|
||||
|
||||
export let isSelectionMode = false;
|
||||
export let singleSelect = false;
|
||||
@@ -47,19 +48,19 @@
|
||||
$: isEmpty = $assetStore.initialized && $assetStore.buckets.length === 0;
|
||||
$: idsSelectedAssets = [...$selectedAssets].filter((a) => !a.isExternal).map((a) => a.id);
|
||||
|
||||
const onKeyboardPress = (event: KeyboardEvent) => handleKeyboardPress(event);
|
||||
const dispatch = createEventDispatcher<{ select: AssetResponseDto; escape: void }>();
|
||||
|
||||
const onKeydown = (event: KeyboardEvent) => handlePromiseError(handleKeyboardPress(event));
|
||||
onMount(async () => {
|
||||
showSkeleton = false;
|
||||
document.addEventListener('keydown', onKeyboardPress);
|
||||
document.addEventListener('keydown', onKeydown);
|
||||
assetStore.connect();
|
||||
await assetStore.init(viewport);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
if (browser) {
|
||||
document.removeEventListener('keydown', onKeyboardPress);
|
||||
document.removeEventListener('keydown', onKeydown);
|
||||
}
|
||||
|
||||
if ($showAssetViewer) {
|
||||
@@ -69,13 +70,13 @@
|
||||
assetStore.disconnect();
|
||||
});
|
||||
|
||||
const trashOrDelete = (force: boolean = false) => {
|
||||
const trashOrDelete = async (force: boolean = false) => {
|
||||
isShowDeleteConfirmation = false;
|
||||
deleteAssets(!(isTrashEnabled && !force), (assetId) => assetStore.removeAsset(assetId), idsSelectedAssets);
|
||||
await deleteAssets(!(isTrashEnabled && !force), (assetId) => assetStore.removeAsset(assetId), idsSelectedAssets);
|
||||
assetInteractionStore.clearMultiselect();
|
||||
};
|
||||
|
||||
const handleKeyboardPress = (event: KeyboardEvent) => {
|
||||
const handleKeyboardPress = async (event: KeyboardEvent) => {
|
||||
if ($isSearchEnabled || shouldIgnoreShortcut(event)) {
|
||||
return;
|
||||
}
|
||||
@@ -98,7 +99,7 @@
|
||||
}
|
||||
case '/': {
|
||||
event.preventDefault();
|
||||
goto(AppRoute.EXPLORE);
|
||||
await goto(AppRoute.EXPLORE);
|
||||
return;
|
||||
}
|
||||
case 'Delete': {
|
||||
@@ -112,7 +113,7 @@
|
||||
force = true;
|
||||
}
|
||||
|
||||
trashOrDelete(force);
|
||||
await trashOrDelete(force);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -126,12 +127,12 @@
|
||||
}
|
||||
};
|
||||
|
||||
function intersectedHandler(event: CustomEvent) {
|
||||
async function intersectedHandler(event: CustomEvent) {
|
||||
const element_ = event.detail.container as HTMLElement;
|
||||
const target = element_.firstChild as HTMLElement;
|
||||
if (target) {
|
||||
const bucketDate = target.id.split('_')[1];
|
||||
assetStore.loadBucket(bucketDate, event.detail.position);
|
||||
await assetStore.loadBucket(bucketDate, event.detail.position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +143,7 @@
|
||||
const handlePrevious = async () => {
|
||||
const previousAsset = await assetStore.getPreviousAssetId($viewingAsset.id);
|
||||
if (previousAsset) {
|
||||
assetViewingStore.setAssetId(previousAsset);
|
||||
await assetViewingStore.setAssetId(previousAsset);
|
||||
}
|
||||
|
||||
return !!previousAsset;
|
||||
@@ -151,7 +152,7 @@
|
||||
const handleNext = async () => {
|
||||
const nextAsset = await assetStore.getNextAssetId($viewingAsset.id);
|
||||
if (nextAsset) {
|
||||
assetViewingStore.setAssetId(nextAsset);
|
||||
await assetViewingStore.setAssetId(nextAsset);
|
||||
}
|
||||
|
||||
return !!nextAsset;
|
||||
@@ -369,7 +370,7 @@
|
||||
<DeleteAssetDialog
|
||||
size={idsSelectedAssets.length}
|
||||
on:cancel={() => (isShowDeleteConfirmation = false)}
|
||||
on:confirm={() => trashOrDelete(true)}
|
||||
on:confirm={() => handlePromiseError(trashOrDelete(true))}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user