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

@@ -29,6 +29,7 @@ import {Dispatch, SetStateAction, useContext, useEffect} from "react";
import CharacterSectionElement from "@/components/book/settings/characters/CharacterSectionElement";
import {useTranslations} from "next-intl";
import {LangContext} from "@/context/LangContext";
import OfflineContext, {OfflineContextType} from "@/context/OfflineContext";
interface CharacterDetailProps {
selectedCharacter: CharacterProps | null;
@@ -55,6 +56,7 @@ export default function CharacterDetail(
) {
const t = useTranslations();
const {lang} = useContext(LangContext);
const {isCurrentlyOffline} = useContext<OfflineContextType>(OfflineContext);
const {session} = useContext(SessionContext);
const {errorMessage} = useContext(AlertContext);
@@ -66,9 +68,16 @@ export default function CharacterDetail(
async function getAttributes(): Promise<void> {
try {
const response: CharacterAttribute = await System.authGetQueryToServer<CharacterAttribute>(`character/attribute`, session.accessToken, lang, {
characterId: selectedCharacter?.id,
});
let response: CharacterAttribute;
if (isCurrentlyOffline()) {
response = await window.electron.invoke<CharacterAttribute>('db:character:attributes', {
characterId: selectedCharacter?.id,
});
} else {
response = await System.authGetQueryToServer<CharacterAttribute>(`character/attribute`, session.accessToken, lang, {
characterId: selectedCharacter?.id,
});
}
if (response) {
setSelectedCharacter({
id: selectedCharacter?.id ?? '',