Refactor character, chapter, and story components to support offline mode
- Add `OfflineContext` and `BookContext` to components for offline state management. - Introduce conditional logic to toggle between server API requests and offline IPC handlers for CRUD operations. - Refine `TextEditor`, `DraftCompanion`, and other components to disable actions or features unavailable in offline mode. - Improve error handling and user feedback in both online and offline scenarios.
This commit is contained in:
@@ -8,6 +8,7 @@ import {LangContext, LangContextProps} from "@/context/LangContext";
|
||||
import {AlertContext, AlertContextProps} from "@/context/AlertContext";
|
||||
import AlertBox from "@/components/AlertBox";
|
||||
import OfflineContext, {OfflineContextType} from "@/context/OfflineContext";
|
||||
import {BookContext} from "@/context/BookContext";
|
||||
|
||||
interface DeleteBookProps {
|
||||
bookId: string;
|
||||
@@ -17,6 +18,7 @@ export default function DeleteBook({bookId}: DeleteBookProps) {
|
||||
const {session, setSession} = useContext(SessionContext);
|
||||
const {lang} = useContext<LangContextProps>(LangContext)
|
||||
const {isCurrentlyOffline} = useContext<OfflineContextType>(OfflineContext);
|
||||
const {book} = useContext(BookContext);
|
||||
const [showConfirmBox, setShowConfirmBox] = useState<boolean>(false);
|
||||
const {errorMessage} = useContext<AlertContextProps>(AlertContext)
|
||||
|
||||
@@ -32,14 +34,20 @@ export default function DeleteBook({bookId}: DeleteBookProps) {
|
||||
id: bookId,
|
||||
});
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>(
|
||||
`book/delete`,
|
||||
{
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:delete', {
|
||||
id: bookId,
|
||||
},
|
||||
session.accessToken,
|
||||
lang
|
||||
);
|
||||
});
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>(
|
||||
`book/delete`,
|
||||
{
|
||||
id: bookId,
|
||||
},
|
||||
session.accessToken,
|
||||
lang
|
||||
);
|
||||
}
|
||||
}
|
||||
if (response) {
|
||||
setShowConfirmBox(false);
|
||||
|
||||
Reference in New Issue
Block a user