Skip to content

Commit

Permalink
include logic to validate library exists, remove Svelte code
Browse files Browse the repository at this point in the history
  • Loading branch information
phildenhoff committed Apr 21, 2024
1 parent 4b02a5c commit 955fedc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 202 deletions.
199 changes: 0 additions & 199 deletions src/components/organisms/Sidebar.svelte

This file was deleted.

15 changes: 12 additions & 3 deletions src/components/organisms/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LibraryState, useLibrary } from "@/lib/contexts/library";
import { Button, Divider, Modal, Stack, Title } from "@mantine/core";
import { useCallback, useEffect, useState } from "react";
import { ImportableBookMetadata, LibraryAuthor } from "@/bindings";
import { ImportableBookMetadata, LibraryAuthor, commands } from "@/bindings";
import { useDisclosure } from "@mantine/hooks";
import {
AddBookForm,
Expand Down Expand Up @@ -190,8 +190,17 @@ export const Sidebar = () => {
};
const setNewLibraryPath = useCallback(
async (form: SwitchLibraryForm) => {
await set("calibreLibraryPath", form.libraryPath);
closeSwitchLibraryModal();
const selectedIsValid = await commands.clbQueryIsPathValidLibrary(
form.libraryPath,
);

if (selectedIsValid) {
await set("calibreLibraryPath", form.libraryPath);
closeSwitchLibraryModal();
} else {
// TODO: You could create a new library, if you like.
console.error("Invalid library path selected");
}
},
[closeSwitchLibraryModal, set],
);
Expand Down

0 comments on commit 955fedc

Please sign in to comment.