Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(web): cleanup promise handling #7382

Merged
merged 31 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4143389
no-misused-promises
benmccann Feb 23, 2024
aa47b6d
no-floating-promises
benmccann Feb 23, 2024
b32c895
format
benmccann Feb 23, 2024
ef8d93e
revert for now
benmccann Feb 24, 2024
22a5359
remove load function
benmccann Feb 24, 2024
c14143c
require-await
benmccann Feb 24, 2024
d8b3702
revert a few no-floating-promises changes that would cause no-misused…
benmccann Feb 24, 2024
681c861
format
benmccann Feb 24, 2024
d85403e
fix a few more
benmccann Feb 25, 2024
e854f14
merge main
benmccann Feb 25, 2024
06cfff0
fix most remaining errors
benmccann Feb 25, 2024
a0f7e25
executor-queue
benmccann Feb 25, 2024
a13ef3b
executor-queue.spec
benmccann Feb 25, 2024
ae1a29b
remove duplicate comments by grouping rules
benmccann Feb 25, 2024
a1d744d
upgrade sveltekit and enforce rules
benmccann Feb 26, 2024
e3595ba
oops. move await
benmccann Feb 26, 2024
1dee3c1
try this
benmccann Feb 26, 2024
aa2ea01
just ignore for now since it's only a test
benmccann Feb 26, 2024
b3cf677
run in parallel
benmccann Feb 26, 2024
4654086
Update web/src/routes/admin/jobs-status/+page.svelte
benmccann Feb 26, 2024
c1d0c2c
remove Promise.resolve call
benmccann Feb 26, 2024
ee244f5
rename function
benmccann Feb 26, 2024
e64aa30
remove unnecessary warning silencing
benmccann Feb 26, 2024
2d0619b
make handleError sync
benmccann Feb 26, 2024
e45315f
merge main
benmccann Feb 26, 2024
17ac589
fix new errors from recently merged PR to main
benmccann Feb 26, 2024
a0a1d72
extract method
benmccann Feb 26, 2024
b235d3f
use handlePromiseError
benmccann Feb 26, 2024
ae6c53c
Merge branch 'main' of github.com:immich-app/immich into eslint
alextran1502 Feb 27, 2024
f6b74de
Merge branch 'main' of github.com:immich-app/immich into eslint
alextran1502 Feb 27, 2024
21fa9d3
Merge branch 'main' of github.com:immich-app/immich into eslint
alextran1502 Feb 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 13 additions & 7 deletions web/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
sourceType: 'module',
ecmaVersion: 2022,
extraFileExtensions: ['.svelte'],
project: ['./tsconfig.json'],
},
env: {
browser: true,
Expand All @@ -32,13 +33,6 @@ module.exports = {
NodeJS: true,
},
rules: {
'unicorn/no-useless-undefined': 'off',
'unicorn/prefer-spread': 'off',
'unicorn/no-null': 'off',
'unicorn/prevent-abbreviations': 'off',
'unicorn/no-nested-ternary': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/prefer-top-level-await': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
Expand All @@ -48,5 +42,17 @@ module.exports = {
},
],
curly: 2,
'unicorn/no-useless-undefined': 'off',
'unicorn/prefer-spread': 'off',
'unicorn/no-null': 'off',
'unicorn/prevent-abbreviations': 'off',
'unicorn/no-nested-ternary': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/prefer-top-level-await': 'off',
// TODO: set recommended-type-checked and remove these rules
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/require-await': 'error',
},
};
8 changes: 4 additions & 4 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@socket.io/component-emitter": "^3.1.0",
"@sveltejs/adapter-static": "^3.0.1",
"@sveltejs/enhanced-img": "^0.1.8",
"@sveltejs/kit": "^2.5.1",
"@sveltejs/kit": "^2.5.2",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/svelte": "^4.0.3",
Expand Down
3 changes: 1 addition & 2 deletions web/src/hooks.client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { isHttpError } from '@immich/sdk';
import type { HandleClientError } from '@sveltejs/kit';

const LOG_PREFIX = '[hooks.client.ts]';
const DEFAULT_MESSAGE = 'Hmm, not sure about that. Check the logs or open a ticket?';

const parseError = (error: unknown) => {
Expand All @@ -23,6 +22,6 @@ const parseError = (error: unknown) => {

export const handleError: HandleClientError = ({ error }) => {
const result = parseError(error);
console.error(`${LOG_PREFIX}:handleError ${result.message}`);
console.error(`[hooks.client.ts]:handleError ${result.message}`);
return result;
};
4 changes: 2 additions & 2 deletions web/src/lib/components/admin-page/jobs/jobs-panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
await handleCommand(jobId, dto);
};

const onConfirm = () => {
const onConfirm = async () => {
if (!confirmJob) {
return;
}
handleCommand(confirmJob, { command: JobCommand.Start, force: true });
await handleCommand(confirmJob, { command: JobCommand.Start, force: true });
confirmJob = null;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
});
};

