forked from akai/readest
Support reading progress synchronization across platforms (#34)
This commit is contained in:
@@ -17,6 +17,7 @@ interface BookData {
|
||||
interface BookDataState {
|
||||
booksData: { [id: string]: BookData };
|
||||
getConfig: (key: string | null) => BookConfig | null;
|
||||
setConfig: (key: string, config: BookConfig) => void;
|
||||
saveConfig: (
|
||||
envConfig: EnvConfigType,
|
||||
bookKey: string,
|
||||
@@ -38,6 +39,20 @@ export const useBookDataStore = create<BookDataState>((set, get) => ({
|
||||
const id = key.split('-')[0]!;
|
||||
return get().booksData[id]?.config || null;
|
||||
},
|
||||
setConfig: (key: string, config: BookConfig) => {
|
||||
set((state: BookDataState) => {
|
||||
const id = key.split('-')[0]!;
|
||||
return {
|
||||
booksData: {
|
||||
...state.booksData,
|
||||
[id]: {
|
||||
...state.booksData[id]!,
|
||||
config,
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
},
|
||||
saveConfig: async (
|
||||
envConfig: EnvConfigType,
|
||||
bookKey: string,
|
||||
@@ -49,10 +64,10 @@ export const useBookDataStore = create<BookDataState>((set, get) => ({
|
||||
const bookIndex = library.findIndex((b) => b.hash === bookKey.split('-')[0]);
|
||||
if (bookIndex == -1) return;
|
||||
const book = library.splice(bookIndex, 1)[0]!;
|
||||
book.lastUpdated = Date.now();
|
||||
book.updatedAt = Date.now();
|
||||
library.unshift(book);
|
||||
setLibrary(library);
|
||||
config.lastUpdated = Date.now();
|
||||
config.updatedAt = Date.now();
|
||||
appService.saveBookConfig(book, config, settings);
|
||||
appService.saveLibraryBooks(library);
|
||||
},
|
||||
@@ -67,7 +82,7 @@ export const useBookDataStore = create<BookDataState>((set, get) => ({
|
||||
);
|
||||
updatedConfig = {
|
||||
...book.config,
|
||||
lastUpdated: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
booknotes: dedupedBooknotes,
|
||||
};
|
||||
return {
|
||||
@@ -77,7 +92,7 @@ export const useBookDataStore = create<BookDataState>((set, get) => ({
|
||||
...book,
|
||||
config: {
|
||||
...book.config,
|
||||
lastUpdated: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
booknotes: dedupedBooknotes,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@ import { create } from 'zustand';
|
||||
|
||||
import { BookContent, BookConfig, PageInfo, BookProgress, ViewSettings } from '@/types/book';
|
||||
import { EnvConfigType } from '@/services/environment';
|
||||
import { FoliateView } from '@/app/reader/components/FoliateViewer';
|
||||
import { FoliateView } from '@/types/view';
|
||||
import { BookDoc, DocumentLoader, SectionItem, TOCItem } from '@/libs/document';
|
||||
import { updateTocCFI, updateTocID } from '@/utils/toc';
|
||||
import { useSettingsStore } from './settingsStore';
|
||||
@@ -182,7 +182,7 @@ export const useReaderStore = create<ReaderStore>((set, get) => ({
|
||||
...bookData,
|
||||
config: {
|
||||
...bookData.config,
|
||||
lastUpdated: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
viewSettings,
|
||||
},
|
||||
},
|
||||
@@ -216,7 +216,7 @@ export const useReaderStore = create<ReaderStore>((set, get) => ({
|
||||
const oldConfig = bookData.config;
|
||||
const newConfig = {
|
||||
...bookData.config,
|
||||
lastUpdated: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
progress: [pageinfo.current, pageinfo.total] as [number, number],
|
||||
location,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user