Skip to content

Commit

Permalink
chore(web): migration svelte 5 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
alextran1502 committed Nov 2, 2024
1 parent f308e01 commit 1c69e9f
Show file tree
Hide file tree
Showing 30 changed files with 503 additions and 498 deletions.
8 changes: 3 additions & 5 deletions web/src/lib/components/admin-page/jobs/jobs-panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<!-- @migration-task Error while migrating Svelte code: Unexpected token -->
<!-- @migration-task Error while migrating Svelte code: Unexpected token -->
<!-- @migration-task Error while migrating Svelte code: Unexpected token -->
<!-- @migration-task Error while migrating Svelte code: Unexpected token -->
<!-- @migration-task Error while migrating Svelte code: Unexpected token -->
<script lang="ts">
import {
notificationController,
Expand Down Expand Up @@ -64,8 +62,7 @@
await handleCommand(jobId, dto);
};
// svelte-ignore reactive_declaration_non_reactive_property
$: jobDetails = <Partial<Record<JobName, JobDetails>>>{
let jobDetails = <Partial<Record<JobName, JobDetails>>>{
[JobName.ThumbnailGeneration]: {
icon: mdiFileJpgBox,
title: $getJobName(JobName.ThumbnailGeneration),
Expand Down Expand Up @@ -150,7 +147,8 @@
missingText: $t('missing'),
},
};
$: jobList = Object.entries(jobDetails) as [JobName, JobDetails][];
let jobList = Object.entries(jobDetails) as [JobName, JobDetails][];
async function handleCommand(jobId: JobName, jobCommand: JobCommandDto) {
const title = jobDetails[jobId]?.title;
Expand Down
60 changes: 35 additions & 25 deletions web/src/lib/components/asset-viewer/asset-viewer-nav-bar.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot making the component unusable -->
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot making the component unusable -->
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot making the component unusable -->
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot making the component unusable -->
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot making the component unusable -->
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot making the component unusable -->
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot making the component unusable -->
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot making the component unusable -->
<script lang="ts">
import { goto } from '$app/navigation';
import type { OnAction } from '$lib/components/asset-viewer/actions/action';
Expand Down Expand Up @@ -53,24 +45,42 @@
import { canCopyImageToClipboard } from '$lib/utils/asset-utils';
import { t } from 'svelte-i18n';
export let asset: AssetResponseDto;
export let album: AlbumResponseDto | null = null;
export let stack: StackResponseDto | null = null;
export let showDetailButton: boolean;
export let showSlideshow = false;
export let onZoomImage: () => void;
export let onCopyImage: () => void;
export let onAction: OnAction;
export let onRunJob: (name: AssetJobName) => void;
export let onPlaySlideshow: () => void;
export let onShowDetail: () => void;
// export let showEditorHandler: () => void;
export let onClose: () => void;
interface Props {
asset: AssetResponseDto;
album?: AlbumResponseDto | null;
stack?: StackResponseDto | null;
showDetailButton: boolean;
showSlideshow?: boolean;
onZoomImage: () => void;
onCopyImage: () => void;
onAction: OnAction;
onRunJob: (name: AssetJobName) => void;
onPlaySlideshow: () => void;
onShowDetail: () => void;
// export let showEditorHandler: () => void;
onClose: () => void;
motionPhoto?: import('svelte').Snippet;
}
let {
asset,
album = null,
stack = null,
showDetailButton,
showSlideshow = false,
onZoomImage,
onCopyImage,
onAction,
onRunJob,
onPlaySlideshow,
onShowDetail,
onClose,
motionPhoto,
}: Props = $props();
const sharedLink = getSharedLink();
$: isOwner = $user && asset.ownerId === $user?.id;
// svelte-ignore reactive_declaration_non_reactive_property
$: showDownloadButton = sharedLink ? sharedLink.allowDownload : !asset.isOffline;
let isOwner = $derived($user && asset.ownerId === $user?.id);
let showDownloadButton = $derived(sharedLink ? sharedLink.allowDownload : !asset.isOffline);
// $: showEditorButton =
// isOwner &&
// asset.type === AssetTypeEnum.Image &&
Expand Down Expand Up @@ -99,7 +109,7 @@
<CircleIconButton color="alert" icon={mdiAlertOutline} on:click={onShowDetail} title={$t('asset_offline')} />
{/if}
{#if asset.livePhotoVideoId}
<slot name="motion-photo" />
{@render motionPhoto?.()}
{/if}
{#if asset.type === AssetTypeEnum.Image}
<CircleIconButton
Expand Down
59 changes: 24 additions & 35 deletions web/src/lib/components/asset-viewer/asset-viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
onClose: (dto: { asset: AssetResponseDto }) => void;
onNext: () => void;
onPrevious: () => void;
copyImage?: () => void;
}
let {
Expand All @@ -77,7 +78,8 @@
reactions = $bindable([]),
onClose,
onNext,
onPrevious
onPrevious,
copyImage = $bindable(),
}: Props = $props();
const { setAsset } = assetViewingStore;
Expand All @@ -99,15 +101,13 @@
let isShowActivity = $state(false);
let isShowEditor = $state(false);
let isLiked: ActivityResponseDto | null = $state(null);
let numberOfComments: number = $state();
let fullscreenElement: Element = $state();
let numberOfComments = $state(0);
let fullscreenElement = $state<Element>();
let unsubscribes: (() => void)[] = [];
let selectedEditType: string = $state('');
let stack: StackResponseDto | null = $state(null);
let zoomToggle = $state(() => void 0);
let copyImage: () => Promise<void> = $state();
const refreshStack = async () => {
if (isSharedLink()) {
Expand All @@ -127,8 +127,6 @@
}
};
const handleAddComment = () => {
numberOfComments++;
updateNumberOfComments(1);
Expand Down Expand Up @@ -194,7 +192,6 @@
}
};
onMount(async () => {
unsubscribes.push(
websocketEvents.on('on_upload_success', onAssetUpdate),
Expand Down Expand Up @@ -237,7 +234,6 @@
}
});
const handleGetAllAlbums = async () => {
if (isSharedLink()) {
return;
Expand Down Expand Up @@ -336,7 +332,7 @@
* Slide show mode
*/
let assetViewerHtmlElement: HTMLElement = $state();
let assetViewerHtmlElement = $state<HTMLElement>();
const slideshowHistory = new SlideshowHistory((asset) => {
setAsset(asset);
Expand All @@ -351,7 +347,7 @@
const handlePlaySlideshow = async () => {
try {
await assetViewerHtmlElement.requestFullscreen?.();
await assetViewerHtmlElement?.requestFullscreen?.();
} catch (error) {
handleError(error, $t('errors.unable_to_enter_fullscreen'));
$slideshowState = SlideshowState.StopSlideshow;
Expand Down Expand Up @@ -442,19 +438,13 @@
onShowDetail={toggleDetailPanel}
onClose={closeViewer}
>
<!-- @migration-task: migrate this slot by hand, `motion-photo` is an invalid identifier -->
<!-- @migration-task: migrate this slot by hand, `motion-photo` is an invalid identifier -->
<!-- @migration-task: migrate this slot by hand, `motion-photo` is an invalid identifier -->
<!-- @migration-task: migrate this slot by hand, `motion-photo` is an invalid identifier -->
<!-- @migration-task: migrate this slot by hand, `motion-photo` is an invalid identifier -->
<!-- @migration-task: migrate this slot by hand, `motion-photo` is an invalid identifier -->
<!-- @migration-task: migrate this slot by hand, `motion-photo` is an invalid identifier -->
<!-- @migration-task: migrate this slot by hand, `motion-photo` is an invalid identifier -->
<MotionPhotoAction
slot="motion-photo"
isPlaying={shouldPlayMotionPhoto}
onClick={(shouldPlay) => (shouldPlayMotionPhoto = shouldPlay)}
/>
{#snippet motionPhoto()}
<MotionPhotoAction

isPlaying={shouldPlayMotionPhoto}
onClick={(shouldPlay) => (shouldPlayMotionPhoto = shouldPlay)}
/>
{/snippet}
</AssetViewerNavBar>
</div>
{/if}
Expand All @@ -471,7 +461,7 @@
<div class="z-[1000] absolute w-full flex">
<SlideshowBar
{isFullScreen}
onSetToFullScreen={() => assetViewerHtmlElement.requestFullscreen?.()}
onSetToFullScreen={() => assetViewerHtmlElement?.requestFullscreen?.()}
onPrevious={() => navigateAsset('previous')}
onNext={() => navigateAsset('next')}
onClose={() => ($slideshowState = SlideshowState.StopSlideshow)}
Expand All @@ -489,7 +479,7 @@
{preloadAssets}
onPreviousAsset={() => navigateAsset('previous')}
onNextAsset={() => navigateAsset('next')}
on:close={closeViewer}
onClose={closeViewer}
haveFadeTransition={false}
{sharedLink}
/>
Expand All @@ -501,9 +491,9 @@
loopVideo={true}
onPreviousAsset={() => navigateAsset('previous')}
onNextAsset={() => navigateAsset('next')}
on:close={closeViewer}
on:onVideoEnded={() => navigateAsset()}
on:onVideoStarted={handleVideoStarted}
onClose={closeViewer}
onVideoEnded={() => navigateAsset()}
onVideoStarted={handleVideoStarted}
/>
{/if}
{/key}
Expand All @@ -518,8 +508,7 @@
loopVideo={$slideshowState !== SlideshowState.PlaySlideshow}
onPreviousAsset={() => navigateAsset('previous')}
onNextAsset={() => navigateAsset('next')}
on:close={closeViewer}
on:onVideoEnded={() => (shouldPlayMotionPhoto = false)}
onVideoEnded={() => (shouldPlayMotionPhoto = false)}
/>
{:else if asset.exifInfo?.projectionType === ProjectionType.EQUIRECTANGULAR || (asset.originalPath && asset.originalPath
.toLowerCase()
Expand All @@ -535,7 +524,7 @@
{preloadAssets}
onPreviousAsset={() => navigateAsset('previous')}
onNextAsset={() => navigateAsset('next')}
on:close={closeViewer}
onClose={closeViewer}
{sharedLink}
haveFadeTransition={$slideshowState === SlideshowState.None || $slideshowTransition}
/>
Expand All @@ -548,9 +537,9 @@
loopVideo={$slideshowState !== SlideshowState.PlaySlideshow}
onPreviousAsset={() => navigateAsset('previous')}
onNextAsset={() => navigateAsset('next')}
on:close={closeViewer}
on:onVideoEnded={() => navigateAsset()}
on:onVideoStarted={handleVideoStarted}
onClose={closeViewer}
onVideoEnded={() => navigateAsset()}
onVideoStarted={handleVideoStarted}
/>
{/if}
{#if $slideshowState === SlideshowState.None && isShared && ((album && album.isActivityEnabled) || numberOfComments > 0)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<!-- @migration-task Error while migrating Svelte code: Can't migrate code with afterUpdate. Please migrate by hand. -->
<!-- @migration-task Error while migrating Svelte code: Can't migrate code with afterUpdate. Please migrate by hand. -->
<!-- @migration-task Error while migrating Svelte code: Can't migrate code with afterUpdate. Please migrate by hand. -->
<!-- @migration-task Error while migrating Svelte code: Can't migrate code with afterUpdate. Please migrate by hand. -->
<!-- @migration-task Error while migrating Svelte code: Can't migrate code with afterUpdate. Please migrate by hand. -->
<!-- @migration-task Error while migrating Svelte code: Can't migrate code with afterUpdate. Please migrate by hand. -->
<!-- @migration-task Error while migrating Svelte code: Can't migrate code with afterUpdate. Please migrate by hand. -->
<!-- @migration-task Error while migrating Svelte code: Can't migrate code with afterUpdate. Please migrate by hand. -->
<!-- @migration-task Error while migrating Svelte code: `$:` is not allowed in runes mode, use `$derived` or `$effect` instead -->
<!-- @migration-task Error while migrating Svelte code: Cannot use `export let` in runes mode — use `$props()` instead -->
<script lang="ts">
import { onMount, afterUpdate, onDestroy, tick } from 'svelte';
import { onMount, onDestroy, tick } from 'svelte';
import { t } from 'svelte-i18n';
import { getAssetOriginalUrl } from '$lib/utils';
import { handleError } from '$lib/utils/handle-error';
Expand All @@ -25,11 +19,23 @@
resetGlobalCropStore,
rotateDegrees,
} from '$lib/stores/asset-editor.store';
import type { AssetResponseDto } from '@immich/sdk';
export let asset;
let img: HTMLImageElement;
interface Props {
asset: AssetResponseDto;
}
let { asset }: Props = $props();
$: imgElement.set(img);
let img = $state<HTMLImageElement>();
$effect(() => {
if (!img) {
return;
}
imgElement.set(img);
});
cropAspectRatio.subscribe((value) => {
if (!img || !$cropAreaEl) {
Expand Down Expand Up @@ -62,7 +68,7 @@
resetGlobalCropStore();
});
afterUpdate(() => {
$effect(() => {
resizeCanvas();
});
</script>
Expand All @@ -72,8 +78,8 @@
class={`crop-area ${$changedOriention ? 'changedOriention' : ''}`}
style={`rotate:${$rotateDegrees}deg`}
bind:this={$cropAreaEl}
on:mousedown={handleMouseDown}
on:mouseup={handleMouseUp}
onmousedown={handleMouseDown}
onmouseup={handleMouseUp}
aria-label="Crop area"
type="button"
>
Expand Down
Loading

0 comments on commit 1c69e9f

Please sign in to comment.