const resetToDefault = async (configKeys: Array<keyof SystemConfigDto>) => {
const resetToDefault = (configKeys: Array<keyof SystemConfigDto>) => {
for (const key of configKeys) {
config = { ...config, [key]: defaultConfig[key] };
}
Expand Down
5 changes: 3 additions & 2 deletions web/src/lib/components/album-page/album-viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import { shouldIgnoreShortcut } from '$lib/utils/shortcut';
import { mdiFileImagePlusOutline, mdiFolderDownloadOutline } from '@mdi/js';
import UpdatePanel from '../shared-components/update-panel.svelte';
import { handlePromiseError } from '$lib/utils';

export let sharedLink: SharedLinkResponseDto;
export let user: UserResponseDto | undefined = undefined;
Expand All @@ -35,7 +36,7 @@

dragAndDropFilesStore.subscribe((value) => {
if (value.isDragging && value.files.length > 0) {
fileUploadHandler(value.files, album.id);
handlePromiseError(fileUploadHandler(value.files, album.id));
dragAndDropFilesStore.set({ isDragging: false, files: [] });
}
});
Expand Down Expand Up @@ -67,7 +68,7 @@

const onKeyboardPress = (event: KeyboardEvent) => handleKeyboardPress(event);

onMount(async () => {
onMount(() => {
document.addEventListener('keydown', onKeyboardPress);
});

Expand Down
8 changes: 4 additions & 4 deletions web/src/lib/components/asset-viewer/activity-viewer.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import Icon from '$lib/components/elements/icon.svelte';
import { timeBeforeShowLoadingSpinner } from '$lib/constants';
import { getAssetThumbnailUrl } from '$lib/utils';
import { getAssetThumbnailUrl, handlePromiseError } from '$lib/utils';
import { getAssetType } from '$lib/utils/asset-utils';
import { autoGrowHeight } from '$lib/utils/autogrow';
import { clickOutside } from '$lib/utils/click-outside';
Expand Down Expand Up @@ -79,7 +79,7 @@

$: {
if (assetId && previousAssetId != assetId) {
getReactions();
handlePromiseError(getReactions());
previousAssetId = assetId;
}
}
Expand All @@ -95,10 +95,10 @@
}
};

const handleEnter = (event: KeyboardEvent) => {
const handleEnter = async (event: KeyboardEvent) => {
if (event.key === 'Enter') {
event.preventDefault();
handleSendComment();
await handleSendComment();
return;
}
};
Expand Down
42 changes: 21 additions & 21 deletions web/src/lib/components/asset-viewer/asset-viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { SlideshowState, slideshowStore } from '$lib/stores/slideshow.store';
import { stackAssetsStore } from '$lib/stores/stacked-asset.store';
import { user } from '$lib/stores/user.store';
import { getAssetJobMessage, isSharedLink } from '$lib/utils';
import { getAssetJobMessage, isSharedLink, handlePromiseError } from '$lib/utils';
import { addAssetsToAlbum, downloadFile } from '$lib/utils/asset-utils';
import { handleError } from '$lib/utils/handle-error';
import { shouldIgnoreShortcut } from '$lib/utils/shortcut';
Expand Down Expand Up @@ -174,8 +174,8 @@

$: {
if (isShared && asset.id) {
getFavorite();
getNumberOfComments();
handlePromiseError(getFavorite());
handlePromiseError(getNumberOfComments());
}
}

Expand All @@ -184,9 +184,9 @@
if (value === SlideshowState.PlaySlideshow) {
slideshowHistory.reset();
slideshowHistory.queue(asset.id);
handlePlaySlideshow();
handlePromiseError(handlePlaySlideshow());
} else if (value === SlideshowState.StopSlideshow) {
handleStopSlideshow();
handlePromiseError(handleStopSlideshow());
}
});

Expand Down Expand Up @@ -226,7 +226,7 @@
}
});

$: asset.id && !sharedLink && handleGetAllAlbums(); // Update the album information when the asset ID changes
$: asset.id && !sharedLink && handlePromiseError(handleGetAllAlbums()); // Update the album information when the asset ID changes

const handleGetAllAlbums = async () => {
if (isSharedLink()) {
Expand All @@ -247,7 +247,7 @@
isShowActivity = !isShowActivity;
};

const handleKeypress = (event: KeyboardEvent) => {
const handleKeypress = async (event: KeyboardEvent) => {
if (shouldIgnoreShortcut(event)) {
return;
}
Expand All @@ -264,7 +264,7 @@
case 'a':
case 'A': {
if (shiftKey) {
toggleArchive();
await toggleArchive();
}
return;
}
Expand All @@ -273,18 +273,18 @@
return;
}
case 'ArrowRight': {
navigateAssetForward();
await navigateAssetForward();
return;
}
case 'd':
case 'D': {
if (shiftKey) {
downloadFile(asset);
await downloadFile(asset);
}
return;
}
case 'Delete': {
trashOrDelete(shiftKey);
await trashOrDelete(shiftKey);
return;
}
case 'Escape': {
Expand All @@ -296,7 +296,7 @@
return;
}
case 'f': {
toggleFavorite();
await toggleFavorite();
return;
}
case 'i': {
Expand Down Expand Up @@ -326,7 +326,7 @@

slideshowHistory.queue(asset.id);

setAssetId(asset.id);
await setAssetId(asset.id);
$restartSlideshowProgress = true;
};

Expand Down Expand Up @@ -369,17 +369,17 @@
$isShowDetail = !$isShowDetail;
};

const trashOrDelete = (force: boolean = false) => {
const trashOrDelete = async (force: boolean = false) => {
if (force || !isTrashEnabled) {
if ($showDeleteModal) {
isShowDeleteConfirmation = true;
return;
}
deleteAsset();
await deleteAsset();
return;
}

trashAsset();
await trashAsset();
return;
};

Expand Down Expand Up @@ -432,7 +432,7 @@
message: asset.isFavorite ? `Added to favorites` : `Removed from favorites`,
});
} catch (error) {
await handleError(error, `Unable to ${asset.isFavorite ? `add asset to` : `remove asset from`} favorites`);
handleError(error, `Unable to ${asset.isFavorite ? `add asset to` : `remove asset from`} favorites`);
}
};

