1
0
mirror of https://github.com/immich-app/immich.git synced 2025-06-16 03:40:33 +02:00

fix(web): Handle duplicate library settings gracefully (#6950)

* don't add duplicate import paths

* improve library import paths form

* same for exclusion patterns

* remove newline
This commit is contained in:
Jonathan Jogenfors
2024-02-09 01:09:09 +01:00
committed by GitHub
parent 90a7f16817
commit b67fddf4b8
4 changed files with 78 additions and 24 deletions

View File

@ -13,7 +13,7 @@
let addImportPath = false;
let editImportPath: number | null = null;
let importPathToAdd: string;
let importPathToAdd: string | null = null;
let editedImportPath: string;
let importPaths: string[] = [];
@ -39,7 +39,7 @@
};
const handleAddImportPath = async () => {
if (!addImportPath) {
if (!addImportPath || !importPathToAdd) {
return;
}
@ -48,12 +48,16 @@
}
try {
library.importPaths.push(importPathToAdd);
importPaths = library.importPaths;
// Check so that import path isn't duplicated
if (!library.importPaths.includes(importPathToAdd)) {
library.importPaths.push(importPathToAdd);
importPaths = library.importPaths;
}
} catch (error) {
handleError(error, 'Unable to remove import path');
handleError(error, 'Unable to add import path');
} finally {
addImportPath = false;
importPathToAdd = null;
}
};
@ -67,8 +71,13 @@
}
try {
library.importPaths[editImportPath] = editedImportPath;
importPaths = library.importPaths;
// Check so that import path isn't duplicated
if (!library.importPaths.includes(editedImportPath)) {
// Update import path
library.importPaths[editImportPath] = editedImportPath;
importPaths = library.importPaths;
}
} catch (error) {
editImportPath = null;
handleError(error, 'Unable to edit import path');
@ -103,9 +112,11 @@
title="Add Import Path"
submitText="Add"
bind:importPath={importPathToAdd}
{importPaths}
on:submit={handleAddImportPath}
on:cancel={() => {
addImportPath = false;
importPathToAdd = null;
}}
/>
{/if}
@ -114,8 +125,9 @@
<LibraryImportPathForm
title="Edit Import Path"
submitText="Save"
canDelete={true}
isEditing={true}
bind:importPath={editedImportPath}
{importPaths}
on:submit={handleEditImportPath}
on:delete={handleDeleteImportPath}
on:cancel={() => {
@ -157,7 +169,11 @@
: 'bg-immich-bg dark:bg-immich-dark-gray/50'
}`}
>
<td class="w-4/5 text-ellipsis px-4 text-sm" />
<td class="w-4/5 text-ellipsis px-4 text-sm">
{#if importPaths.length === 0}
No paths added
{/if}</td
>
<td class="w-1/5 text-ellipsis px-4 text-sm"
><Button
type="button"