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:
Ben McCann
2024-02-27 08:37:37 -08:00
committed by GitHub
parent 57f25855d3
commit 907a95a746
70 changed files with 312 additions and 282 deletions
+3 -3
View File
@@ -196,7 +196,7 @@
const handleCreateAlbum = async () => {
const newAlbum = await createAlbum();
if (newAlbum) {
goto(`${AppRoute.ALBUMS}/${newAlbum.id}`);
await goto(`${AppRoute.ALBUMS}/${newAlbum.id}`);
}
};
@@ -204,8 +204,8 @@
return new Date(dateString).toLocaleDateString($locale, dateFormats.album);
};
onMount(() => {
removeAlbumsIfEmpty();
onMount(async () => {
await removeAlbumsIfEmpty();
});
const removeAlbumsIfEmpty = async () => {
@@ -220,12 +220,11 @@
onMount(async () => {
if (album.sharedUsers.length > 0) {
getFavorite();
getNumberOfComments();
await Promise.all([getFavorite(), getNumberOfComments()]);
}
});
const handleKeypress = async (event: KeyboardEvent) => {
const handleKeypress = (event: KeyboardEvent) => {
if (event.target !== textArea) {
return;
}
@@ -242,12 +241,12 @@
const handleStartSlideshow = async () => {
const asset = $slideshowShuffle ? await assetStore.getRandomAsset() : assetStore.assets[0];
if (asset) {
setAssetId(asset.id);
await setAssetId(asset.id);
$slideshowState = SlideshowState.PlaySlideshow;
}
};
const handleEscape = () => {
const handleEscape = async () => {
if (viewMode === ViewMode.SELECT_USERS) {
viewMode = ViewMode.VIEW;
return;
@@ -275,7 +274,7 @@
assetInteractionStore.clearMultiselect();
return;
}
goto(backUrl);
await goto(backUrl);
return;
};
@@ -371,7 +370,7 @@
const handleRemoveUser = async (userId: string) => {
if (userId == 'me' || userId === $user.id) {
goto(backUrl);
await goto(backUrl);
return;
}
@@ -390,7 +389,7 @@
const handleRemoveAlbum = async () => {
try {
await deleteAlbum({ id: album.id });
goto(backUrl);
await goto(backUrl);
} catch (error) {
handleError(error, 'Unable to delete album');
} finally {
@@ -2,7 +2,7 @@ import { AppRoute } from '$lib/constants';
import { redirect } from '@sveltejs/kit';
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ params }) => {
export const load: PageLoad = ({ params }) => {
const albumId = params.albumId;
if (albumId) {
+4 -7
View File
@@ -1,5 +1,6 @@
import type { OnShowContextMenuDetail } from '$lib/components/album-page/album-card';
import { notificationController, NotificationType } from '$lib/components/shared-components/notification/notification';
import { asyncTimeout } from '$lib/utils';
import { handleError } from '$lib/utils/handle-error';
import { createAlbum, deleteAlbum, getAllAlbums, type AlbumResponseDto } from '@immich/sdk';
import { derived, get, writable } from 'svelte/store';
@@ -20,9 +21,8 @@ export const useAlbums = (properties: AlbumsProperties) => {
// Delete album that has no photos and is named ''
for (const album of data) {
if (album.albumName === '' && album.assetCount === 0) {
setTimeout(async () => {
await handleDeleteAlbum(album);
}, 500);
await asyncTimeout(500);
await handleDeleteAlbum(album);
}
}
} catch {
@@ -46,10 +46,7 @@ export const useAlbums = (properties: AlbumsProperties) => {
albums.set(get(albums).filter(({ id }) => id !== albumToDelete.id));
}
async function showAlbumContextMenu(
contextMenuDetail: OnShowContextMenuDetail,
album: AlbumResponseDto,
): Promise<void> {
function showAlbumContextMenu(contextMenuDetail: OnShowContextMenuDetail, album: AlbumResponseDto): void {
contextMenuTargetAlbum.set(album);
contextMenuPosition.set({