Expand Down Expand Up @@ -472,7 +472,7 @@
message: asset.isArchived ? `Added to archive` : `Removed from archive`,
});
} catch (error) {
await handleError(error, `Unable to ${asset.isArchived ? `add asset to` : `remove asset from`} archive`);
handleError(error, `Unable to ${asset.isArchived ? `add asset to` : `remove asset from`} archive`);
}
};

Expand All @@ -481,7 +481,7 @@
await runAssetJobs({ assetJobsDto: { assetIds: [asset.id], name } });
notificationController.show({ type: NotificationType.Info, message: getAssetJobMessage(name) });
} catch (error) {
await handleError(error, `Unable to submit job`);
handleError(error, `Unable to submit job`);
}
};

Expand All @@ -492,7 +492,7 @@
let assetViewerHtmlElement: HTMLElement;

const slideshowHistory = new SlideshowHistory((assetId: string) => {
setAssetId(assetId);
handlePromiseError(setAssetId(assetId));
$restartSlideshowProgress = true;
});

Expand Down Expand Up @@ -550,7 +550,7 @@
dispatch('close');
notificationController.show({ type: NotificationType.Info, message: 'Un-stacked', timeout: 1500 });
} catch (error) {
await handleError(error, `Unable to unstack`);
handleError(error, `Unable to unstack`);
}
};
</script>
Expand Down
6 changes: 3 additions & 3 deletions web/src/lib/components/asset-viewer/detail-panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { featureFlags } from '$lib/stores/server-config.store';
import { user } from '$lib/stores/user.store';
import { websocketEvents } from '$lib/stores/websocket';
import { getAssetThumbnailUrl, getPeopleThumbnailUrl, isSharedLink } from '$lib/utils';
import { getAssetThumbnailUrl, getPeopleThumbnailUrl, isSharedLink, handlePromiseError } from '$lib/utils';
import { delay, getAssetFilename } from '$lib/utils/asset-utils';
import { autoGrowHeight } from '$lib/utils/autogrow';
import { clickOutside } from '$lib/utils/click-outside';
Expand Down Expand Up @@ -78,7 +78,7 @@
originalDescription = description;
};

$: handleNewAsset(asset);
$: handlePromiseError(handleNewAsset(asset));

$: latlng = (() => {
const lat = asset.exifInfo?.latitude;
Expand Down Expand Up @@ -113,7 +113,7 @@
switch (event.key) {
case 'Enter': {
if (ctrl && event.target === textArea) {
handleFocusOut();
await handleFocusOut();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions web/src/lib/components/asset-viewer/photo-viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { boundingBoxesArray } from '$lib/stores/people.store';
import { alwaysLoadOriginalFile } from '$lib/stores/preferences.store';
import { photoZoomState } from '$lib/stores/zoom-image.store';
import { getKey } from '$lib/utils';
import { getKey, handlePromiseError } from '$lib/utils';
import { isWebCompatibleImage } from '$lib/utils/asset-utils';
import { getBoundingBox } from '$lib/utils/people-utils';
import { shouldIgnoreShortcut } from '$lib/utils/shortcut';
Expand Down Expand Up @@ -102,7 +102,7 @@
}
};

const doZoomImage = async () => {
const doZoomImage = () => {
setZoomImageWheelState({
currentZoom: $zoomImageWheelState.currentZoom === 1 ? 2 : 1,
});
Expand All @@ -120,7 +120,7 @@
if (state.currentZoom > 1 && isWebCompatibleImage(asset) && !hasZoomed && !$alwaysLoadOriginalFile) {
hasZoomed = true;

loadAssetData({ loadOriginal: true });
handlePromiseError(loadAssetData({ loadOriginal: true }));
jrasm91 marked this conversation as resolved.
Show resolved Hide resolved
}
});
</script>
Expand Down
2 changes: 1 addition & 1 deletion web/src/lib/components/asset-viewer/video-viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
video.muted = false;
dispatch('onVideoStarted');
} catch (error) {
await handleError(error, 'Unable to play video');
handleError(error, 'Unable to play video');
} finally {
isVideoLoading = false;
}
Expand Down