From 6b7a7b0cbc45583d5b6c1a4e106f3045a6ae4dbd Mon Sep 17 00:00:00 2001 From: Jonathan Jogenfors Date: Thu, 20 Feb 2025 16:45:34 +0100 Subject: [PATCH] feat(web): library import path onboarding (#16229) --- docs/docs/features/libraries.md | 5 +-- .../admin/library-management/+page.svelte | 45 ++++++++++++++++++- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/docs/docs/features/libraries.md b/docs/docs/features/libraries.md index 796337f37c4..a137980e00e 100644 --- a/docs/docs/features/libraries.md +++ b/docs/docs/features/libraries.md @@ -111,11 +111,10 @@ These actions must be performed by the Immich administrator. - Click on Administration -> Libraries - Click on Create External Library - Select which user owns the library, this can not be changed later +- Enter `/mnt/media/christmas-trip` then click Add +- Click on Save - Click the drop-down menu on the newly created library - Click on Rename Library and rename it to "Christmas Trip" -- Click Edit Import Paths -- Click on Add Path -- Enter `/mnt/media/christmas-trip` then click Add NOTE: We have to use the `/mnt/media/christmas-trip` path and not the `/mnt/nas/christmas-trip` path since all paths have to be what the Docker containers see. diff --git a/web/src/routes/admin/library-management/+page.svelte b/web/src/routes/admin/library-management/+page.svelte index 34a42446cde..4c916bd49d1 100644 --- a/web/src/routes/admin/library-management/+page.svelte +++ b/web/src/routes/admin/library-management/+page.svelte @@ -35,6 +35,7 @@ import { t } from 'svelte-i18n'; import { fade, slide } from 'svelte/transition'; import type { PageData } from './$types'; + import LibraryImportPathForm from '$lib/components/forms/library-import-path-form.svelte'; interface Props { data: PageData; @@ -57,6 +58,8 @@ let updateLibraryIndex: number | null; let dropdownOpen: boolean[] = []; let toCreateLibrary = $state(false); + let toAddImportPath = $state(false); + let importPathToAdd: string | null = $state(null); onMount(async () => { await readLibraryList(); @@ -67,6 +70,7 @@ editScanSettings = undefined; renameLibrary = undefined; updateLibraryIndex = null; + toAddImportPath = false; for (let index = 0; index < dropdownOpen.length; index++) { dropdownOpen[index] = false; @@ -93,8 +97,9 @@ } const handleCreate = async (ownerId: string) => { + let createdLibrary: LibraryResponseDto | undefined; try { - const createdLibrary = await createLibrary({ createLibraryDto: { ownerId } }); + createdLibrary = await createLibrary({ createLibraryDto: { ownerId } }); notificationController.show({ message: $t('admin.library_created', { values: { library: createdLibrary.name } }), type: NotificationType.Info, @@ -105,6 +110,29 @@ toCreateLibrary = false; await readLibraryList(); } + + if (createdLibrary) { + // Open the import paths form for the newly created library + updateLibraryIndex = libraries.findIndex((library) => library.id === createdLibrary.id); + toAddImportPath = true; + } + }; + + const handleAddImportPath = () => { + if (!updateLibraryIndex || !importPathToAdd) { + return; + } + + try { + onEditImportPathClicked(updateLibraryIndex); + + libraries[updateLibraryIndex].importPaths.push(importPathToAdd); + } catch (error) { + handleError(error, $t('errors.unable_to_add_import_path')); + } finally { + importPathToAdd = null; + toAddImportPath = false; + } }; const handleUpdate = async (library: Partial) => { @@ -216,6 +244,21 @@ (toCreateLibrary = false)} /> {/if} +{#if toAddImportPath} + { + toAddImportPath = false; + if (updateLibraryIndex) { + onEditImportPathClicked(updateLibraryIndex); + } + }} + /> +{/if} + {#snippet buttons()}