diff --git a/apps/readest-app/src/app/library.module.css b/apps/readest-app/src/app/library.module.css deleted file mode 100644 index d859a8ea..00000000 --- a/apps/readest-app/src/app/library.module.css +++ /dev/null @@ -1,48 +0,0 @@ -.libraryContainer { - padding: 16px; -} - -.viewToggle { - display: flex; - justify-content: flex-end; - margin-bottom: 16px; -} - -.viewToggle button { - background: none; - border: none; - padding: 8px; - cursor: pointer; - color: #333; -} - -.viewToggle button.active { - color: blue; -} - -.grid { - display: grid; - grid-template-columns: repeat(3, 1fr); - gap: 16px; -} - -.list { - display: block; -} - -.bookCard { - text-align: center; - border: 1px solid #eaeaea; - padding: 16px; - border-radius: 8px; -} - -.bookCard img { - width: 100%; - height: auto; - border-radius: 8px; -} - -.bookCard h3 { - margin-top: 12px; -} diff --git a/apps/readest-app/src/components/Bookshelf.tsx b/apps/readest-app/src/app/library/components/Bookshelf.tsx similarity index 96% rename from apps/readest-app/src/components/Bookshelf.tsx rename to apps/readest-app/src/app/library/components/Bookshelf.tsx index bd8aad10..e1f7a474 100644 --- a/apps/readest-app/src/components/Bookshelf.tsx +++ b/apps/readest-app/src/app/library/components/Bookshelf.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import Image from 'next/image'; import { useRouter } from 'next/navigation'; -import { Book, BooksGroup } from '../types/book'; +import { Book, BooksGroup } from '@/types/book'; import { FaPlus } from 'react-icons/fa'; type BookshelfItem = Book | BooksGroup; @@ -59,7 +59,7 @@ const Bookshelf: React.FC = ({ libraryBooks, onImportBooks }) => {/* Books Grid */}
{bookshelfItems.map((item, index) => ( -
+
{'format' in item ? (
handleBookClick(item.hash)}> diff --git a/apps/readest-app/src/components/SearchBar.tsx b/apps/readest-app/src/app/library/components/SearchBar.tsx similarity index 100% rename from apps/readest-app/src/components/SearchBar.tsx rename to apps/readest-app/src/app/library/components/SearchBar.tsx diff --git a/apps/readest-app/src/app/library/page.tsx b/apps/readest-app/src/app/library/page.tsx new file mode 100644 index 00000000..fa631c7c --- /dev/null +++ b/apps/readest-app/src/app/library/page.tsx @@ -0,0 +1,98 @@ +'use client'; + +import * as React from 'react'; +import { useState, useRef } from 'react'; + +import { useEnv } from '@/context/EnvContext'; +import { useReaderStore } from '@/store/readerStore'; + +import Spinner from '@/components/Spinner'; +import SearchBar from '@/app/library/components/SearchBar'; +import Bookshelf from '@/app/library/components/Bookshelf'; + +const LibraryPage = () => { + const { envConfig, appService, getAppService } = useEnv(); + const { library: libraryBooks, setLibrary } = useReaderStore(); + const [loading, setLoading] = useState(true); + const isInitiating = useRef(false); + + React.useEffect(() => { + if (isInitiating.current) return; + isInitiating.current = true; + setLoading(true); + getAppService(envConfig).then(async (appService) => { + console.log('Loading library books...'); + setLibrary(await appService.loadLibraryBooks()); + setLoading(false); + }); + }, []); + + const importBooks = async (files: [string | File]) => { + setLoading(true); + for (const file of files) { + await appService?.importBook(file, libraryBooks); + setLibrary(libraryBooks); + } + appService?.saveLibraryBooks(libraryBooks); + setLoading(false); + }; + + const selectFilesTauri = async () => { + return appService?.selectFiles('Select Books', ['epub', 'pdf']); + }; + + const selectFilesWeb = () => { + return new Promise((resolve) => { + const fileInput = document.createElement('input'); + fileInput.type = 'file'; + fileInput.accept = '.epub, .pdf'; + fileInput.multiple = true; + fileInput.click(); + + fileInput.onchange = () => { + resolve(fileInput.files); + }; + }); + }; + + const handleImportBooks = async () => { + console.log('Importing books...'); + const { type } = await import('@tauri-apps/plugin-os'); + let files; + if (['android', 'ios'].includes(type())) { + files = (await selectFilesWeb()) as [File]; + } else { + files = (await selectFilesTauri()) as [string]; + } + importBooks(files); + }; + + return ( +
+ +
+
+ + +
+ {!loading && libraryBooks.length === 0 && ( +
+
+
+

Your Library

+

+ Welcome to your library. You can upload your books here and read them anytime. +

+ +
+
+
+ )} +
+
+ ); +}; + +export default LibraryPage; diff --git a/apps/readest-app/src/app/page.tsx b/apps/readest-app/src/app/page.tsx index dd1aaa03..bf52f844 100644 --- a/apps/readest-app/src/app/page.tsx +++ b/apps/readest-app/src/app/page.tsx @@ -1,98 +1,18 @@ 'use client'; -import * as React from 'react'; -import { useState, useRef } from 'react'; +import { useEffect } from 'react'; +import { useRouter } from 'next/navigation'; -import { useEnv } from '@/context/EnvContext'; -import { useReaderStore } from '@/store/readerStore'; - -import SearchBar from '@/components/SearchBar'; import Spinner from '@/components/Spinner'; -import Bookshelf from '@/components/Bookshelf'; -const LibraryPage = () => { - const { envConfig, appService, getAppService } = useEnv(); - const { library: libraryBooks, setLibrary } = useReaderStore(); - const [loading, setLoading] = useState(true); - const isInitiating = useRef(false); +const HomePage = () => { + const router = useRouter(); - React.useEffect(() => { - if (isInitiating.current) return; - isInitiating.current = true; - setLoading(true); - getAppService(envConfig).then(async (appService) => { - console.log('Loading library books...'); - setLibrary(await appService.loadLibraryBooks()); - setLoading(false); - }); - }, []); + useEffect(() => { + router.push('/library'); + }, [router]); - const importBooks = async (files: [string | File]) => { - setLoading(true); - for (const file of files) { - await appService?.importBook(file, libraryBooks); - setLibrary(libraryBooks); - } - appService?.saveLibraryBooks(libraryBooks); - setLoading(false); - }; - - const selectFilesTauri = async () => { - return appService?.selectFiles('Select Books', ['epub', 'pdf']); - }; - - const selectFilesWeb = () => { - return new Promise((resolve) => { - const fileInput = document.createElement('input'); - fileInput.type = 'file'; - fileInput.accept = '.epub, .pdf'; - fileInput.multiple = true; - fileInput.click(); - - fileInput.onchange = () => { - resolve(fileInput.files); - }; - }); - }; - - const handleImportBooks = async () => { - console.log('Importing books...'); - const { type } = await import('@tauri-apps/plugin-os'); - let files; - if (['android', 'ios'].includes(type())) { - files = (await selectFilesWeb()) as [File]; - } else { - files = (await selectFilesTauri()) as [string]; - } - importBooks(files); - }; - - return ( -
- -
-
- - -
- {!loading && libraryBooks.length === 0 && ( -
-
-
-

Your Library

-

- Welcome to your library. You can upload your books here and read them anytime. -

- -
-
-
- )} -
-
- ); + return ; }; -export default LibraryPage; +export default HomePage;