refactor: resolve() internal links instead of plain hrefs
Type-checks every link against the real route tree. Caught a dead one: the
book page linked tags to /tag/{id}, a route that has never existed.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import * as Dialog from '$lib/components/ui/dialog/index.js';
|
||||
import * as Field from '$lib/components/ui/field/index.js';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
@@ -36,8 +37,8 @@
|
||||
|
||||
const onUpload: FileDropZoneProps['onUpload'] = async (uploadedFiles) => {
|
||||
// Rename files to use webkitRelativePath so directory structure is preserved through form submission
|
||||
const renamedFiles = uploadedFiles.map(f =>
|
||||
new File([f], f.webkitRelativePath || f.name, { type: f.type })
|
||||
const renamedFiles = uploadedFiles.map(
|
||||
(f) => new File([f], f.webkitRelativePath || f.name, { type: f.type })
|
||||
);
|
||||
uploadBooks.fields.files.set([...Array.from(files), ...renamedFiles]);
|
||||
if (autoUploadOnDrop && files.length > 0) {
|
||||
@@ -55,9 +56,12 @@
|
||||
let libraryId = books.items[0].library_id;
|
||||
libraryState.setActive(libraryId);
|
||||
if (books.items.length === 1) {
|
||||
goto(`/book/${books.items[0].id}`);
|
||||
goto(resolve('/(root)/(library)/book/[bookId]', { bookId: String(books.items[0].id) }));
|
||||
} else {
|
||||
goto(`/library/${libraryId}/view?orderBy=created_at&sortOrder=desc`);
|
||||
// The path is resolved; the query string is what the rule cannot see past.
|
||||
const view = resolve('/(root)/(library)/library/[libraryId]/view', { libraryId: String(libraryId) });
|
||||
// eslint-disable-next-line svelte/no-navigation-without-resolve
|
||||
goto(`${view}?orderBy=created_at&sortOrder=desc`);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -88,8 +92,10 @@
|
||||
}
|
||||
|
||||
// Update library book count
|
||||
const count = uploadBooks.result.total
|
||||
libraryState.libraries.find(lib => uploadBooks.fields.library_id.value() == lib.id.toString())!.total += count
|
||||
const count = uploadBooks.result.total;
|
||||
libraryState.libraries.find(
|
||||
(lib) => uploadBooks.fields.library_id.value() == lib.id.toString()
|
||||
)!.total += count;
|
||||
|
||||
// Reset the files field
|
||||
uploadBooks.fields.files.set([]);
|
||||
|
||||
Reference in New Issue
Block a user