Compare commits

...

13 commits

Author SHA1 Message Date
bcbce884a1 Merge pull request 'merge-move-all-books-from-shelf' (#14) from move-all-books-from-shelf into main
Reviewed-on: #14
2024-10-11 13:31:44 +02:00
118ca1ed82 feat(MoveToShelf): resolve threads 2024-10-11 13:24:25 +02:00
22ab06f395 Merge branch 'always-use-environment-camera' into move-all-books-from-shelf 2024-09-30 21:33:39 +02:00
c03aa30cfd feat(MoveToShelf): move selected books to shelf 2024-09-30 21:32:24 +02:00
65e9aa2e0b feat(DNBApi): add api from deutsche national bibliothek 2024-09-25 21:33:17 +02:00
cff1ddf005 Merge pull request 'merge-always-use-environment-camera' (#11) from always-use-environment-camera into main
Reviewed-on: #11
2024-09-13 22:24:51 +02:00
46198913b1 fix(camera): always try cam facing environment 2024-09-13 22:24:04 +02:00
afdc95d5c6 Merge pull request 'Darkmode' (#9) from Darkmode into main
Reviewed-on: #9
2024-09-13 21:30:03 +02:00
1e19501dab fix(vars): remove unused 2024-09-13 21:28:46 +02:00
2016a8619d feat(Darkmode): add Darkmode 2024-09-13 21:28:03 +02:00
04d9b86419 Merge pull request 'merge-checkout-modal-can-be-submitted-if-its-invalid' (#8) from checkout-modal-can-be-submitted-if-its-invalid into main
Reviewed-on: #8
2024-09-13 19:46:41 +02:00
6940fab53a fix(CheckoutModal): no submit if invalid form 2024-09-13 19:46:16 +02:00
6d0a62ec21 Merge pull request 'merge-try-google-books-api-for-book-identification-by-isbn' (#7) from try-google-books-api-for-book-identification-by-isbn into main
Reviewed-on: #7
2024-09-13 19:39:58 +02:00
25 changed files with 2509 additions and 648 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
.env .env
n39env n39env
.n39env
.vscode .vscode

File diff suppressed because it is too large Load diff

View file

@ -16,6 +16,7 @@
"@types/react-dom": "^18.3.0", "@types/react-dom": "^18.3.0",
"bootstrap": "^5.3.3", "bootstrap": "^5.3.3",
"date-fns": "^3.6.0", "date-fns": "^3.6.0",
"fast-xml-parser": "^4.5.0",
"history": "^5.3.0", "history": "^5.3.0",
"react": "^18.3.1", "react": "^18.3.1",
"react-bootstrap": "^2.10.4", "react-bootstrap": "^2.10.4",

View file

@ -6,7 +6,6 @@ import "./App.css";
import { Main } from "./pages"; import { Main } from "./pages";
import { Library } from "./pages/Library"; import { Library } from "./pages/Library";
import { Book } from "./pages/Book"; import { Book } from "./pages/Book";
import { primary } from "./colors";
import { ActiveModalProps } from "./shared/components/modals/types"; import { ActiveModalProps } from "./shared/components/modals/types";
export const AuthContext = createContext<{ export const AuthContext = createContext<{
@ -50,7 +49,6 @@ function App() {
style={{ style={{
height: "100vh", height: "100vh",
width: "100vw", width: "100vw",
backgroundColor: primary,
fontFamily: "New Amsterdam", fontFamily: "New Amsterdam",
overflow: "scroll", overflow: "scroll",
}} }}

View file

@ -0,0 +1,5 @@
export const primary = "#5e6268";
export const primaryRGBA = "rgba(83,86,91, 0.8)";
export const secondary = "#5f5e68";
export const tertiary = "#5e6768";
export const danger = "#685e62";

View file

@ -12,49 +12,219 @@ body {
} }
} }
#bootstrap-overrides .form-select .form-control { #bootstrap-overrides {
background-color: #f2f3f4;
color: #5e6268;
.btn-primary {
background-color: #5e6268;
color: #f2f3f4;
border: 2px solid #5e6268;
}
form-control {
background-color: #f2f2e8 !important;
border-color: #5e6268 !important;
}
.form-select .form-control {
background-color: #f2f2e8 !important; background-color: #f2f2e8 !important;
border-color: #f2f2e8 !important; border-color: #f2f2e8 !important;
} }
#bootstrap-overrides .dropdown-toggle::after { .dropdown-toggle::after {
display: none; display: none;
} }
#bootstrap-overrides .form-label { .form-label {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans",
sans-serif !important; "Helvetica Neue", sans-serif !important;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
letter-spacing: normal; letter-spacing: normal;
} }
#bootstrap-overrides table { tbody > tr > td {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
"Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans",
"Helvetica Neue", sans-serif !important;
}
.table > :not(caption) > * > * {
background-color: #f2f2e8 !important;
color: #5e6268 !important;
}
table > thead {
letter-spacing: 0.25em; letter-spacing: 0.25em;
} }
#bootstrap-overrides .bg-primary { .bg-primary {
background-color: #f2f3f4 !important; background-color: #f2f3f4 !important;
} }
#bootstrap-overrides .modal-body { .modal-content {
background-color: #f2f3f4 !important; background-color: #f2f3f4 !important;
} border-radius: 10px;
}
#bootstrap-overrides .danger { .modal-body {
background-color: #f2f3f4 !important;
border-radius: 0px 0px 10px 10px;
}
.modal-header {
background-color: #f2f3f4 !important;
border-radius: 10px 10px 0px 0px;
border-bottom: none;
}
.dropdown button {
background-color: #f2f2e8 !important;
color: #5e6268 !important;
border: 2px solid #5e6268;
}
.dropdown-menu {
background-color: #f2f2e8 !important;
color: #5e6268 !important;
border: 2px solid #f2f2e8;
}
.danger {
background-color: #f9a9ab !important; background-color: #f9a9ab !important;
} }
#bootstrap-overrides .page-link { .page-link {
color: black !important; color: #5e6268 !important;
border: 2px solid black !important; border: 2px solid #5e6268 !important;
background-color: transparent !important; background-color: transparent !important;
}
.active > .page-link {
background-color: #5e6268 !important;
color: #f2f3f4 !important;
}
.pagination {
margin-top: 10px !important;
li {
min-width: 40px;
}
}
} }
#bootstrap-overrides .active > .page-link { @media (prefers-color-scheme: dark) {
background-color: black !important; #bootstrap-overrides {
background-color: #5e6268;
color: #f2f3f4;
.btn-primary {
background-color: #f2f3f4;
color: #5e6268;
border: 2px solid #5e6268;
}
.form-control {
background-color: #f2f2e8 !important;
border-color: #5e6268 !important;
border-right: none;
}
.form-select .form-control {
background-color: #f2f2e8 !important;
border-color: #f2f2e8 !important;
}
.dropdown-toggle::after {
display: none;
}
.form-label {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
"Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans",
"Helvetica Neue", sans-serif !important;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
letter-spacing: normal;
}
tbody > tr > td {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
"Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans",
"Helvetica Neue", sans-serif !important;
}
.table > :not(caption) > * > * {
background-color: #5e6268 !important;
color: #f2f2e8 !important;
}
table > thead {
letter-spacing: 0.25em;
}
.bg-primary {
background-color: #5e6268 !important;
}
.dropdown button {
background-color: #f2f2e8 !important;
color: #5e6268 !important;
}
.dropdown-menu {
background-color: #5e6268 !important;
border: 2px solid #5e6268;
}
.dropdown-item {
color: #f2f2e8 !important;
svg {
color: #f2f2e8 !important;
}
}
.dropdown-item:hover {
color: #5e6268 !important;
background-color: #f2f2e8 !important;
}
.modal-content {
background-color: #5e6268 !important;
border-radius: 10px;
}
.modal-body {
background-color: #5e6268 !important;
border-radius: 0px 0px 10px 10px;
}
.modal-header {
background-color: #5e6268 !important;
border-radius: 10px 10px 0px 0px;
border-bottom: none;
}
.danger {
background-color: #c94414 !important;
}
.page-link {
color: #f2f3f4 !important; color: #f2f3f4 !important;
border: 2px solid #f2f3f4 !important;
background-color: transparent !important;
}
.active > .page-link {
background-color: #f2f3f4 !important;
color: #5e6268 !important;
}
.pagination {
margin-top: 10px !important;
}
}
} }
code { code {

View file

@ -1,7 +1,7 @@
import React, { useCallback, useContext, useMemo } from "react"; import React, { useCallback, useContext, useMemo, useState } from "react";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { Book } from "../../types/Book"; import { Book } from "../../types/Book";
import { Pagination, Table } from "react-bootstrap"; import { Button, Form, Table } from "react-bootstrap";
import { import {
createColumnHelper, createColumnHelper,
flexRender, flexRender,
@ -15,12 +15,13 @@ import {
} from "@tanstack/react-table"; } from "@tanstack/react-table";
import { Actions } from "./components/Actions"; import { Actions } from "./components/Actions";
import { ImArrowDown, ImArrowUp } from "react-icons/im"; import { ImArrowDown, ImArrowUp } from "react-icons/im";
import { AiOutlineLeft, AiOutlineRight } from "react-icons/ai";
import { useLocation } from "react-router-dom"; import { useLocation } from "react-router-dom";
import { format } from "date-fns"; import { format } from "date-fns";
import { useAuth } from "../../shared/utils/useAuthentication"; import { useAuth } from "../../shared/utils/useAuthentication";
import { ModalSelector } from "../../shared/components/modals/Modals"; import { ModalSelector } from "../../shared/components/modals/Modals";
import { ModalContext } from "../../App"; import { ModalContext } from "../../App";
import { Pagination } from "./components/Pagination";
import { modalTypes } from "../../shared/components/modals/types";
export const Library = (): React.JSX.Element => { export const Library = (): React.JSX.Element => {
const location = useLocation(); const location = useLocation();
@ -31,9 +32,21 @@ export const Library = (): React.JSX.Element => {
[location] [location]
); );
const auth = useAuth(); const { authenticated } = useAuth();
const modalContext = useContext(ModalContext); const modalContext = useContext(ModalContext);
const [selectedBooks, setSelectedBooks] = useState<Book["uuid"][]>([]);
const toggleBookSelection = useCallback(
(uuid: Book["uuid"]) =>
setSelectedBooks((prev) =>
prev.includes(uuid)
? prev.filter((current) => current !== uuid)
: [...prev, uuid]
),
[]
);
const { data: books, refetch } = useQuery<Book[]>({ const { data: books, refetch } = useQuery<Book[]>({
queryFn: async () => { queryFn: async () => {
if ( if (
@ -50,10 +63,48 @@ export const Library = (): React.JSX.Element => {
queryKey: ["books"], queryKey: ["books"],
}); });
const shelf = params.get("shelf");
const year = params.get("year");
const data = useMemo(
() =>
books?.filter(
(b) =>
(!shelf || b.shelf?.toLowerCase() === shelf?.toLowerCase()) &&
(!year || b.published.toString() === year)
) ?? [],
[books, year, shelf]
);
const columnHelper = createColumnHelper<Book>(); const columnHelper = createColumnHelper<Book>();
const columns: ColumnDef<Book, any>[] = useMemo( const columns: ColumnDef<Book, any>[] = useMemo(
() => () =>
[ [
authenticated
? columnHelper.display({
id: "selection",
header: () => (
<Form.Check
type='checkbox'
checked={selectedBooks.length === data?.length}
id={`select-all-books`}
onChange={() =>
setSelectedBooks((prev) =>
prev.length || !data ? [] : data.map((b) => b.uuid)
)
}
/>
),
cell: (props) => (
<Form.Check
type='checkbox'
checked={selectedBooks.includes(props.row.original.uuid)}
id={`select-book-${props.row.original.uuid}`}
onChange={() => toggleBookSelection(props.row.original.uuid)}
/>
),
})
: undefined,
columnHelper.accessor((book) => book.isbn, { columnHelper.accessor((book) => book.isbn, {
id: "isbn", id: "isbn",
header: "ISBN", header: "ISBN",
@ -108,7 +159,7 @@ export const Library = (): React.JSX.Element => {
</div> </div>
), ),
}), }),
auth.authenticated authenticated
? columnHelper.accessor( ? columnHelper.accessor(
(book) => (!book.contact ? "" : book.contact), (book) => (!book.contact ? "" : book.contact),
{ {
@ -133,26 +184,21 @@ export const Library = (): React.JSX.Element => {
<Actions <Actions
book={props.row.original} book={props.row.original}
refetch={refetch} refetch={refetch}
authenticated={auth.authenticated} authenticated={authenticated}
setActiveModal={modalContext.setActiveModal} setActiveModal={modalContext.setActiveModal}
/> />
), ),
}), }),
].filter((c) => typeof c !== "undefined") as ColumnDef<Book, any>[], ].filter((c) => typeof c !== "undefined") as ColumnDef<Book, any>[],
[auth.authenticated, columnHelper, modalContext.setActiveModal, refetch] [
); authenticated,
columnHelper,
const shelf = params.get("shelf"); selectedBooks,
const year = params.get("year"); data,
toggleBookSelection,
const data = useMemo( refetch,
() => modalContext.setActiveModal,
books?.filter( ]
(b) =>
(!shelf || b.shelf?.toLowerCase() === shelf?.toLowerCase()) &&
(!year || b.published.toString() === year)
) ?? [],
[books, year, shelf]
); );
const [pagination, setPagination] = React.useState<PaginationState>({ const [pagination, setPagination] = React.useState<PaginationState>({
@ -179,19 +225,6 @@ export const Library = (): React.JSX.Element => {
[table.getState().pagination.pageIndex] [table.getState().pagination.pageIndex]
); );
const getPage = useCallback(
(n: number) => (
<Pagination.Item
key={`${n}th-page`}
active={n === currentPage}
onClick={() => table.setPageIndex(n)}
>
{n + 1}
</Pagination.Item>
),
[table, currentPage]
);
return ( return (
<div className='m-auto p-2' style={{ width: "100%", maxHeight: "100vh" }}> <div className='m-auto p-2' style={{ width: "100%", maxHeight: "100vh" }}>
<ModalSelector {...modalContext} /> <ModalSelector {...modalContext} />
@ -249,32 +282,32 @@ export const Library = (): React.JSX.Element => {
</div> </div>
{table.getPageCount() ? ( {table.getPageCount() ? (
<div className='d-flex w-100'> <div className='d-flex w-100'>
<Pagination className='d-flex m-auto'> <Pagination
<Pagination.Item currentPage={currentPage}
key='prev' setPageIndex={table.setPageIndex}
disabled={currentPage === 0} getPageCount={table.getPageCount}
onClick={() => table.setPageIndex(currentPage - 1)} />
{authenticated && (
<Button
style={{
marginLeft: "0px",
marginRight: "auto",
}}
className='my-auto'
onClick={() =>
modalContext.setActiveModal({
type: modalTypes.moveShelf,
books: selectedBooks,
onClose: () => {
refetch();
modalContext.setActiveModal();
},
})
}
> >
<AiOutlineLeft /> Move selection
</Pagination.Item> </Button>
{getPage(0)} )}
{currentPage > 3 && <Pagination.Ellipsis />}
{currentPage === 3 && getPage(currentPage - 2)}
{currentPage > 1 && getPage(currentPage - 1)}
{currentPage > 0 && getPage(currentPage)}
{currentPage < table.getPageCount() - 2 && getPage(currentPage + 1)}
{currentPage < table.getPageCount() - 3 &&
table.getPageCount() > 4 && <Pagination.Ellipsis />}
{currentPage < table.getPageCount() - 1 &&
getPage(table.getPageCount() - 1)}
<Pagination.Item
key='next'
onClick={() => table.setPageIndex(currentPage + 1)}
disabled={currentPage >= table.getPageCount() - 1}
>
<AiOutlineRight />
</Pagination.Item>
</Pagination>
</div> </div>
) : null} ) : null}
</div> </div>

View file

@ -1,11 +1,10 @@
import { Badge, Dropdown } from "react-bootstrap";
import { Book } from "../../../types/Book";
import { ImBin, ImBook, ImBoxAdd, ImBoxRemove, ImMenu } from "react-icons/im";
import { useMutation } from "@tanstack/react-query"; import { useMutation } from "@tanstack/react-query";
import { secondary } from "../../../colors"; import { useCallback } from "react";
import { Badge, Dropdown } from "react-bootstrap";
import { ImBin, ImBook, ImBoxAdd, ImBoxRemove, ImMenu } from "react-icons/im";
import { ModalContextType } from "../../../App"; import { ModalContextType } from "../../../App";
import { modalTypes } from "../../../shared/components/modals/types"; import { modalTypes } from "../../../shared/components/modals/types";
import { useCallback } from "react"; import { Book } from "../../../types/Book";
const { book: bookModal, checkout, del } = modalTypes; const { book: bookModal, checkout, del } = modalTypes;
@ -44,11 +43,7 @@ export const Actions = ({
return ( return (
<> <>
<Dropdown> <Dropdown>
<Dropdown.Toggle <Dropdown.Toggle variant='success' id='dropdown-basic'>
variant='success'
id='dropdown-basic'
style={{ backgroundColor: secondary, border: "2px solid black" }}
>
<ImMenu size={25} color='black' /> <ImMenu size={25} color='black' />
</Dropdown.Toggle> </Dropdown.Toggle>
@ -59,14 +54,7 @@ export const Actions = ({
className='d-flex' className='d-flex'
onClick={() => setActiveModal({ type: bookModal, book, onClose })} onClick={() => setActiveModal({ type: bookModal, book, onClose })}
> >
<Badge <Badge pill className='ml-2 d-flex mr-2'>
pill
className='ml-2 d-flex mr-2'
style={{
border: "2px solid black",
backgroundColor: "transparent",
}}
>
<ImBook size={25} color='black' className='m-auto' /> <ImBook size={25} color='black' className='m-auto' />
</Badge> </Badge>
<p className='m-auto' style={{ paddingLeft: "10px" }}> <p className='m-auto' style={{ paddingLeft: "10px" }}>
@ -87,13 +75,7 @@ export const Actions = ({
}) })
} }
> >
<Badge <Badge pill className='ml-2 d-flex mr-2'>
pill
className='ml-2 d-flex mr-2'
style={{
border: "2px solid black",
}}
>
<ImBoxRemove size={25} color='black' className='m-auto' /> <ImBoxRemove size={25} color='black' className='m-auto' />
</Badge>{" "} </Badge>{" "}
<p className='m-auto' style={{ paddingLeft: "10px" }}> <p className='m-auto' style={{ paddingLeft: "10px" }}>
@ -126,17 +108,9 @@ export const Actions = ({
<Dropdown.Item <Dropdown.Item
id='delete' id='delete'
className='d-flex' className='d-flex'
onClick={() => onClick={() => setActiveModal({ type: del, onClose, ...book })}
setActiveModal({ type: del, uuid: book.uuid, onClose })
}
>
<Badge
pill
className='ml-2 d-flex danger mr-2'
style={{
border: "2px solid black",
}}
> >
<Badge pill className='ml-2 d-flex danger mr-2'>
<ImBin size={25} color='black' className='m-auto' /> <ImBin size={25} color='black' className='m-auto' />
</Badge>{" "} </Badge>{" "}
<p className='m-auto' style={{ paddingLeft: "10px" }}> <p className='m-auto' style={{ paddingLeft: "10px" }}>

View file

@ -0,0 +1,64 @@
import React, { useCallback } from "react";
import { Pagination as BP } from "react-bootstrap";
import { AiOutlineLeft, AiOutlineRight } from "react-icons/ai";
import { useAuth } from "../../../shared/utils/useAuthentication";
export const Pagination = ({
currentPage,
getPageCount,
setPageIndex,
}: {
currentPage: number;
getPageCount: () => number;
setPageIndex: (index: number) => void;
}): React.JSX.Element => {
const { authenticated } = useAuth();
const getPage = useCallback(
(n: number) => (
<BP.Item
key={`${n}th-page`}
active={n === currentPage}
onClick={() => setPageIndex(n)}
>
{n + 1}
</BP.Item>
),
[setPageIndex, currentPage]
);
return (
<BP
className='d-flex'
style={{
marginLeft: "auto",
marginRight: authenticated ? "10px" : "auto",
}}
>
<BP.Item
key='prev'
disabled={currentPage === 0}
onClick={() => setPageIndex(currentPage - 1)}
>
<AiOutlineLeft />
</BP.Item>
{getPage(0)}
{currentPage > 3 && <BP.Ellipsis />}
{currentPage === 3 && getPage(currentPage - 2)}
{currentPage > 1 && getPage(currentPage - 1)}
{currentPage > 0 && getPage(currentPage)}
{currentPage < getPageCount() - 2 && getPage(currentPage + 1)}
{currentPage < getPageCount() - 3 && getPageCount() > 4 && (
<BP.Ellipsis />
)}
{currentPage < getPageCount() - 1 && getPage(getPageCount() - 1)}
<BP.Item
key='next'
onClick={() => setPageIndex(currentPage + 1)}
disabled={currentPage >= getPageCount() - 1}
>
<AiOutlineRight />
</BP.Item>
</BP>
);
};

View file

@ -13,7 +13,6 @@ import { TfiKey } from "react-icons/tfi";
import { Link, useNavigate } from "react-router-dom"; import { Link, useNavigate } from "react-router-dom";
import { Book } from "../../types/Book"; import { Book } from "../../types/Book";
import { secondary } from "../../colors";
import { useAuth } from "../../shared/utils/useAuthentication"; import { useAuth } from "../../shared/utils/useAuthentication";
import { ModalContext } from "../../App"; import { ModalContext } from "../../App";
import { modalTypes } from "../../shared/components/modals/types"; import { modalTypes } from "../../shared/components/modals/types";
@ -95,16 +94,12 @@ export const Main = (): React.JSX.Element => {
onChange={(ev) => setTitle(ev.target.value)} onChange={(ev) => setTitle(ev.target.value)}
style={{ style={{
borderRadius: "20px 0px 0px 20px", borderRadius: "20px 0px 0px 20px",
border: "2px solid black",
borderRight: "none", borderRight: "none",
}} }}
/> />
<Button <Button
style={{ style={{
borderRadius: "0px 5px 5px 0px", borderRadius: "0px 5px 5px 0px",
backgroundColor: secondary,
color: "black",
border: "2px solid black",
}} }}
className='mr-2' className='mr-2'
disabled={activeModal?.type === scanner || isFetching} disabled={activeModal?.type === scanner || isFetching}
@ -135,9 +130,6 @@ export const Main = (): React.JSX.Element => {
<Button <Button
style={{ style={{
borderRadius: "5px", borderRadius: "5px",
backgroundColor: secondary,
color: "black",
border: "2px solid black",
marginLeft: "auto", marginLeft: "auto",
marginRight: "10px", marginRight: "10px",
}} }}
@ -151,9 +143,6 @@ export const Main = (): React.JSX.Element => {
<Button <Button
style={{ style={{
borderRadius: "5px", borderRadius: "5px",
backgroundColor: secondary,
color: "black",
border: "2px solid black",
marginLeft: "auto", marginLeft: "auto",
marginRight: "10px", marginRight: "10px",
}} }}
@ -174,9 +163,6 @@ export const Main = (): React.JSX.Element => {
<Button <Button
style={{ style={{
borderRadius: "5px", borderRadius: "5px",
backgroundColor: secondary,
color: "black",
border: "2px solid black",
}} }}
> >
<ImBooks /> Browse library{" "} <ImBooks /> Browse library{" "}
@ -186,9 +172,6 @@ export const Main = (): React.JSX.Element => {
<Button <Button
style={{ style={{
borderRadius: "5px", borderRadius: "5px",
backgroundColor: secondary,
color: "black",
border: "2px solid black",
marginRight: "auto", marginRight: "auto",
marginLeft: "10px", marginLeft: "10px",
}} }}

View file

@ -0,0 +1,29 @@
import { XMLParser } from "fast-xml-parser";
import { Book } from "../../../types/Book";
export const tryDeutscheNationalBibliothekApi = async (
isbn: string
): Promise<Pick<Book, "published" | "title"> | undefined> => {
const parser = new XMLParser();
const foundBooks = parser.parse(
await (
await fetch(
"https://services.dnb.de/sru/dnb?version=1.1&operation=searchRetrieve&query=" +
isbn
)
).text()
);
const foundBook =
foundBooks.searchRetrieveResponse?.records?.record?.recordData?.[
"rdf:RDF"
]?.["rdf:Description"];
if (!!foundBook) {
return {
published: foundBook["dcterms:issued"],
title: foundBook["dc:title"],
};
}
return undefined;
};

View file

@ -0,0 +1,16 @@
import { Book } from "../../../types/Book";
export const tryGoogleBooksApi = async (
isbn: string
): Promise<Pick<Book, "published" | "title"> | undefined> => {
const googleBooks = await (
await fetch("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn)
).json();
if ("items" in googleBooks) {
return {
published: googleBooks.items[0].volumeInfo.publishedDate.substring(0, 4),
title: googleBooks.items[0].volumeInfo.title,
};
}
return undefined;
};

View file

@ -2,7 +2,6 @@ import { useCallback, useContext } from "react";
import { Button, Col, Form, Modal, Row } from "react-bootstrap"; import { Button, Col, Form, Modal, Row } from "react-bootstrap";
import { useForm, useWatch } from "react-hook-form"; import { useForm, useWatch } from "react-hook-form";
import { TfiKey } from "react-icons/tfi"; import { TfiKey } from "react-icons/tfi";
import { primaryRGBA, primary, secondary } from "../../../colors";
import { ModalHeader } from "./ModalHeader"; import { ModalHeader } from "./ModalHeader";
import { AuthContext } from "../../../App"; import { AuthContext } from "../../../App";
import { AuthModalProps } from "./types"; import { AuthModalProps } from "./types";
@ -71,12 +70,7 @@ export const AuthenticationModal = ({
); );
return ( return (
<Modal <Modal show={open} onHide={onClose} centered>
show={open}
onHide={onClose}
style={{ backgroundColor: primaryRGBA }}
centered
>
<ModalHeader <ModalHeader
onClose={onClose} onClose={onClose}
title={isUpdate ? "Set new Admin key" : "Admin Login"} title={isUpdate ? "Set new Admin key" : "Admin Login"}
@ -84,9 +78,7 @@ export const AuthenticationModal = ({
/> />
<Modal.Body <Modal.Body
style={{ style={{
border: "2px solid black",
borderTop: "none", borderTop: "none",
backgroundColor: primary,
}} }}
> >
<Form <Form
@ -141,9 +133,6 @@ export const AuthenticationModal = ({
{!isUpdate && ( {!isUpdate && (
<Form.Group as={Row} className='mb-2'> <Form.Group as={Row} className='mb-2'>
<Col sm='4'>
<Form.Label>Password</Form.Label>
</Col>
<Col> <Col>
<Form.Control <Form.Control
{...register("password", { {...register("password", {
@ -166,9 +155,6 @@ export const AuthenticationModal = ({
<Button <Button
style={{ style={{
borderRadius: "5px", borderRadius: "5px",
backgroundColor: secondary,
color: "black",
border: "2px solid black",
marginLeft: "auto", marginLeft: "auto",
marginRight: "10px", marginRight: "10px",
}} }}

View file

@ -5,8 +5,9 @@ import { ModalHeader } from "./ModalHeader";
import { useForm, useWatch } from "react-hook-form"; import { useForm, useWatch } from "react-hook-form";
import { Book, bookShelfs } from "../../../types/Book"; import { Book, bookShelfs } from "../../../types/Book";
import { useScanner } from "../../utils/useScanner"; import { useScanner } from "../../utils/useScanner";
import { primary, primaryRGBA, secondary } from "../../../colors";
import { BookModalProps } from "./types"; import { BookModalProps } from "./types";
import { tryGoogleBooksApi } from "../../../pages/Main/utils/tryGoogleBooksApi";
import { tryDeutscheNationalBibliothekApi } from "../../../pages/Main/utils/tryDeutscheNationalBibliothekApi";
type BookForm = Pick<Book, "isbn" | "title" | "shelf" | "published">; type BookForm = Pick<Book, "isbn" | "title" | "shelf" | "published">;
@ -28,24 +29,33 @@ export const BookModal = ({
reset(book); reset(book);
}, [book, reset]); }, [book, reset]);
const { scannerError, setScannerRef } = useScanner({ const [processingDetection, setProcessingDetection] = useState(false);
onDetected: async (result) => {
const googleBooks = await ( const onDetected = useCallback(
await fetch( async (result: string) => {
"https://www.googleapis.com/books/v1/volumes?q=isbn:" + result if (!processingDetection) {
) setProcessingDetection(true);
).json(); const apiResponses = (
if ("items" in googleBooks) { await Promise.all([
console.log(googleBooks); tryDeutscheNationalBibliothekApi(result),
setValue( tryGoogleBooksApi(result),
"published", ])
googleBooks.items[0].volumeInfo.publishedDate.substring(0, 4) ).filter((b) => !!b) as Pick<Book, "published" | "title">[];
); if (apiResponses.length) {
setValue("title", googleBooks.items[0].volumeInfo.title); Object.entries(apiResponses[0]).forEach(([key, value]) => {
setValue(key as keyof BookForm, value);
});
} }
setValue("isbn", result); setValue("isbn", result);
setShowScanner(false); setShowScanner(false);
setProcessingDetection(false);
}
}, },
[processingDetection, setValue]
);
const { scannerError, setScannerRef } = useScanner({
onDetected,
}); });
const values = useWatch({ control }); const values = useWatch({ control });
@ -94,12 +104,7 @@ export const BookModal = ({
); );
return ( return (
<Modal <Modal show={open} onHide={onClose} centered>
show={open}
onHide={onClose}
style={{ backgroundColor: primaryRGBA }}
centered
>
<ModalHeader <ModalHeader
onClose={onClose} onClose={onClose}
title={`${!!book ? "Edit" : "Add new"} Book`} title={`${!!book ? "Edit" : "Add new"} Book`}
@ -107,9 +112,7 @@ export const BookModal = ({
/> />
<Modal.Body <Modal.Body
style={{ style={{
border: "2px solid black",
borderTop: "none", borderTop: "none",
backgroundColor: primary,
}} }}
> >
{!showScanner && ( {!showScanner && (
@ -136,9 +139,6 @@ export const BookModal = ({
<Button <Button
style={{ style={{
borderRadius: "0px 5px 5px 0px", borderRadius: "0px 5px 5px 0px",
backgroundColor: secondary,
color: "black",
border: "2px solid black",
}} }}
className='mr-2 pt-0' className='mr-2 pt-0'
disabled={showScanner} disabled={showScanner}
@ -237,9 +237,6 @@ export const BookModal = ({
<Button <Button
style={{ style={{
borderRadius: "5px", borderRadius: "5px",
backgroundColor: secondary,
color: "black",
border: "2px solid black",
marginLeft: "auto", marginLeft: "auto",
marginRight: "10px", marginRight: "10px",
}} }}
@ -260,7 +257,6 @@ export const BookModal = ({
className='drawingBuffer w-100 position-absolute' className='drawingBuffer w-100 position-absolute'
style={{ style={{
height: "100%", height: "100%",
border: "2px solid black",
}} }}
/> />
</div> </div>

View file

@ -1,12 +1,11 @@
import React, { useCallback, useState } from "react"; import React, { useCallback, useState } from "react";
import { Alert, Button, Col, Form, Modal, Row } from "react-bootstrap"; import { Alert, Button, Col, Form, Modal, Row } from "react-bootstrap";
import { ImBoxAdd, ImBoxRemove } from "react-icons/im";
import { useForm, useWatch } from "react-hook-form"; import { useForm, useWatch } from "react-hook-form";
import { AiOutlineExclamationCircle } from "react-icons/ai";
import { ImBoxAdd, ImBoxRemove } from "react-icons/im";
import { Book } from "../../../types/Book"; import { Book } from "../../../types/Book";
import { primary, primaryRGBA, secondary } from "../../../colors";
import { ModalHeader } from "./ModalHeader"; import { ModalHeader } from "./ModalHeader";
import { CheckoutBookModalProps } from "./types"; import { CheckoutBookModalProps } from "./types";
import { AiOutlineExclamationCircle } from "react-icons/ai";
type BookCheckoutForm = Pick<Book, "checkoutBy" | "contact">; type BookCheckoutForm = Pick<Book, "checkoutBy" | "contact">;
@ -30,6 +29,9 @@ export const CheckoutBookModal = ({
const onSubmit = useCallback( const onSubmit = useCallback(
async (data: Partial<BookCheckoutForm>) => { async (data: Partial<BookCheckoutForm>) => {
if (!formState.isValid) {
return;
}
if (!data.checkoutBy) { if (!data.checkoutBy) {
setError("checkoutBy", { setError("checkoutBy", {
message: `please enter ${ message: `please enter ${
@ -61,16 +63,11 @@ export const CheckoutBookModal = ({
setFailed(await res.text()); setFailed(await res.text());
} }
}, },
[uuid, onClose, setError, isChechout] [formState.isValid, isChechout, uuid, setError, onClose]
); );
return ( return (
<Modal <Modal show={open} onHide={onClose} centered>
show={open}
onHide={onClose}
style={{ backgroundColor: primaryRGBA }}
centered
>
<ModalHeader <ModalHeader
onClose={onClose} onClose={onClose}
title={`${isChechout ? "Checkout" : "Return"} book '${title}'`} title={`${isChechout ? "Checkout" : "Return"} book '${title}'`}
@ -84,9 +81,7 @@ export const CheckoutBookModal = ({
/> />
<Modal.Body <Modal.Body
style={{ style={{
border: "2px solid black",
borderTop: "none", borderTop: "none",
backgroundColor: primary,
}} }}
> >
<Alert className='w-80 m-auto my-4' variant='warning'> <Alert className='w-80 m-auto my-4' variant='warning'>
@ -116,6 +111,12 @@ export const CheckoutBookModal = ({
"'null' is not a valid nickname" "'null' is not a valid nickname"
); );
}, },
notUndefinedString: (value) => {
return (
value?.toLocaleLowerCase() !== "undefined" ||
"'undefined' is not a valid nickname"
);
},
}, },
})} })}
isInvalid={!!formState.errors.checkoutBy} isInvalid={!!formState.errors.checkoutBy}
@ -178,12 +179,10 @@ export const CheckoutBookModal = ({
<Button <Button
style={{ style={{
borderRadius: "5px", borderRadius: "5px",
backgroundColor: secondary,
color: "black",
border: "2px solid black",
marginLeft: "auto", marginLeft: "auto",
marginRight: "10px", marginRight: "10px",
}} }}
disabled={!formState.isValid}
onClick={() => onSubmit(values)} onClick={() => onSubmit(values)}
> >
{`${isChechout ? "Checkout" : "Return"} book`} {`${isChechout ? "Checkout" : "Return"} book`}

View file

@ -1,12 +1,12 @@
import { Button, Modal } from "react-bootstrap";
import { primary, primaryRGBA, secondary } from "../../../colors";
import { ModalHeader } from "./ModalHeader";
import { ImBin } from "react-icons/im";
import { useMutation } from "@tanstack/react-query"; import { useMutation } from "@tanstack/react-query";
import { Button, Modal } from "react-bootstrap";
import { ImBin } from "react-icons/im";
import { ModalHeader } from "./ModalHeader";
import { DeleteBookModalProps } from "./types"; import { DeleteBookModalProps } from "./types";
export const DeleteBookModal = ({ export const DeleteBookModal = ({
uuid, uuid,
title,
open, open,
onClose, onClose,
}: Omit<DeleteBookModalProps, "type">): React.JSX.Element => { }: Omit<DeleteBookModalProps, "type">): React.JSX.Element => {
@ -24,31 +24,22 @@ export const DeleteBookModal = ({
}); });
return ( return (
<Modal <Modal show={open} onHide={onClose} centered>
show={open}
onHide={onClose}
style={{ backgroundColor: primaryRGBA }}
centered
>
<ModalHeader <ModalHeader
onClose={onClose} onClose={onClose}
title={"Move to Shelf"} title={`Delete Book "${title}"`}
icon={<ImBin size={50} className='ml-0 mr-auto' />} icon={<ImBin size={50} className='ml-0 mr-auto' />}
/> />
<Modal.Body <Modal.Body
style={{ style={{
border: "2px solid black",
borderTop: "none", borderTop: "none",
backgroundColor: primary,
}} }}
> >
Do you really want to delete this book?
<div className='d-flex mx-auto mb-auto mt-2 w-100'> <div className='d-flex mx-auto mb-auto mt-2 w-100'>
<Button <Button
style={{ style={{
borderRadius: "5px", borderRadius: "5px",
backgroundColor: secondary,
color: "black",
border: "2px solid black",
marginLeft: "auto", marginLeft: "auto",
marginRight: "10px", marginRight: "10px",
}} }}
@ -59,9 +50,6 @@ export const DeleteBookModal = ({
<Button <Button
style={{ style={{
borderRadius: "5px", borderRadius: "5px",
backgroundColor: secondary,
color: "black",
border: "2px solid black",
marginLeft: "auto", marginLeft: "auto",
marginRight: "10px", marginRight: "10px",
}} }}

View file

@ -1,7 +1,6 @@
import React from "react"; import React from "react";
import { Button, Modal } from "react-bootstrap"; import { Button, Modal } from "react-bootstrap";
import { AiOutlineClose } from "react-icons/ai"; import { AiOutlineClose } from "react-icons/ai";
import { primary, secondary } from "../../../colors";
export const ModalHeader = ({ export const ModalHeader = ({
title, title,
@ -13,13 +12,7 @@ export const ModalHeader = ({
icon?: JSX.Element; icon?: JSX.Element;
}): React.JSX.Element => { }): React.JSX.Element => {
return ( return (
<Modal.Header <Modal.Header>
style={{
border: "2px solid black",
borderBottom: "none",
backgroundColor: primary,
}}
>
<Modal.Title className='w-100 d-flex' style={{ height: "fit-content" }}> <Modal.Title className='w-100 d-flex' style={{ height: "fit-content" }}>
{typeof title === "string" ? ( {typeof title === "string" ? (
<> <>
@ -34,9 +27,6 @@ export const ModalHeader = ({
<Button <Button
className='ml-auto mr-0' className='ml-auto mr-0'
style={{ style={{
backgroundColor: secondary,
color: "black",
border: "2px solid black",
width: "fit-content", width: "fit-content",
height: "fit-content", height: "fit-content",
}} }}

View file

@ -6,8 +6,9 @@ import { CheckoutBookModal } from "./CheckoutModal";
import { ScannerModal } from "./ScannerModal"; import { ScannerModal } from "./ScannerModal";
import { DeleteBookModal } from "./DeleteBookModal"; import { DeleteBookModal } from "./DeleteBookModal";
import { ModalContextType } from "../../../App"; import { ModalContextType } from "../../../App";
import { MoveShelfModal } from "./MoveShelfModal";
const { auth, book, checkout, scanner, del } = modalTypes; const { auth, book, checkout, scanner, del, moveShelf } = modalTypes;
export const ModalSelector = ({ export const ModalSelector = ({
activeModal, activeModal,
@ -48,7 +49,15 @@ export const ModalSelector = ({
<DeleteBookModal <DeleteBookModal
open={activeModal?.type === del} open={activeModal?.type === del}
onClose={activeModal?.type === del ? activeModal.onClose : setActiveModal} onClose={activeModal?.type === del ? activeModal.onClose : setActiveModal}
uuid={activeModal?.type === checkout ? activeModal.uuid : ""} uuid={activeModal?.type === del ? activeModal.uuid : ""}
title={activeModal?.type === del ? activeModal.title : ""}
/>
<MoveShelfModal
books={activeModal?.type === moveShelf ? activeModal.books : []}
open={activeModal?.type === moveShelf}
onClose={
activeModal?.type === moveShelf ? activeModal.onClose : setActiveModal
}
/> />
</> </>
); );

View file

@ -0,0 +1,100 @@
import { useMutation } from "@tanstack/react-query";
import { Button, Col, Form, Modal, Row } from "react-bootstrap";
import { ImBook } from "react-icons/im";
import { ModalHeader } from "./ModalHeader";
import { MoveShelfAction, MoveShelfModalProps } from "./types";
import { useForm, useWatch } from "react-hook-form";
import { bookShelfs } from "../../../types/Book";
export const MoveShelfModal = ({
books,
open,
onClose,
}: Omit<MoveShelfModalProps, "type">): React.JSX.Element => {
const { control, register, formState, setError } = useForm<MoveShelfAction>({
mode: "onChange",
});
const values = useWatch({ control });
const { mutate: mv } = useMutation({
mutationFn: async () => {
if (!values.target) {
setError("target", { message: "Taget shelf is required" });
return;
}
await fetch(`/api/shelf/move`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ ...values, books }),
});
onClose();
},
});
return (
<Modal show={open} onHide={onClose} centered>
<ModalHeader
onClose={onClose}
title={"Move to Shelf"}
icon={<ImBook size={50} className='ml-0 mr-auto' />}
/>
<Modal.Body
style={{
borderTop: "none",
}}
>
<Form.Group as={Row} className='mb-2'>
<Col sm='2'>
<Form.Label>Shelf</Form.Label>
</Col>
<Col>
<Form.Select
{...register("target", { required: true })}
isInvalid={!!formState.errors.target}
>
{Object.keys(bookShelfs).map((key) => (
<option
key='key'
value={bookShelfs[key as keyof typeof bookShelfs]}
>
{key}
</option>
))}
</Form.Select>
<Form.Control.Feedback type='invalid'>
{!values.target
? "Target shelf is required"
: formState.errors.target?.message}
</Form.Control.Feedback>
</Col>
</Form.Group>
<div className='d-flex mx-auto mb-auto mt-2 w-100'>
<Button
style={{
borderRadius: "5px",
marginLeft: "auto",
marginRight: "10px",
}}
onClick={() => onClose()}
>
Cancel
</Button>
<Button
style={{
borderRadius: "5px",
marginLeft: "0px",
marginRight: "10px",
}}
onClick={() => mv()}
>
Move
</Button>
</div>
</Modal.Body>
</Modal>
);
};

View file

@ -1,7 +1,6 @@
import React from "react"; import React from "react";
import { Modal } from "react-bootstrap"; import { Modal } from "react-bootstrap";
import { ImCamera } from "react-icons/im"; import { ImCamera } from "react-icons/im";
import { primaryRGBA } from "../../../colors";
import { useScanner } from "../../utils/useScanner"; import { useScanner } from "../../utils/useScanner";
import { ModalHeader } from "./ModalHeader"; import { ModalHeader } from "./ModalHeader";
@ -17,18 +16,13 @@ export const ScannerModal = ({
const { scannerError, setScannerRef } = useScanner({ onDetected }); const { scannerError, setScannerRef } = useScanner({ onDetected });
return ( return (
<Modal <Modal show={open} onHide={onClose} centered>
show={open}
onHide={onClose}
style={{ backgroundColor: primaryRGBA }}
centered
>
<ModalHeader <ModalHeader
onClose={onClose} onClose={onClose}
title={"Scan barcode"} title={"Scan barcode"}
icon={<ImCamera size={50} className='ml-0 mr-auto' />} icon={<ImCamera size={50} className='ml-0 mr-auto' />}
/> />
<Modal.Body style={{ border: "2px solid black", borderTop: "none" }}> <Modal.Body>
<div <div
className='w-100 overflow-hidden' className='w-100 overflow-hidden'
ref={(ref) => setScannerRef(ref)} ref={(ref) => setScannerRef(ref)}
@ -41,7 +35,7 @@ export const ScannerModal = ({
className='drawingBuffer w-100 position-absolute' className='drawingBuffer w-100 position-absolute'
style={{ style={{
height: "100%", height: "100%",
border: "2px solid black", border: `2px solid black`,
}} }}
/> />
</div> </div>

View file

@ -11,6 +11,7 @@ export const modalTypes = {
checkout: "checkout", checkout: "checkout",
scanner: "scanner", scanner: "scanner",
del: "del", del: "del",
moveShelf: "moveShelf",
} as const; } as const;
export type ModalTypes = keyof typeof modalTypes; export type ModalTypes = keyof typeof modalTypes;
@ -37,11 +38,21 @@ export type ScannnerModal = {
} & BaseModalProps; } & BaseModalProps;
export type DeleteBookModalProps = { type: "del" } & BaseModalProps & export type DeleteBookModalProps = { type: "del" } & BaseModalProps &
Pick<Book, "uuid">; Pick<Book, "uuid" | "title">;
export type MoveShelfModalProps = { type: "moveShelf" } & BaseModalProps & {
books: Book["uuid"][];
};
export interface MoveShelfAction {
target: Book["shelf"];
books: Book["uuid"][];
}
export type ActiveModalProps = export type ActiveModalProps =
| Omit<AuthModalProps, "open" | "onClose"> | Omit<AuthModalProps, "open" | "onClose">
| Omit<BookModalProps, "open"> | Omit<BookModalProps, "open">
| Omit<CheckoutBookModalProps, "open"> | Omit<CheckoutBookModalProps, "open">
| Omit<ScannnerModal, "open" | "onClose"> | Omit<ScannnerModal, "open" | "onClose">
| Omit<DeleteBookModalProps, "open">; | Omit<DeleteBookModalProps, "open">
| Omit<MoveShelfModalProps, "open">;

View file

@ -103,15 +103,25 @@ export const useScanner = ({
}; };
const getCameraId = useCallback(async () => { const getCameraId = useCallback(async () => {
await navigator.mediaDevices.getUserMedia({ const stream = await navigator.mediaDevices.getUserMedia({
video: true, video: { facingMode: "environment" },
}); });
if (
stream &&
stream.getVideoTracks().length &&
stream.getVideoTracks()[0].getSettings().deviceId
) {
return stream.getVideoTracks()[0].getSettings().deviceId;
}
const devices = await navigator.mediaDevices const devices = await navigator.mediaDevices
.enumerateDevices() .enumerateDevices()
.then((ds) => ds.filter((d) => d.kind === "videoinput")); .then((ds) => ds.filter((d) => d.kind === "videoinput"));
const back = devices.filter((d) => d.label === "Back Camera")[0]; const back = devices.filter((d) =>
d.label.toLowerCase().includes("back")
)[0];
return !back ? devices[0].deviceId : back.deviceId; return !back ? devices[0].deviceId : back.deviceId;
}, []); }, []);

View file

@ -2,7 +2,7 @@ import express, { Request, Response, Application } from "express";
import dotenv from "dotenv"; import dotenv from "dotenv";
import { createPool } from "mariadb"; import { createPool } from "mariadb";
import { Book } from "./types/Book"; import { Book, MoveShelfAction } from "./types/Book";
import { import {
checkoutBook, checkoutBook,
findBook, findBook,
@ -19,6 +19,7 @@ import session from "express-session";
import { censorBookData } from "./utils/censorBookData"; import { censorBookData } from "./utils/censorBookData";
import * as fs from "fs"; import * as fs from "fs";
import { checkForThreads } from "./utils/passesSQLInjectionCheck"; import { checkForThreads } from "./utils/passesSQLInjectionCheck";
import { moveShelf } from "./queries/moveShelf";
dotenv.config(); dotenv.config();
@ -199,6 +200,31 @@ app.post(
} }
); );
app.post(
"/api/shelf/move",
async (
req: Request<undefined, undefined, MoveShelfAction>,
res: Response
) => {
await isAuthenticated(req, res, async () => {
const { target } = req.body;
try {
const containsThread = checkForThreads([target], res);
if (containsThread) {
return;
}
const conn = await pool.getConnection();
await conn.query(moveShelf(req.body));
await conn.end();
res.status(200).send(`Books moved to shelf ${target}.`);
} catch (error) {
res.status(500).send("Internal Server Error: " + error);
}
});
}
);
app.post( app.post(
"/api/books/edit", "/api/books/edit",
async ( async (
@ -230,7 +256,7 @@ app.post(
} else { } else {
await conn.query(editBook(req.body)); await conn.query(editBook(req.body));
await conn.end(); await conn.end();
res.status(200).send("Book moved to shelf"); res.status(200).send("Book edited.");
} }
} catch (error) { } catch (error) {
res.status(500).send("Internal Server Error: " + error); res.status(500).send("Internal Server Error: " + error);

View file

@ -0,0 +1,6 @@
import { MoveShelfAction } from "../types/Book";
export const moveShelf = ({ target, books }: MoveShelfAction) =>
`UPDATE bookData SET shelf='${target}' WHERE uuid IN ('${books.join(
"', '"
)}');`;

View file

@ -9,3 +9,8 @@ export type Book = {
contact: string | null; contact: string | null;
shelf: "AVAILABLE" | "FNORD1" | "FNORD2" | "SHARING" | null; shelf: "AVAILABLE" | "FNORD1" | "FNORD2" | "SHARING" | null;
}; };
export interface MoveShelfAction {
target: Book["shelf"];
books: Book["uuid"][];
}