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: migrate to SvelteKit app state #14807

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
231 changes: 133 additions & 98 deletions web/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@socket.io/component-emitter": "^3.1.0",
"@sveltejs/adapter-static": "^3.0.5",
"@sveltejs/enhanced-img": "^0.4.0",
"@sveltejs/kit": "^2.7.2",
"@sveltejs/kit": "^2.12.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/svelte": "^5.2.4",
Expand Down
6 changes: 3 additions & 3 deletions web/src/lib/components/faces-page/merge-face-selector.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { page } from '$app/state';
import Icon from '$lib/components/elements/icon.svelte';
import { ActionQueryParameterValue, AppRoute, QueryParameter } from '$lib/constants';
import { handleError } from '$lib/utils/handle-error';
Expand Down Expand Up @@ -41,8 +41,8 @@

const handleSwapPeople = async () => {
[person, selectedPeople[0]] = [selectedPeople[0], person];
$page.url.searchParams.set(QueryParameter.ACTION, ActionQueryParameterValue.MERGE);
await goto(`${AppRoute.PEOPLE}/${person.id}?${$page.url.searchParams.toString()}`);
page.url.searchParams.set(QueryParameter.ACTION, ActionQueryParameterValue.MERGE);
await goto(`${AppRoute.PEOPLE}/${person.id}?${page.url.searchParams.toString()}`);
};

const onSelect = async (selected: PersonResponseDto) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { page } from '$app/stores';
import { page } from '$app/state';
import { shouldIgnoreEvent } from '$lib/actions/shortcut';
import { dragAndDropFilesStore } from '$lib/stores/drag-and-drop-files.store';
import { fileUploadHandler } from '$lib/utils/file-uploader';
Expand All @@ -8,8 +8,8 @@
import { fade } from 'svelte/transition';
import ImmichLogo from './immich-logo.svelte';

let albumId = $derived(isAlbumsRoute($page.route?.id) ? $page.params.albumId : undefined);
let isShare = $derived(isSharedLinkRoute($page.route?.id));
let albumId = $derived(isAlbumsRoute(page.route?.id) ? page.params.albumId : undefined);
let isShare = $derived(isSharedLinkRoute(page.route?.id));

let dragStartTarget: EventTarget | null = $state(null);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { page } from '$app/stores';
import { page } from '$app/state';
import { focusTrap } from '$lib/actions/focus-trap';
import Button from '$lib/components/elements/buttons/button.svelte';
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
Expand Down Expand Up @@ -90,7 +90,7 @@
size="sm"
shadow={false}
border
aria-current={$page.url.pathname.includes('/admin') ? 'page' : undefined}
aria-current={page.url.pathname.includes('/admin') ? 'page' : undefined}
>
<div class="flex place-content-center place-items-center text-center gap-2 px-2">
<Icon path={mdiWrench} size="18" ariaHidden />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { page } from '$app/stores';
import { page } from '$app/state';
import { clickOutside } from '$lib/actions/click-outside';
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
import LinkButton from '$lib/components/elements/buttons/link-button.svelte';
Expand Down Expand Up @@ -96,7 +96,7 @@
/>
</div>

