Refactor IPC handlers, types, and models for streamlined data handling
- Unified return types across IPC handlers (`Character`, `Location`, `World`, and `Book`) for consistency. - Replaced `BookListProps` with `BookProps` for simplified type usage in components and handlers. - Cleaned up obsolete `BookListProps` interface and applied consistent typings throughout. - Updated imports to include revised response types (`CharacterListResponse`, `LocationListResponse`, `WorldListResponse`). - Adjusted data transformation logic in `BookList` and related components to align with new type definitions.
This commit is contained in:
@@ -9,7 +9,7 @@ import {faGear, faGlobe, faHome} from "@fortawesome/free-solid-svg-icons";
|
|||||||
import {SelectBoxProps} from "@/shared/interface";
|
import {SelectBoxProps} from "@/shared/interface";
|
||||||
import {AlertContext} from "@/context/AlertContext";
|
import {AlertContext} from "@/context/AlertContext";
|
||||||
import {SessionContext} from "@/context/SessionContext";
|
import {SessionContext} from "@/context/SessionContext";
|
||||||
import Book, {BookListProps} from "@/lib/models/Book";
|
import Book, {BookProps} from "@/lib/models/Book";
|
||||||
import Modal from "@/components/Modal";
|
import Modal from "@/components/Modal";
|
||||||
import BookSetting from "@/components/book/settings/BookSetting";
|
import BookSetting from "@/components/book/settings/BookSetting";
|
||||||
import SelectBox from "@/components/form/SelectBox";
|
import SelectBox from "@/components/form/SelectBox";
|
||||||
@@ -61,7 +61,7 @@ export default function ScribeControllerBar() {
|
|||||||
|
|
||||||
async function getBook(bookId: string): Promise<void> {
|
async function getBook(bookId: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const response: BookListProps = await System.authGetQueryToServer<BookListProps>(`book/basic-information`, session.accessToken, lang, {
|
const response: BookProps = await System.authGetQueryToServer<BookProps>(`book/basic-information`, session.accessToken, lang, {
|
||||||
id: bookId,
|
id: bookId,
|
||||||
});
|
});
|
||||||
if (!response) {
|
if (!response) {
|
||||||
@@ -69,12 +69,12 @@ export default function ScribeControllerBar() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setBook!!({
|
setBook!!({
|
||||||
bookId: response.id,
|
bookId: response.bookId,
|
||||||
type: response.type,
|
type: response.type,
|
||||||
title: response.title,
|
title: response.title,
|
||||||
subTitle: response.subTitle,
|
subTitle: response.subTitle,
|
||||||
summary: response.summary,
|
summary: response.summary,
|
||||||
publicationDate: response.desiredReleaseDate,
|
publicationDate: response.publicationDate,
|
||||||
desiredWordCount: response.desiredWordCount,
|
desiredWordCount: response.desiredWordCount,
|
||||||
totalWordCount: response.desiredWordCount,
|
totalWordCount: response.desiredWordCount,
|
||||||
quillsenseEnabled: response.quillsenseEnabled,
|
quillsenseEnabled: response.quillsenseEnabled,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import SearchBook from "./SearchBook";
|
|||||||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
||||||
import {faBook, faDownload, faGear, faTrash} from "@fortawesome/free-solid-svg-icons";
|
import {faBook, faDownload, faGear, faTrash} from "@fortawesome/free-solid-svg-icons";
|
||||||
import {SessionContext} from "@/context/SessionContext";
|
import {SessionContext} from "@/context/SessionContext";
|
||||||
import Book, {BookListProps, BookProps} from "@/lib/models/Book";
|
import Book, {BookProps} from "@/lib/models/Book";
|
||||||
import BookCard from "@/components/book/BookCard";
|
import BookCard from "@/components/book/BookCard";
|
||||||
import BookCardSkeleton from "@/components/book/BookCardSkeleton";
|
import BookCardSkeleton from "@/components/book/BookCardSkeleton";
|
||||||
import GuideTour, {GuideStep} from "@/components/GuideTour";
|
import GuideTour, {GuideStep} from "@/components/GuideTour";
|
||||||
@@ -139,40 +139,40 @@ export default function BookList() {
|
|||||||
async function getBooks(): Promise<void> {
|
async function getBooks(): Promise<void> {
|
||||||
setIsLoadingBooks(true);
|
setIsLoadingBooks(true);
|
||||||
try {
|
try {
|
||||||
let bookResponse: (BookListProps & { itIsLocal: boolean })[] = [];
|
let bookResponse: (BookProps & { itIsLocal: boolean })[] = [];
|
||||||
if (!isCurrentlyOffline()) {
|
if (!isCurrentlyOffline()) {
|
||||||
const [onlineBooks, localBooks]: [BookListProps[], BookListProps[]] = await Promise.all([
|
const [onlineBooks, localBooks]: [BookProps[], BookProps[]] = await Promise.all([
|
||||||
System.authGetQueryToServer<BookListProps[]>('books', accessToken, lang),
|
System.authGetQueryToServer<BookProps[]>('books', accessToken, lang),
|
||||||
offlineMode.isDatabaseInitialized
|
offlineMode.isDatabaseInitialized
|
||||||
? window.electron.invoke<BookListProps[]>('db:book:books')
|
? window.electron.invoke<BookProps[]>('db:book:books')
|
||||||
: Promise.resolve([])
|
: Promise.resolve([])
|
||||||
]);
|
]);
|
||||||
const onlineBookIds: Set<string> = new Set(onlineBooks.map((book: BookListProps): string => book.id));
|
const onlineBookIds: Set<string> = new Set(onlineBooks.map((book: BookProps): string => book.bookId));
|
||||||
const uniqueLocalBooks: BookListProps[] = localBooks.filter((book: BookListProps): boolean => !onlineBookIds.has(book.id));
|
const uniqueLocalBooks: BookProps[] = localBooks.filter((book: BookProps): boolean => !onlineBookIds.has(book.bookId));
|
||||||
bookResponse = [
|
bookResponse = [
|
||||||
...onlineBooks.map((book: BookListProps): BookListProps & { itIsLocal: boolean } => ({ ...book, itIsLocal: false })),
|
...onlineBooks.map((book: BookProps): BookProps & { itIsLocal: boolean } => ({ ...book, itIsLocal: false })),
|
||||||
...uniqueLocalBooks.map((book: BookListProps): BookListProps & { itIsLocal: boolean } => ({ ...book, itIsLocal: true }))
|
...uniqueLocalBooks.map((book: BookProps): BookProps & { itIsLocal: boolean } => ({ ...book, itIsLocal: true }))
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
if (!offlineMode.isDatabaseInitialized) {
|
if (!offlineMode.isDatabaseInitialized) {
|
||||||
setIsLoadingBooks(false);
|
setIsLoadingBooks(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const localBooks: BookListProps[] = await window.electron.invoke<BookListProps[]>('db:book:books');
|
const localBooks: BookProps[] = await window.electron.invoke<BookProps[]>('db:book:books');
|
||||||
bookResponse = localBooks.map((book: BookListProps): BookListProps & { itIsLocal: boolean } => ({ ...book, itIsLocal: true }));
|
bookResponse = localBooks.map((book: BookProps): BookProps & { itIsLocal: boolean } => ({ ...book, itIsLocal: true }));
|
||||||
}
|
}
|
||||||
if (bookResponse) {
|
if (bookResponse) {
|
||||||
const booksByType: Record<string, BookProps[]> = bookResponse.reduce((groups: Record<string, BookProps[]>, book: BookListProps): Record<string, BookProps[]> => {
|
const booksByType: Record<string, BookProps[]> = bookResponse.reduce((groups: Record<string, BookProps[]>, book: BookProps): Record<string, BookProps[]> => {
|
||||||
const imageDataUrl: string = book.coverImage ? 'data:image/jpeg;base64,' + book.coverImage : '';
|
const imageDataUrl: string = book.coverImage ? 'data:image/jpeg;base64,' + book.coverImage : '';
|
||||||
const categoryLabel: string = Book.getBookTypeLabel(book.type);
|
const categoryLabel: string = Book.getBookTypeLabel(book.type);
|
||||||
const transformedBook: BookProps = {
|
const transformedBook: BookProps = {
|
||||||
bookId: book.id,
|
bookId: book.bookId,
|
||||||
type: categoryLabel,
|
type: categoryLabel,
|
||||||
title: book.title,
|
title: book.title,
|
||||||
subTitle: book.subTitle,
|
subTitle: book.subTitle,
|
||||||
summary: book.summary,
|
summary: book.summary,
|
||||||
serie: book.serieId,
|
serie: book.serie,
|
||||||
publicationDate: book.desiredReleaseDate,
|
publicationDate: book.publicationDate,
|
||||||
desiredWordCount: book.desiredWordCount,
|
desiredWordCount: book.desiredWordCount,
|
||||||
totalWordCount: 0,
|
totalWordCount: 0,
|
||||||
coverImage: imageDataUrl,
|
coverImage: imageDataUrl,
|
||||||
@@ -229,7 +229,7 @@ export default function BookList() {
|
|||||||
async function getBook(bookId: string): Promise<void> {
|
async function getBook(bookId: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
let localBookOnly: boolean = false;
|
let localBookOnly: boolean = false;
|
||||||
let bookResponse: BookListProps|null = null;
|
let bookResponse: BookProps|null = null;
|
||||||
if (isCurrentlyOffline()){
|
if (isCurrentlyOffline()){
|
||||||
if (!offlineMode.isDatabaseInitialized) {
|
if (!offlineMode.isDatabaseInitialized) {
|
||||||
errorMessage(t("bookList.errorBookDetails"));
|
errorMessage(t("bookList.errorBookDetails"));
|
||||||
@@ -246,7 +246,7 @@ export default function BookList() {
|
|||||||
localBookOnly = true;
|
localBookOnly = true;
|
||||||
}
|
}
|
||||||
if (!bookResponse) {
|
if (!bookResponse) {
|
||||||
bookResponse = await System.authGetQueryToServer<BookListProps>(`book/basic-information`, accessToken, lang, {id: bookId});
|
bookResponse = await System.authGetQueryToServer<BookProps>(`book/basic-information`, accessToken, lang, {id: bookId});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!bookResponse) {
|
if (!bookResponse) {
|
||||||
@@ -260,8 +260,8 @@ export default function BookList() {
|
|||||||
subTitle: bookResponse?.subTitle || '',
|
subTitle: bookResponse?.subTitle || '',
|
||||||
summary: bookResponse?.summary || '',
|
summary: bookResponse?.summary || '',
|
||||||
type: bookResponse?.type || '',
|
type: bookResponse?.type || '',
|
||||||
serie: bookResponse?.serieId,
|
serie: bookResponse?.serie,
|
||||||
publicationDate: bookResponse?.desiredReleaseDate || '',
|
publicationDate: bookResponse?.publicationDate || '',
|
||||||
desiredWordCount: bookResponse?.desiredWordCount || 0,
|
desiredWordCount: bookResponse?.desiredWordCount || 0,
|
||||||
totalWordCount: 0,
|
totalWordCount: 0,
|
||||||
localBook: localBookOnly,
|
localBook: localBookOnly,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import Upload from "../database/models/Upload.js";
|
|||||||
import GuideLine, {GuideLineAI} from "../database/models/GuideLine.js";
|
import GuideLine, {GuideLineAI} from "../database/models/GuideLine.js";
|
||||||
import Incident from "../database/models/Incident.js";
|
import Incident from "../database/models/Incident.js";
|
||||||
import PlotPoint from "../database/models/PlotPoint.js";
|
import PlotPoint from "../database/models/PlotPoint.js";
|
||||||
import World, {WorldProps} from "../database/models/World.js";
|
import World, {WorldListResponse, WorldProps} from "../database/models/World.js";
|
||||||
|
|
||||||
interface UpdateBookBasicData {
|
interface UpdateBookBasicData {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -330,8 +330,8 @@ ipcMain.handle('db:book:issue:remove', createHandler<RemoveIssueData, boolean>(
|
|||||||
interface GetWorldsData {
|
interface GetWorldsData {
|
||||||
bookid: string;
|
bookid: string;
|
||||||
}
|
}
|
||||||
ipcMain.handle('db:book:worlds:get', createHandler<GetWorldsData, WorldProps[]>(
|
ipcMain.handle('db:book:worlds:get', createHandler<GetWorldsData, WorldListResponse>(
|
||||||
function(userId: string, data: GetWorldsData, lang: 'fr' | 'en') {
|
function(userId: string, data: GetWorldsData, lang: 'fr' | 'en'): WorldListResponse {
|
||||||
return World.getWorlds(userId, data.bookid, lang);
|
return World.getWorlds(userId, data.bookid, lang);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ipcMain } from 'electron';
|
import { ipcMain } from 'electron';
|
||||||
import { createHandler } from '../database/LocalSystem.js';
|
import { createHandler } from '../database/LocalSystem.js';
|
||||||
import Character from '../database/models/Character.js';
|
import Character, {CharacterListResponse} from '../database/models/Character.js';
|
||||||
import type { CharacterProps, CharacterPropsPost, CharacterAttribute } from '../database/models/Character.js';
|
import type { CharacterPropsPost, CharacterAttribute } from '../database/models/Character.js';
|
||||||
|
|
||||||
interface AddCharacterData {
|
interface AddCharacterData {
|
||||||
character: CharacterPropsPost;
|
character: CharacterPropsPost;
|
||||||
@@ -20,8 +20,8 @@ interface AddAttributeData {
|
|||||||
interface GetCharacterListData {
|
interface GetCharacterListData {
|
||||||
bookid: string;
|
bookid: string;
|
||||||
}
|
}
|
||||||
ipcMain.handle('db:character:list', createHandler<GetCharacterListData, CharacterProps[]>(
|
ipcMain.handle('db:character:list', createHandler<GetCharacterListData, CharacterListResponse>(
|
||||||
function(userId: string, data: GetCharacterListData, lang: 'fr' | 'en'): CharacterProps[] {
|
function(userId: string, data: GetCharacterListData, lang: 'fr' | 'en'): CharacterListResponse {
|
||||||
return Character.getCharacterList(userId, data.bookid, lang);
|
return Character.getCharacterList(userId, data.bookid, lang);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ipcMain } from 'electron';
|
import { ipcMain } from 'electron';
|
||||||
import { createHandler } from '../database/LocalSystem.js';
|
import { createHandler } from '../database/LocalSystem.js';
|
||||||
import Location from '../database/models/Location.js';
|
import Location, {LocationListResponse} from '../database/models/Location.js';
|
||||||
import type { LocationProps } from '../database/models/Location.js';
|
import type { LocationProps } from '../database/models/Location.js';
|
||||||
|
|
||||||
interface UpdateLocationResponse {
|
interface UpdateLocationResponse {
|
||||||
@@ -34,8 +34,8 @@ interface UpdateLocationData {
|
|||||||
interface GetAllLocationsData {
|
interface GetAllLocationsData {
|
||||||
bookid: string;
|
bookid: string;
|
||||||
}
|
}
|
||||||
ipcMain.handle('db:location:all', createHandler<GetAllLocationsData, LocationProps[]>(
|
ipcMain.handle('db:location:all', createHandler<GetAllLocationsData, LocationListResponse>(
|
||||||
function(userId: string, data: GetAllLocationsData, lang: 'fr' | 'en'): LocationProps[] {
|
function(userId: string, data: GetAllLocationsData, lang: 'fr' | 'en'): LocationListResponse {
|
||||||
return Location.getAllLocations(userId, data.bookid, lang);
|
return Location.getAllLocations(userId, data.bookid, lang);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -81,23 +81,6 @@ export interface BookProps {
|
|||||||
tools?: BookToolsSettings;
|
tools?: BookToolsSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BookListProps {
|
|
||||||
id: string;
|
|
||||||
type: string;
|
|
||||||
authorId: string;
|
|
||||||
title: string;
|
|
||||||
subTitle?: string;
|
|
||||||
summary?: string;
|
|
||||||
serieId?: number;
|
|
||||||
desiredReleaseDate?: string;
|
|
||||||
desiredWordCount?: number;
|
|
||||||
wordCount?: number;
|
|
||||||
coverImage?: string;
|
|
||||||
bookMeta?: string;
|
|
||||||
itIsLocal?: boolean;
|
|
||||||
quillsenseEnabled?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GuideLine {
|
export interface GuideLine {
|
||||||
tone: string;
|
tone: string;
|
||||||
atmosphere: string;
|
atmosphere: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user