Remove DataService and OfflineDataService, refactor book and character operations to use streamlined handlers in LocalSystem
- Delete `data.service.ts` and `offline-data.service.ts`, consolidating functionality into `LocalSystem`. - Refactor book, character, and conversation operations to adopt unified, multilingual, and session-enabled IPC handlers in `LocalSystem`. - Simplify redundant legacy methods, enhancing maintainability and consistency.
This commit is contained in:
@@ -13,7 +13,7 @@ import GuideTour, {GuideStep} from "@/components/GuideTour";
|
||||
import User from "@/lib/models/User";
|
||||
import {useTranslations} from "next-intl";
|
||||
import {LangContext, LangContextProps} from "@/context/LangContext";
|
||||
import {getOfflineDataService} from "@/lib/services/offline-data.service";
|
||||
import OfflineContext, {OfflineContextType} from "@/context/OfflineContext";
|
||||
|
||||
export default function BookList() {
|
||||
const {session, setSession} = useContext(SessionContext);
|
||||
@@ -22,6 +22,7 @@ export default function BookList() {
|
||||
const {setBook} = useContext(BookContext);
|
||||
const t = useTranslations();
|
||||
const {lang} = useContext<LangContextProps>(LangContext)
|
||||
const {isCurrentlyOffline} = useContext<OfflineContextType>(OfflineContext)
|
||||
|
||||
const [searchQuery, setSearchQuery] = useState<string>('');
|
||||
const [groupedBooks, setGroupedBooks] = useState<Record<string, BookProps[]>>({});
|
||||
@@ -114,10 +115,12 @@ export default function BookList() {
|
||||
async function getBooks(): Promise<void> {
|
||||
setIsLoadingBooks(true);
|
||||
try {
|
||||
const offlineDataService = getOfflineDataService();
|
||||
const bookResponse: BookListProps[] = await offlineDataService.getBooks(
|
||||
() => System.authGetQueryToServer<BookListProps[]>('books', accessToken, lang)
|
||||
);
|
||||
let bookResponse: BookListProps[] = [];
|
||||
if (!isCurrentlyOffline()) {
|
||||
bookResponse = await System.authGetQueryToServer<BookListProps[]>('books', accessToken, lang);
|
||||
} else {
|
||||
bookResponse = await window.electron.invoke<BookListProps[]>('db:book:books');
|
||||
}
|
||||
if (bookResponse) {
|
||||
const booksByType: Record<string, BookProps[]> = bookResponse.reduce((groups: Record<string, BookProps[]>, book: BookListProps): Record<string, BookProps[]> => {
|
||||
const imageDataUrl: string = book.coverImage ? 'data:image/jpeg;base64,' + book.coverImage : '';
|
||||
|
||||
Reference in New Issue
Block a user