Migrate from window.electron to tauri IPC functions across components
- Replaced `window.electron.invoke` calls with equivalent `tauri` function calls for all IPC interactions. - Removed `electron.d.ts` TypeScript definitions as they are no longer needed. - Updated related logic for offline/online state synchronization. - Added `types.rs` and `shared/mod.rs` modules to support Tauri IPC integration with Rust enums and shared logic. - Refactored IPC request queues to use updated handler names for consistency with Tauri.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
'use client'
|
||||
import * as tauri from '@/lib/tauri';
|
||||
import {ChangeEvent, Dispatch, RefObject, SetStateAction, useContext, useEffect, useRef, useState} from "react";
|
||||
import {AlertContext} from "@/context/AlertContext";
|
||||
import System from "@/lib/models/System";
|
||||
@@ -139,7 +140,7 @@ export default function AddNewBookForm({setCloseForm}: { setCloseForm: Dispatch<
|
||||
|
||||
let bookId: string;
|
||||
if (isCurrentlyOffline()) {
|
||||
bookId = await window.electron.invoke<string>('db:book:create', bookData);
|
||||
bookId = await tauri.createBook(bookData);
|
||||
} else {
|
||||
bookId = await System.authPostToServer<string>('book/add', bookData, token, lang);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as tauri from '@/lib/tauri';
|
||||
import {useContext, useEffect, useRef, useState} from "react";
|
||||
import System from "@/lib/models/System";
|
||||
import {AlertContext} from "@/context/AlertContext";
|
||||
@@ -178,11 +179,11 @@ export default function BookList() {
|
||||
const [onlineBooks, localBooks, onlineSeries, localSeries] = await Promise.all([
|
||||
System.authGetQueryToServer<BookProps[]>('books', accessToken, lang),
|
||||
offlineMode.isDatabaseInitialized
|
||||
? window.electron.invoke<BookProps[]>('db:book:books')
|
||||
? tauri.getBooks()
|
||||
: Promise.resolve([]),
|
||||
System.authGetQueryToServer<SeriesListItemProps[]>('series/list', accessToken, lang),
|
||||
offlineMode.isDatabaseInitialized
|
||||
? window.electron.invoke<SeriesListItemProps[]>('db:series:list')
|
||||
? tauri.getSeriesList() as Promise<SeriesListItemProps[]>
|
||||
: Promise.resolve([])
|
||||
]);
|
||||
|
||||
@@ -221,8 +222,8 @@ export default function BookList() {
|
||||
return;
|
||||
}
|
||||
const [localBooks, localSeries] = await Promise.all([
|
||||
window.electron.invoke<BookProps[]>('db:book:books'),
|
||||
window.electron.invoke<SeriesListItemProps[]>('db:series:list')
|
||||
tauri.getBooks(),
|
||||
tauri.getSeriesList() as Promise<SeriesListItemProps[]>
|
||||
]);
|
||||
booksResponse = localBooks.map(b => ({...b, itIsLocal: true}));
|
||||
seriesResponse = localSeries;
|
||||
@@ -396,24 +397,19 @@ export default function BookList() {
|
||||
let bookResponse: BookProps | null = null;
|
||||
|
||||
// DUAL LOGIC
|
||||
if (isCurrentlyOffline()) {
|
||||
if (!offlineMode.isDatabaseInitialized) {
|
||||
const isOfflineBook = localOnlyBooks.find((book: SyncedBook): boolean => book.id === bookId);
|
||||
if (isCurrentlyOffline() || isOfflineBook) {
|
||||
if (isCurrentlyOffline() && !offlineMode.isDatabaseInitialized) {
|
||||
errorMessage(t("bookList.errorBookDetails"));
|
||||
return;
|
||||
}
|
||||
bookResponse = await window.electron.invoke('db:book:bookBasicInformation', bookId);
|
||||
bookResponse = await tauri.getBookBasicInformation(bookId);
|
||||
if (bookResponse) localBookOnly = true;
|
||||
} else {
|
||||
const isOfflineBook = localOnlyBooks.find((book: SyncedBook): boolean => book.id === bookId);
|
||||
if (isOfflineBook) {
|
||||
bookResponse = await window.electron.invoke('db:book:bookBasicInformation', bookId);
|
||||
localBookOnly = true;
|
||||
}
|
||||
if (!bookResponse) {
|
||||
bookResponse = await System.authGetQueryToServer<BookProps>(
|
||||
'book/basic-information', accessToken, lang, {id: bookId}
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!bookResponse) {
|
||||
bookResponse = await System.authGetQueryToServer<BookProps>(
|
||||
'book/basic-information', accessToken, lang, {id: bookId}
|
||||
);
|
||||
}
|
||||
|
||||
if (!bookResponse) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
'use client'
|
||||
import * as tauri from '@/lib/tauri';
|
||||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
||||
import {faFeather, faTimes} from "@fortawesome/free-solid-svg-icons";
|
||||
import {ChangeEvent, forwardRef, useContext, useImperativeHandle, useState} from "react";
|
||||
@@ -131,12 +132,12 @@ function BasicInformationSetting(props: any, ref: any) {
|
||||
bookId: bookId
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:updateBasicInformation', basicInfoData);
|
||||
response = await tauri.updateBookBasicInfo(basicInfoData);
|
||||
} else {
|
||||
response = await System.authPostToServer<boolean>('book/basic-information', basicInfoData, userToken, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:updateBasicInformation', basicInfoData);
|
||||
addToQueue('update_book_basic_info', {data: basicInfoData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as tauri from '@/lib/tauri';
|
||||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
||||
import {faTrash} from "@fortawesome/free-solid-svg-icons";
|
||||
import {useContext, useState} from "react";
|
||||
@@ -40,7 +41,7 @@ export default function DeleteBook({bookId}: DeleteBookProps) {
|
||||
const deleteData = { id: bookId, deletedAt };
|
||||
|
||||
if (isCurrentlyOffline() || ifLocalOnlyBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:delete', deleteData);
|
||||
response = await tauri.deleteBook(deleteData.id, deleteData.deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>(
|
||||
`book/delete`,
|
||||
@@ -50,7 +51,7 @@ export default function DeleteBook({bookId}: DeleteBookProps) {
|
||||
);
|
||||
// If synced book and user wants to delete local too
|
||||
if (response && ifSyncedBook && deleteLocalToo) {
|
||||
await window.electron.invoke<boolean>('db:book:delete', deleteData);
|
||||
await tauri.deleteBook(deleteData.id, deleteData.deletedAt);
|
||||
}
|
||||
}
|
||||
if (response) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
'use client'
|
||||
import * as tauri from '@/lib/tauri';
|
||||
import React, {useCallback, useContext, useEffect, useState} from 'react';
|
||||
import {useTranslations} from 'next-intl';
|
||||
import {BookContext} from '@/context/BookContext';
|
||||
@@ -33,10 +34,7 @@ export default function ExportSetting(): React.JSX.Element {
|
||||
if (!book) return;
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const chaptersInfo: ChapterExportInfo[] = await window.electron.invoke<ChapterExportInfo[]>(
|
||||
'db:book:export:info',
|
||||
{bookId: book.bookId}
|
||||
);
|
||||
const chaptersInfo: ChapterExportInfo[] = await tauri.getBookExportInfo(book.bookId) as ChapterExportInfo[];
|
||||
setChapters(chaptersInfo);
|
||||
const initialSelections: ChapterExportSelection[] = chaptersInfo.map(
|
||||
(ch: ChapterExportInfo): ChapterExportSelection => ({
|
||||
@@ -92,7 +90,7 @@ export default function ExportSetting(): React.JSX.Element {
|
||||
.filter((s: ChapterExportSelection): boolean => s.selected)
|
||||
.map((s: ChapterExportSelection) => ({chapterId: s.chapterId, version: s.version}));
|
||||
|
||||
const result: boolean = await window.electron.invoke<boolean>('db:book:export', {
|
||||
const result: boolean = await tauri.exportBook({
|
||||
bookId: book.bookId,
|
||||
format,
|
||||
selections: selectedChapters.length === chapters.length ? null : selectedChapters
|
||||
|
||||
@@ -14,6 +14,7 @@ import {LangContext} from '@/context/LangContext';
|
||||
import OfflineContext, {OfflineContextType} from '@/context/OfflineContext';
|
||||
import {BookContext} from '@/context/BookContext';
|
||||
import System from '@/lib/models/System';
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
type AttributeResponse = { type: string; values: Attribute[] }[];
|
||||
|
||||
@@ -49,10 +50,8 @@ export default function CharacterEditorDetail({
|
||||
async function getAttributes(): Promise<void> {
|
||||
try {
|
||||
let response: AttributeResponse;
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<AttributeResponse>('db:character:attributes', {characterId: character?.id});
|
||||
} else if (book?.localBook) {
|
||||
response = await window.electron.invoke<AttributeResponse>('db:character:attributes', {characterId: character?.id});
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await tauri.getCharacterAttributes(character?.id!) as AttributeResponse;
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<AttributeResponse>(
|
||||
'character/attribute',
|
||||
|
||||
@@ -28,6 +28,7 @@ import OfflineContext, {OfflineContextType} from '@/context/OfflineContext';
|
||||
import {BookContext} from '@/context/BookContext';
|
||||
import System from '@/lib/models/System';
|
||||
import {Dispatch, SetStateAction} from 'react';
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
type AttributeResponse = { type: string; values: Attribute[] }[];
|
||||
|
||||
@@ -84,10 +85,8 @@ export default function CharacterEditorEdit({
|
||||
async function getAttributes(): Promise<void> {
|
||||
try {
|
||||
let response: AttributeResponse;
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<AttributeResponse>('db:character:attributes', {characterId: character?.id});
|
||||
} else if (book?.localBook) {
|
||||
response = await window.electron.invoke<AttributeResponse>('db:character:attributes', {characterId: character?.id});
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await tauri.getCharacterAttributes(character?.id!) as AttributeResponse;
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<AttributeResponse>(
|
||||
'character/attribute',
|
||||
|
||||
@@ -39,6 +39,7 @@ import {LangContext} from '@/context/LangContext';
|
||||
import OfflineContext, {OfflineContextType} from '@/context/OfflineContext';
|
||||
import {BookContext} from '@/context/BookContext';
|
||||
import System from '@/lib/models/System';
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
type AttributeResponse = { type: string; values: Attribute[] }[];
|
||||
|
||||
@@ -70,10 +71,8 @@ export default function CharacterSettingsDetail({
|
||||
async function getAttributes(): Promise<void> {
|
||||
try {
|
||||
let response: AttributeResponse;
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<AttributeResponse>('db:character:attributes', {characterId: character?.id});
|
||||
} else if (book?.localBook) {
|
||||
response = await window.electron.invoke<AttributeResponse>('db:character:attributes', {characterId: character?.id});
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await tauri.getCharacterAttributes(character?.id!) as AttributeResponse;
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<AttributeResponse>(
|
||||
'character/attribute',
|
||||
|
||||
@@ -37,6 +37,7 @@ import OfflineContext, {OfflineContextType} from '@/context/OfflineContext';
|
||||
import {BookContext} from '@/context/BookContext';
|
||||
import System from '@/lib/models/System';
|
||||
import {Dispatch, SetStateAction} from 'react';
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
type AttributeResponse = { type: string; values: Attribute[] }[];
|
||||
|
||||
@@ -94,10 +95,8 @@ export default function CharacterSettingsEdit({
|
||||
async function getAttributes(): Promise<void> {
|
||||
try {
|
||||
let response: AttributeResponse;
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<AttributeResponse>('db:character:attributes', {characterId: character?.id});
|
||||
} else if (book?.localBook) {
|
||||
response = await window.electron.invoke<AttributeResponse>('db:character:attributes', {characterId: character?.id});
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await tauri.getCharacterAttributes(character?.id!) as AttributeResponse;
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<AttributeResponse>(
|
||||
'character/attribute',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
'use client'
|
||||
import * as tauri from '@/lib/tauri';
|
||||
import {ChangeEvent, forwardRef, useContext, useEffect, useImperativeHandle, useState} from 'react';
|
||||
import System from '@/lib/models/System';
|
||||
import {AlertContext} from "@/context/AlertContext";
|
||||
@@ -83,14 +84,10 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
async function getAIGuideLine(): Promise<void> {
|
||||
try {
|
||||
let response: GuideLineAI;
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<GuideLineAI>('db:book:guideline:ai:get', {id: bookId});
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await tauri.getAIGuideLine(bookId);
|
||||
} else {
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<GuideLineAI>('db:book:guideline:ai:get', {id: bookId});
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<GuideLineAI>(`book/ai/guideline`, userToken, lang, {id: bookId});
|
||||
}
|
||||
response = await System.authGetQueryToServer<GuideLineAI>(`book/ai/guideline`, userToken, lang, {id: bookId});
|
||||
}
|
||||
if (response) {
|
||||
setPlotSummary(response.globalResume || '');
|
||||
@@ -113,19 +110,15 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
async function getGuideLine(): Promise<void> {
|
||||
try {
|
||||
let response: GuideLine;
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<GuideLine>('db:book:guideline:get', {id: bookId});
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await tauri.getGuideLine(bookId);
|
||||
} else {
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<GuideLine>('db:book:guideline:get', {id: bookId});
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<GuideLine>(
|
||||
`book/guide-line`,
|
||||
userToken,
|
||||
lang,
|
||||
{id: bookId},
|
||||
);
|
||||
}
|
||||
response = await System.authGetQueryToServer<GuideLine>(
|
||||
`book/guide-line`,
|
||||
userToken,
|
||||
lang,
|
||||
{id: bookId},
|
||||
);
|
||||
}
|
||||
if (response) {
|
||||
setTone(response.tone);
|
||||
@@ -165,7 +158,7 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
keyMessages: keyMessages,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:guideline:update', guidelineData);
|
||||
response = await tauri.updateGuideLine(guidelineData);
|
||||
} else {
|
||||
response = await System.authPostToServer<boolean>(
|
||||
'book/guide-line',
|
||||
@@ -175,7 +168,7 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:guideline:update', guidelineData);
|
||||
addToQueue('update_guideline', {data: guidelineData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
@@ -206,7 +199,7 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
themes: themes,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:guideline:ai:update', aiGuidelineData);
|
||||
response = await tauri.updateAIGuideLine(aiGuidelineData);
|
||||
} else {
|
||||
response = await System.authPostToServer<boolean>(
|
||||
'quillsense/book/guide-line',
|
||||
@@ -216,7 +209,7 @@ function GuideLineSetting(props: any, ref: any) {
|
||||
);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:guideline:ai:update', aiGuidelineData);
|
||||
addToQueue('update_ai_guideline', {data: aiGuidelineData});
|
||||
}
|
||||
}
|
||||
if (response) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import {SyncedSeries} from "@/lib/models/SyncedSeries";
|
||||
import ToggleSwitch from "@/components/form/ToggleSwitch";
|
||||
import {SeriesLocationElement, SeriesLocationItem, SeriesLocationSubElement} from "@/lib/models/Series";
|
||||
import SeriesImportSelector from "@/components/form/SeriesImportSelector";
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
interface SubElement {
|
||||
id: string;
|
||||
@@ -120,11 +121,7 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
try {
|
||||
let response: boolean;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:tool:update', {
|
||||
bookId: currentEntityId,
|
||||
toolName: 'locations',
|
||||
enabled: enabled
|
||||
});
|
||||
response = await tauri.updateBookToolSetting(currentEntityId, 'locations', enabled);
|
||||
} else {
|
||||
response = await System.authPatchToServer<boolean>('book/tool-setting', {
|
||||
bookId: currentEntityId,
|
||||
@@ -132,11 +129,11 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
enabled: enabled
|
||||
}, token, lang);
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:book:tool:update', {
|
||||
addToQueue('update_book_tool_setting', {data: {
|
||||
bookId: currentEntityId,
|
||||
toolName: 'locations',
|
||||
enabled: enabled
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (response && setBook && book) {
|
||||
@@ -162,7 +159,7 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
if (isSeriesMode) {
|
||||
let response: SeriesLocationItem[];
|
||||
if (isCurrentlyOffline() || localSeries) {
|
||||
response = await window.electron.invoke<SeriesLocationItem[]>('db:series:location:list', {seriesId: currentEntityId});
|
||||
response = await tauri.getSeriesLocationList(currentEntityId) as SeriesLocationItem[];
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<SeriesLocationItem[]>(
|
||||
'series/location/list',
|
||||
@@ -190,16 +187,12 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
}
|
||||
} else {
|
||||
let response: LocationListResponse;
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<LocationListResponse>('db:location:all', {bookid: currentEntityId});
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await tauri.getAllLocations(currentEntityId, true) as LocationListResponse;
|
||||
} else {
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<LocationListResponse>('db:location:all', {bookid: currentEntityId});
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<LocationListResponse>(`location/all`, token, lang, {
|
||||
bookid: currentEntityId,
|
||||
});
|
||||
}
|
||||
response = await System.authGetQueryToServer<LocationListResponse>(`location/all`, token, lang, {
|
||||
bookid: currentEntityId,
|
||||
});
|
||||
}
|
||||
if (response) {
|
||||
setSections(response.locations);
|
||||
@@ -238,7 +231,7 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
name: newSectionName,
|
||||
};
|
||||
if (isCurrentlyOffline() || localSeries) {
|
||||
sectionId = await window.electron.invoke<string>('db:series:location:section:add', addData);
|
||||
sectionId = await tauri.addSeriesLocationSection(addData);
|
||||
} else {
|
||||
sectionId = await System.authPostToServer<string>(
|
||||
'series/location/section/add',
|
||||
@@ -247,7 +240,7 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
lang
|
||||
);
|
||||
if (localSyncedSeries.find((s: SyncedSeries): boolean => s.id === seriesId)) {
|
||||
addToQueue('db:series:location:section:add', addData);
|
||||
addToQueue('add_series_location_section', {data: addData});
|
||||
}
|
||||
}
|
||||
if (!sectionId) {
|
||||
@@ -255,10 +248,7 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
return;
|
||||
}
|
||||
} else if (isCurrentlyOffline() || book?.localBook) {
|
||||
sectionId = await window.electron.invoke<string>('db:location:section:add', {
|
||||
bookId: currentEntityId,
|
||||
locationName: newSectionName,
|
||||
});
|
||||
sectionId = await tauri.addLocationSection(newSectionName, currentEntityId);
|
||||
} else {
|
||||
sectionId = await System.authPostToServer<string>(`location/section/add`, {
|
||||
bookId: currentEntityId,
|
||||
@@ -266,11 +256,11 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
}, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:location:section:add', {
|
||||
addToQueue('add_location_section', {data: {
|
||||
bookId: currentEntityId,
|
||||
sectionId,
|
||||
locationName: newSectionName,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!sectionId) {
|
||||
@@ -306,7 +296,7 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
name: newElementNames[sectionId],
|
||||
};
|
||||
if (isCurrentlyOffline() || localSeries) {
|
||||
elementId = await window.electron.invoke<string>('db:series:location:element:add', addData);
|
||||
elementId = await tauri.addSeriesLocationElement(addData);
|
||||
} else {
|
||||
elementId = await System.authPostToServer<string>(
|
||||
'series/location/element/add',
|
||||
@@ -315,7 +305,7 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
lang
|
||||
);
|
||||
if (localSyncedSeries.find((s: SyncedSeries): boolean => s.id === seriesId)) {
|
||||
addToQueue('db:series:location:element:add', addData);
|
||||
addToQueue('add_series_location_element', {data: addData});
|
||||
}
|
||||
}
|
||||
if (!elementId) {
|
||||
@@ -323,11 +313,7 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
return;
|
||||
}
|
||||
} else if (isCurrentlyOffline() || book?.localBook) {
|
||||
elementId = await window.electron.invoke<string>('db:location:element:add', {
|
||||
bookId: currentEntityId,
|
||||
locationId: sectionId,
|
||||
elementName: newElementNames[sectionId],
|
||||
});
|
||||
elementId = await tauri.addLocationElement(sectionId, newElementNames[sectionId]);
|
||||
} else {
|
||||
elementId = await System.authPostToServer<string>(`location/element/add`, {
|
||||
bookId: currentEntityId,
|
||||
@@ -337,12 +323,12 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:location:element:add', {
|
||||
addToQueue('add_location_element', {data: {
|
||||
bookId: currentEntityId,
|
||||
locationId: sectionId,
|
||||
elementId,
|
||||
elementName: newElementNames[sectionId],
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!elementId) {
|
||||
@@ -405,7 +391,7 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
name: newSubElementNames[elementIndex],
|
||||
};
|
||||
if (isCurrentlyOffline() || localSeries) {
|
||||
subElementId = await window.electron.invoke<string>('db:series:location:subelement:add', addData);
|
||||
subElementId = await tauri.addSeriesLocationSubElement(addData);
|
||||
} else {
|
||||
subElementId = await System.authPostToServer<string>(
|
||||
'series/location/sub-element/add',
|
||||
@@ -414,7 +400,7 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
lang
|
||||
);
|
||||
if (localSyncedSeries.find((s: SyncedSeries): boolean => s.id === seriesId)) {
|
||||
addToQueue('db:series:location:subelement:add', addData);
|
||||
addToQueue('add_series_location_sub_element', {data: addData});
|
||||
}
|
||||
}
|
||||
if (!subElementId) {
|
||||
@@ -422,10 +408,7 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
return;
|
||||
}
|
||||
} else if (isCurrentlyOffline() || book?.localBook) {
|
||||
subElementId = await window.electron.invoke<string>('db:location:subelement:add', {
|
||||
elementId: elementId,
|
||||
subElementName: newSubElementNames[elementIndex],
|
||||
});
|
||||
subElementId = await tauri.addLocationSubElement(elementId, newSubElementNames[elementIndex]);
|
||||
} else {
|
||||
subElementId = await System.authPostToServer<string>(`location/sub-element/add`, {
|
||||
elementId: elementId,
|
||||
@@ -433,11 +416,11 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
}, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:location:subelement:add', {
|
||||
addToQueue('add_location_sub_element', {data: {
|
||||
elementId: elementId,
|
||||
subElementId,
|
||||
subElementName: newSubElementNames[elementIndex],
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!subElementId) {
|
||||
@@ -490,26 +473,24 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
if (isSeriesMode) {
|
||||
const deleteData = {elementId: elementId, deletedAt};
|
||||
if (isCurrentlyOffline() || localSeries) {
|
||||
response = await window.electron.invoke<boolean>('db:series:location:element:delete', deleteData);
|
||||
response = await tauri.deleteSeriesLocationElement(deleteData.elementId!, deleteData.deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('series/location/element/delete', deleteData, token, lang);
|
||||
if (localSyncedSeries.find((s: SyncedSeries): boolean => s.id === seriesId)) {
|
||||
addToQueue('db:series:location:element:delete', deleteData);
|
||||
addToQueue('delete_series_location_element', {data: deleteData});
|
||||
}
|
||||
}
|
||||
} else if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:location:element:delete', {
|
||||
elementId: elementId, bookId: currentEntityId, deletedAt,
|
||||
});
|
||||
response = await tauri.deleteLocationElement(elementId!, currentEntityId, deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>(`location/element/delete`, {
|
||||
elementId: elementId, bookId: currentEntityId, deletedAt,
|
||||
}, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:location:element:delete', {
|
||||
addToQueue('delete_location_element', {data: {
|
||||
elementId: elementId, bookId: currentEntityId, deletedAt,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
@@ -541,26 +522,24 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
if (isSeriesMode) {
|
||||
const deleteData = {subElementId: subElementId, deletedAt};
|
||||
if (isCurrentlyOffline() || localSeries) {
|
||||
response = await window.electron.invoke<boolean>('db:series:location:subelement:delete', deleteData);
|
||||
response = await tauri.deleteSeriesLocationSubElement(deleteData.subElementId!, deleteData.deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('series/location/sub-element/delete', deleteData, token, lang);
|
||||
if (localSyncedSeries.find((s: SyncedSeries): boolean => s.id === seriesId)) {
|
||||
addToQueue('db:series:location:subelement:delete', deleteData);
|
||||
addToQueue('delete_series_location_sub_element', {data: deleteData});
|
||||
}
|
||||
}
|
||||
} else if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:location:subelement:delete', {
|
||||
subElementId: subElementId, bookId: currentEntityId, deletedAt,
|
||||
});
|
||||
response = await tauri.deleteLocationSubElement(subElementId!, currentEntityId, deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>(`location/sub-element/delete`, {
|
||||
subElementId: subElementId, bookId: currentEntityId, deletedAt,
|
||||
}, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:location:subelement:delete', {
|
||||
addToQueue('delete_location_sub_element', {data: {
|
||||
subElementId: subElementId, bookId: currentEntityId, deletedAt,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
@@ -587,26 +566,24 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
if (isSeriesMode) {
|
||||
const deleteData = {locationId: sectionId, deletedAt};
|
||||
if (isCurrentlyOffline() || localSeries) {
|
||||
response = await window.electron.invoke<boolean>('db:series:location:delete', deleteData);
|
||||
response = await tauri.deleteSeriesLocation(deleteData.locationId, deleteData.deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('series/location/delete', deleteData, token, lang);
|
||||
if (localSyncedSeries.find((s: SyncedSeries): boolean => s.id === seriesId)) {
|
||||
addToQueue('db:series:location:delete', deleteData);
|
||||
addToQueue('delete_series_location', {data: deleteData});
|
||||
}
|
||||
}
|
||||
} else if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:location:delete', {
|
||||
locationId: sectionId, bookId: currentEntityId, deletedAt,
|
||||
});
|
||||
response = await tauri.deleteLocationSection(sectionId, currentEntityId, deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>(`location/delete`, {
|
||||
locationId: sectionId, bookId: currentEntityId, deletedAt,
|
||||
}, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:location:delete', {
|
||||
addToQueue('delete_location_section', {data: {
|
||||
locationId: sectionId, bookId: currentEntityId, deletedAt,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
@@ -628,18 +605,16 @@ export function LocationComponent(props: LocationComponentProps, ref: React.Ref<
|
||||
try {
|
||||
let response: boolean;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:location:update', {
|
||||
locations: sections,
|
||||
});
|
||||
response = await tauri.updateLocations(sections) as boolean;
|
||||
} else {
|
||||
response = await System.authPostToServer<boolean>(`location/update`, {
|
||||
locations: sections,
|
||||
}, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:location:update', {
|
||||
addToQueue('update_locations', {data: {
|
||||
locations: sections,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import OfflineContext, {OfflineContextType} from "@/context/OfflineContext";
|
||||
import {LocalSyncQueueContext, LocalSyncQueueContextProps} from "@/context/SyncQueueContext";
|
||||
import {BooksSyncContext, BooksSyncContextProps} from "@/context/BooksSyncContext";
|
||||
import {SyncedBook} from "@/lib/models/SyncedBook";
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
interface ActProps {
|
||||
acts: ActType[];
|
||||
@@ -80,10 +81,7 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
|
||||
try {
|
||||
let incidentId: string;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
incidentId = await window.electron.invoke<string>('db:book:incident:add', {
|
||||
bookId,
|
||||
name: newIncidentTitle,
|
||||
});
|
||||
incidentId = await tauri.addIncident(bookId!, newIncidentTitle);
|
||||
} else {
|
||||
incidentId = await System.authPostToServer<string>('book/incident/new', {
|
||||
bookId,
|
||||
@@ -91,11 +89,11 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
|
||||
}, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:incident:add', {
|
||||
addToQueue('add_incident', {data: {
|
||||
bookId,
|
||||
incidentId,
|
||||
name: newIncidentTitle,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!incidentId) {
|
||||
@@ -134,12 +132,12 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
|
||||
let response: boolean;
|
||||
const deleteData = { bookId, incidentId, deletedAt: System.timeStampInSeconds() };
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:incident:remove', deleteData);
|
||||
response = await tauri.removeIncident(deleteData.bookId!, deleteData.incidentId, deleteData.deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('book/incident/remove', deleteData, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:incident:remove', deleteData);
|
||||
addToQueue('remove_incident', {data: deleteData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
@@ -177,15 +175,15 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
|
||||
incidentId: selectedIncidentId,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
plotId = await window.electron.invoke<string>('db:book:plot:add', plotData);
|
||||
plotId = await tauri.addPlotPoint(plotData.bookId!, plotData.name, plotData.incidentId);
|
||||
} else {
|
||||
plotId = await System.authPostToServer<string>('book/plot/new', plotData, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:plot:add', {
|
||||
addToQueue('add_plot_point', {data: {
|
||||
...plotData,
|
||||
plotId,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!plotId) {
|
||||
@@ -225,12 +223,12 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
|
||||
let response: boolean;
|
||||
const deleteData = { plotId: plotPointId, bookId, deletedAt: System.timeStampInSeconds() };
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:plot:remove', deleteData);
|
||||
response = await tauri.removePlotPoint(deleteData.plotId, deleteData.bookId!, deleteData.deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('book/plot/remove', deleteData, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:plot:remove', deleteData);
|
||||
addToQueue('remove_plot_point', {data: deleteData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
@@ -279,15 +277,15 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
|
||||
incidentId: destination === 'incident' ? itemId : null,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
linkId = await window.electron.invoke<string>('db:chapter:information:add', linkData);
|
||||
linkId = await tauri.addChapterInformation(linkData as any);
|
||||
} else {
|
||||
linkId = await System.authPostToServer<string>('chapter/resume/add', linkData, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:chapter:information:add', {
|
||||
addToQueue('add_chapter_information', {data: {
|
||||
...linkData,
|
||||
chapterInfoId: linkId,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!linkId) {
|
||||
@@ -367,12 +365,12 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
|
||||
let response: boolean;
|
||||
const unlinkData = { chapterInfoId, bookId, deletedAt: System.timeStampInSeconds() };
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:chapter:information:remove', unlinkData);
|
||||
response = await tauri.removeChapterInformation(unlinkData.chapterInfoId, unlinkData.bookId!, unlinkData.deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('chapter/resume/remove', unlinkData, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:chapter:information:remove', unlinkData);
|
||||
addToQueue('remove_chapter_information', {data: unlinkData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import OfflineContext, {OfflineContextType} from "@/context/OfflineContext";
|
||||
import {LocalSyncQueueContext, LocalSyncQueueContextProps} from "@/context/SyncQueueContext";
|
||||
import {BooksSyncContext, BooksSyncContextProps} from "@/context/BooksSyncContext";
|
||||
import {SyncedBook} from "@/lib/models/SyncedBook";
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
interface IssuesProps {
|
||||
issues: Issue[];
|
||||
@@ -42,10 +43,7 @@ export default function Issues({issues, setIssues}: IssuesProps) {
|
||||
try {
|
||||
let issueId: string;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
issueId = await window.electron.invoke<string>('db:book:issue:add', {
|
||||
bookId,
|
||||
name: newIssueName,
|
||||
});
|
||||
issueId = await tauri.addIssue(bookId!, newIssueName);
|
||||
} else {
|
||||
issueId = await System.authPostToServer<string>('book/issue/add', {
|
||||
bookId,
|
||||
@@ -53,11 +51,11 @@ export default function Issues({issues, setIssues}: IssuesProps) {
|
||||
}, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:issue:add', {
|
||||
addToQueue('add_issue', {data: {
|
||||
bookId,
|
||||
issueId,
|
||||
name: newIssueName,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!issueId) {
|
||||
@@ -90,11 +88,7 @@ export default function Issues({issues, setIssues}: IssuesProps) {
|
||||
let response: boolean;
|
||||
const deletedAt: number = System.timeStampInSeconds();
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:issue:remove', {
|
||||
bookId,
|
||||
issueId,
|
||||
deletedAt,
|
||||
});
|
||||
response = await tauri.removeIssue(bookId!, issueId, deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>(
|
||||
'book/issue/remove',
|
||||
@@ -108,11 +102,11 @@ export default function Issues({issues, setIssues}: IssuesProps) {
|
||||
);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:issue:remove', {
|
||||
addToQueue('remove_issue', {data: {
|
||||
bookId,
|
||||
issueId,
|
||||
deletedAt,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (response) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import OfflineContext, {OfflineContextType} from "@/context/OfflineContext";
|
||||
import {LocalSyncQueueContext, LocalSyncQueueContextProps} from "@/context/SyncQueueContext";
|
||||
import {BooksSyncContext, BooksSyncContextProps} from "@/context/BooksSyncContext";
|
||||
import {SyncedBook} from "@/lib/models/SyncedBook";
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
interface MainChapterProps {
|
||||
chapters: ChapterListProps[];
|
||||
@@ -93,12 +94,12 @@ export default function MainChapter({chapters, setChapters}: MainChapterProps) {
|
||||
deletedAt,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:chapter:remove', deleteData);
|
||||
response = await tauri.removeChapter(deleteData.chapterId, deleteData.bookId!, deleteData.deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('chapter/remove', deleteData, token, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:chapter:remove', deleteData);
|
||||
addToQueue('remove_chapter', {data: deleteData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
@@ -129,15 +130,15 @@ export default function MainChapter({chapters, setChapters}: MainChapterProps) {
|
||||
title: newChapterTitle,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
responseId = await window.electron.invoke<string>('db:chapter:add', chapterData);
|
||||
responseId = await tauri.addChapter(chapterData);
|
||||
} else {
|
||||
responseId = await System.authPostToServer<string>('chapter/add', chapterData, token);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:chapter:add', {
|
||||
addToQueue('add_chapter', {data: {
|
||||
...chapterData,
|
||||
chapterId: responseId,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!responseId) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import OfflineContext, {OfflineContextType} from "@/context/OfflineContext";
|
||||
import {LocalSyncQueueContext, LocalSyncQueueContextProps} from "@/context/SyncQueueContext";
|
||||
import {BooksSyncContext, BooksSyncContextProps} from "@/context/BooksSyncContext";
|
||||
import {SyncedBook} from "@/lib/models/SyncedBook";
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
export const StoryContext = createContext<{
|
||||
acts: ActType[];
|
||||
@@ -76,16 +77,12 @@ export function Story(props: any, ref: any) {
|
||||
async function getStoryData(): Promise<void> {
|
||||
try {
|
||||
let response: StoryFetchData;
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<StoryFetchData>('db:book:story:get', {bookid: bookId});
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await tauri.getBookStory(bookId) as StoryFetchData;
|
||||
} else {
|
||||
if (book?.localBook) {
|
||||
response = await window.electron.invoke<StoryFetchData>('db:book:story:get', {bookid: bookId});
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<StoryFetchData>(`book/story`, userToken, lang, {
|
||||
bookid: bookId,
|
||||
});
|
||||
}
|
||||
response = await System.authGetQueryToServer<StoryFetchData>(`book/story`, userToken, lang, {
|
||||
bookid: bookId,
|
||||
});
|
||||
}
|
||||
if (response) {
|
||||
setActs(response.acts);
|
||||
@@ -143,12 +140,12 @@ export function Story(props: any, ref: any) {
|
||||
issues,
|
||||
};
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:story:update', storyData);
|
||||
response = await tauri.updateBookStory(storyData);
|
||||
} else {
|
||||
response = await System.authPostToServer<boolean>('book/story', storyData, userToken, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
|
||||
addToQueue('db:book:story:update', storyData);
|
||||
addToQueue('update_book_story', {data: storyData});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import {SyncedBook} from "@/lib/models/SyncedBook";
|
||||
import {SeriesContext, SeriesContextProps} from "@/context/SeriesContext";
|
||||
import {SeriesSyncContext, SeriesSyncContextProps} from "@/context/SeriesSyncContext";
|
||||
import {SyncedSeries} from "@/lib/models/SyncedSeries";
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
interface WorldElementInputProps {
|
||||
sectionLabel: string;
|
||||
@@ -69,26 +70,24 @@ export default function WorldElementComponent({sectionLabel, sectionType}: World
|
||||
if (isSeriesMode) {
|
||||
const deleteData = {elementId, deletedAt};
|
||||
if (isCurrentlyOffline() || localSeries) {
|
||||
response = await window.electron.invoke<boolean>('db:series:world:element:delete', deleteData);
|
||||
response = await tauri.deleteSeriesWorldElement(elementId, deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('series/world/element/delete', deleteData, session.accessToken, lang);
|
||||
if (localSyncedSeries.find((s: SyncedSeries): boolean => s.id === seriesId)) {
|
||||
addToQueue('db:series:world:element:delete', deleteData);
|
||||
addToQueue('delete_series_world_element', {data: deleteData});
|
||||
}
|
||||
}
|
||||
} else if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:world:element:remove', {
|
||||
elementId, bookId: book?.bookId, deletedAt,
|
||||
});
|
||||
response = await tauri.removeWorldElement(elementId, book?.bookId || '', deletedAt);
|
||||
} else {
|
||||
response = await System.authDeleteToServer<boolean>('book/world/element/delete', {
|
||||
elementId, bookId: book?.bookId, deletedAt,
|
||||
}, session.accessToken, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === book?.bookId)) {
|
||||
addToQueue('db:book:world:element:remove', {
|
||||
addToQueue('remove_world_element', {data: {
|
||||
elementId: elementId, bookId: book?.bookId, deletedAt,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!response) {
|
||||
@@ -123,7 +122,7 @@ export default function WorldElementComponent({sectionLabel, sectionType}: World
|
||||
name: newElementName,
|
||||
};
|
||||
if (isCurrentlyOffline() || localSeries) {
|
||||
elementId = await window.electron.invoke<string>('db:series:world:element:add', addData);
|
||||
elementId = await tauri.addSeriesWorldElement(addData);
|
||||
} else {
|
||||
elementId = await System.authPostToServer<string>(
|
||||
'series/world/element/add',
|
||||
@@ -132,7 +131,7 @@ export default function WorldElementComponent({sectionLabel, sectionType}: World
|
||||
lang
|
||||
);
|
||||
if (localSyncedSeries.find((s: SyncedSeries): boolean => s.id === seriesId)) {
|
||||
addToQueue('db:series:world:element:add', addData);
|
||||
addToQueue('add_series_world_element', {data: addData});
|
||||
}
|
||||
}
|
||||
if (!elementId) {
|
||||
@@ -140,11 +139,7 @@ export default function WorldElementComponent({sectionLabel, sectionType}: World
|
||||
return;
|
||||
}
|
||||
} else if (isCurrentlyOffline() || book?.localBook) {
|
||||
elementId = await window.electron.invoke<string>('db:book:world:element:add', {
|
||||
elementType: section,
|
||||
worldId: worlds[selectedWorldIndex].id,
|
||||
elementName: newElementName,
|
||||
});
|
||||
elementId = await tauri.addWorldElement(worlds[selectedWorldIndex].id, newElementName, section as string);
|
||||
} else {
|
||||
elementId = await System.authPostToServer('book/world/element/add', {
|
||||
elementType: section,
|
||||
@@ -153,12 +148,12 @@ export default function WorldElementComponent({sectionLabel, sectionType}: World
|
||||
}, session.accessToken, lang);
|
||||
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === book?.bookId)) {
|
||||
addToQueue('db:book:world:element:add', {
|
||||
addToQueue('add_world_element', {data: {
|
||||
elementType: section,
|
||||
worldId: worlds[selectedWorldIndex].id,
|
||||
elementId,
|
||||
elementName: newElementName,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (!elementId) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import ToggleSwitch from "@/components/form/ToggleSwitch";
|
||||
import {SeriesWorldProps, SeriesWorldListItem} from "@/lib/models/Series";
|
||||
import SeriesImportSelector from "@/components/form/SeriesImportSelector";
|
||||
import SyncFieldWrapper from "@/components/form/SyncFieldWrapper";
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
export interface ElementSection {
|
||||
title: string;
|
||||
@@ -99,11 +100,7 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
try {
|
||||
let response: boolean;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<boolean>('db:book:tool:update', {
|
||||
bookId: currentEntityId,
|
||||
toolName: 'worlds',
|
||||
enabled: enabled
|
||||
});
|
||||
response = await tauri.updateBookToolSetting(currentEntityId, 'worlds', enabled);
|
||||
} else {
|
||||
response = await System.authPatchToServer<boolean>('book/tool-setting', {
|
||||
bookId: currentEntityId,
|
||||
@@ -111,11 +108,11 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
enabled: enabled
|
||||
}, session.accessToken, lang);
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:book:tool:update', {
|
||||
addToQueue('update_book_tool_setting', {data: {
|
||||
bookId: currentEntityId,
|
||||
toolName: 'worlds',
|
||||
enabled: enabled
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
if (response && setBook && book) {
|
||||
@@ -176,7 +173,7 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
// Book mode: dual offline/online logic
|
||||
let response: WorldListResponse;
|
||||
if (isCurrentlyOffline() || book?.localBook) {
|
||||
response = await window.electron.invoke<WorldListResponse>('db:book:worlds:get', {bookid: currentEntityId});
|
||||
response = await tauri.getWorlds(currentEntityId, true);
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<WorldListResponse>('book/worlds', session.accessToken, lang, {
|
||||
bookid: currentEntityId,
|
||||
@@ -237,10 +234,7 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
}
|
||||
} else if (isCurrentlyOffline() || book?.localBook) {
|
||||
// Book mode: offline/local
|
||||
newWorldId = await window.electron.invoke<string>('db:book:world:add', {
|
||||
worldName: newWorldName,
|
||||
bookId: currentEntityId,
|
||||
});
|
||||
newWorldId = await tauri.addWorld(currentEntityId, newWorldName);
|
||||
if (!newWorldId) {
|
||||
errorMessage(t("worldSetting.addWorldError"));
|
||||
return;
|
||||
@@ -256,11 +250,11 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
return;
|
||||
}
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:book:world:add', {
|
||||
addToQueue('add_world', {data: {
|
||||
worldName: newWorldName,
|
||||
worldId: newWorldId,
|
||||
bookId: currentEntityId,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
const newWorld: WorldProps = {
|
||||
@@ -319,10 +313,7 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
}, session.accessToken, lang);
|
||||
} else if (isCurrentlyOffline() || book?.localBook) {
|
||||
// Book mode: offline/local
|
||||
response = await window.electron.invoke<boolean>('db:book:world:update', {
|
||||
world: currentWorld,
|
||||
bookId: currentEntityId,
|
||||
});
|
||||
response = await tauri.updateWorld(currentWorld);
|
||||
} else {
|
||||
// Book mode: online
|
||||
response = await System.authPatchToServer<boolean>('book/world/update', {
|
||||
@@ -330,10 +321,10 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
bookId: currentEntityId,
|
||||
}, session.accessToken, lang);
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:book:world:update', {
|
||||
addToQueue('update_world', {data: {
|
||||
world: currentWorld,
|
||||
bookId: currentEntityId,
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,11 +415,11 @@ export function WorldSetting(props: WorldSettingProps, ref: React.Ref<{ handleSa
|
||||
|
||||
// Sync to local if book is synced
|
||||
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === currentEntityId)) {
|
||||
addToQueue('db:book:world:add', {
|
||||
addToQueue('add_world', {data: {
|
||||
worldName: seriesWorld.name,
|
||||
worldId: worldId,
|
||||
bookId: currentEntityId,
|
||||
});
|
||||
}});
|
||||
}
|
||||
|
||||
const newWorld: WorldProps = {
|
||||
|
||||
Reference in New Issue
Block a user