{#if !$page.url.pathname.includes('/admin') && showUploadButton}
{#if !page.url.pathname.includes('/admin') && showUploadButton}
<LinkButton onclick={onUploadClick} class="hidden lg:block">
<div class="flex gap-2">
<Icon path={mdiTrayArrowUp} size="1.5em" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<script lang="ts">
import { writable, type Writable } from 'svelte/store';
import { createContext } from '$lib/utils/context';
import { page } from '$app/stores';
import { page } from '$app/state';
import { handlePromiseError } from '$lib/utils';
import { goto } from '$app/navigation';
import type { Snippet } from 'svelte';

const getParamValues = (param: string) => {
return new Set(($page.url.searchParams.get(param) || '').split(' ').filter((x) => x !== ''));
return new Set((page.url.searchParams.get(param) || '').split(' ').filter((x) => x !== ''));
};

interface Props {
Expand All @@ -28,7 +28,7 @@

$effect(() => {
if (queryParam && $state) {
const searchParams = new URLSearchParams($page.url.searchParams);
const searchParams = new URLSearchParams(page.url.searchParams);
if ($state.size > 0) {
searchParams.set(queryParam, [...$state].join(' '));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Icon from '$lib/components/elements/icon.svelte';
import { mdiChevronDown, mdiChevronLeft } from '@mdi/js';
import { resolveRoute } from '$app/paths';
import { page } from '$app/stores';
import { page } from '$app/state';
import type { Snippet } from 'svelte';
import { t } from 'svelte-i18n';

Expand Down Expand Up @@ -32,7 +32,7 @@
let routePath = $derived(resolveRoute(routeId, {}));

$effect(() => {
isSelected = ($page.route.id?.match(/^\/(admin|\(user\))\/[^/]*/) || [])[0] === routeId;
isSelected = (page.route.id?.match(/^\/(admin|\(user\))\/[^/]*/) || [])[0] === routeId;
});
</script>

Expand Down
6 changes: 3 additions & 3 deletions web/src/routes/(user)/share/[key]/+error.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { page } from '$app/stores';
import { page } from '$app/state';
</script>

<svelte:head>
Expand All @@ -8,7 +8,7 @@

<section class="flex flex-col px-4 h-screen w-screen place-content-center place-items-center">
<h1 class="py-10 text-4xl text-immich-primary dark:text-immich-dark-primary">Page not found :/</h1>
{#if $page.error?.message}
<h2 class="text-xl text-immich-fg dark:text-immich-dark-fg">{$page.error.message}</h2>
{#if page.error?.message}
<h2 class="text-xl text-immich-fg dark:text-immich-dark-fg">{page.error.message}</h2>
{/if}
</section>
4 changes: 2 additions & 2 deletions web/src/routes/+error.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import { page } from '$app/stores';
import { page } from '$app/state';
import Error from '$lib/components/error.svelte';
</script>

<Error error={$page.error}></Error>
<Error error={page.error}></Error>
34 changes: 17 additions & 17 deletions web/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { run } from 'svelte/legacy';

import { afterNavigate, beforeNavigate } from '$app/navigation';
import { page } from '$app/stores';
import { page } from '$app/state';
import DownloadPanel from '$lib/components/asset-viewer/download-panel.svelte';
import AppleHeader from '$lib/components/shared-components/apple-header.svelte';
import FullscreenContainer from '$lib/components/shared-components/fullscreen-container.svelte';
Expand Down Expand Up @@ -52,7 +52,7 @@
};

const getMyImmichLink = () => {
return new URL($page.url.pathname + $page.url.search, 'https://my.immich.app');
return new URL(page.url.pathname + page.url.search, 'https://my.immich.app');
};

onMount(() => {
Expand All @@ -66,8 +66,8 @@
document.removeEventListener('change', handleChangeTheme);
});

if (isSharedLinkRoute($page.route?.id)) {
setKey($page.params.key);
if (isSharedLinkRoute(page.route?.id)) {
setKey(page.params.key);
}

beforeNavigate(({ from, to }) => {
Expand Down Expand Up @@ -95,33 +95,33 @@
</script>

<svelte:head>
<title>{$page.data.meta?.title || 'Web'} - Immich</title>
<title>{page.data.meta?.title || 'Web'} - Immich</title>
<link rel="manifest" href="/manifest.json" crossorigin="use-credentials" />
<meta name="theme-color" content="currentColor" />
<AppleHeader />

{#if $page.data.meta}
<meta name="description" content={$page.data.meta.description} />
{#if page.data.meta}
<meta name="description" content={page.data.meta.description} />

<!-- Facebook Meta Tags -->
<meta property="og:type" content="website" />
<meta property="og:title" content={$page.data.meta.title} />
<meta property="og:description" content={$page.data.meta.description} />
{#if $page.data.meta.imageUrl}
<meta property="og:title" content={page.data.meta.title} />
<meta property="og:description" content={page.data.meta.description} />
{#if page.data.meta.imageUrl}
<meta
property="og:image"
content={new URL($page.data.meta.imageUrl, $serverConfig.externalDomain || globalThis.location.origin).href}
content={new URL(page.data.meta.imageUrl, $serverConfig.externalDomain || globalThis.location.origin).href}
/>
{/if}

<!-- Twitter Meta Tags -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={$page.data.meta.title} />
<meta name="twitter:description" content={$page.data.meta.description} />
{#if $page.data.meta.imageUrl}
<meta name="twitter:title" content={page.data.meta.title} />
<meta name="twitter:description" content={page.data.meta.description} />
{#if page.data.meta.imageUrl}
<meta
name="twitter:image"
content={new URL($page.data.meta.imageUrl, $serverConfig.externalDomain || globalThis.location.origin).href}
content={new URL(page.data.meta.imageUrl, $serverConfig.externalDomain || globalThis.location.origin).href}
/>
{/if}
{/if}
Expand All @@ -142,8 +142,8 @@
}}
/>

{#if $page.data.error}
<Error error={$page.data.error}></Error>
{#if page.data.error}
<Error error={page.data.error}></Error>
{:else}
{@render children?.()}
{/if}
Expand Down
Loading