Add offline mode logic for book, story, and world operations

- Integrate `OfflineContext` into book, story settings, and related components.
- Add conditional logic to toggle between server API requests and offline IPC handlers (`db:book:delete`, `db:book:story:get`, `db:location:all`, etc.).
- Refactor and update IPC handlers to accept structured data arguments for improved consistency (`data: object`).
- Ensure stricter typings in IPC handlers and frontend functions.
- Improve error handling and user feedback in both online and offline modes.
This commit is contained in:
natreex
2025-11-26 22:52:34 -05:00
parent e1abcd9490
commit 23f1592c22
15 changed files with 518 additions and 201 deletions

View File

@@ -7,6 +7,7 @@ import {BookProps} from "@/lib/models/Book";
import {LangContext, LangContextProps} from "@/context/LangContext";
import {AlertContext, AlertContextProps} from "@/context/AlertContext";
import AlertBox from "@/components/AlertBox";
import OfflineContext, {OfflineContextType} from "@/context/OfflineContext";
interface DeleteBookProps {
bookId: string;
@@ -15,6 +16,7 @@ interface DeleteBookProps {
export default function DeleteBook({bookId}: DeleteBookProps) {
const {session, setSession} = useContext(SessionContext);
const {lang} = useContext<LangContextProps>(LangContext)
const {isCurrentlyOffline} = useContext<OfflineContextType>(OfflineContext);
const [showConfirmBox, setShowConfirmBox] = useState<boolean>(false);
const {errorMessage} = useContext<AlertContextProps>(AlertContext)
@@ -24,14 +26,21 @@ export default function DeleteBook({bookId}: DeleteBookProps) {
async function handleDeleteBook(): Promise<void> {
try {
const response: boolean = await System.authDeleteToServer<boolean>(
`book/delete`,
{
let response: boolean;
if (isCurrentlyOffline()) {
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);
const updatedBooks: BookProps[] = (session.user?.books || []).reduce((acc: BookProps[], book: BookProps): BookProps[] => {