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 {AlertContext} from "@/context/AlertContext";
|
||||
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 BookSetting from "@/components/book/settings/BookSetting";
|
||||
import SelectBox from "@/components/form/SelectBox";
|
||||
@@ -61,7 +61,7 @@ export default function ScribeControllerBar() {
|
||||
|
||||
async function getBook(bookId: string): Promise<void> {
|
||||
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,
|
||||
});
|
||||
if (!response) {
|
||||
@@ -69,12 +69,12 @@ export default function ScribeControllerBar() {
|
||||
return;
|
||||
}
|
||||
setBook!!({
|
||||
bookId: response.id,
|
||||
bookId: response.bookId,
|
||||
type: response.type,
|
||||
title: response.title,
|
||||
subTitle: response.subTitle,
|
||||
summary: response.summary,
|
||||
publicationDate: response.desiredReleaseDate,
|
||||
publicationDate: response.publicationDate,
|
||||
desiredWordCount: response.desiredWordCount,
|
||||
totalWordCount: response.desiredWordCount,
|
||||
quillsenseEnabled: response.quillsenseEnabled,
|
||||
|
||||
@@ -6,7 +6,7 @@ import SearchBook from "./SearchBook";
|
||||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
||||
import {faBook, faDownload, faGear, faTrash} from "@fortawesome/free-solid-svg-icons";
|
||||
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 BookCardSkeleton from "@/components/book/BookCardSkeleton";
|
||||
import GuideTour, {GuideStep} from "@/components/GuideTour";
|
||||
@@ -139,40 +139,40 @@ export default function BookList() {
|
||||
async function getBooks(): Promise<void> {
|
||||
setIsLoadingBooks(true);
|
||||
try {
|
||||
let bookResponse: (BookListProps & { itIsLocal: boolean })[] = [];
|
||||
let bookResponse: (BookProps & { itIsLocal: boolean })[] = [];
|
||||
if (!isCurrentlyOffline()) {
|
||||
const [onlineBooks, localBooks]: [BookListProps[], BookListProps[]] = await Promise.all([
|
||||
System.authGetQueryToServer<BookListProps[]>('books', accessToken, lang),
|
||||
const [onlineBooks, localBooks]: [BookProps[], BookProps[]] = await Promise.all([
|
||||
System.authGetQueryToServer<BookProps[]>('books', accessToken, lang),
|
||||
offlineMode.isDatabaseInitialized
|
||||
? window.electron.invoke<BookListProps[]>('db:book:books')
|
||||
? window.electron.invoke<BookProps[]>('db:book:books')
|
||||
: Promise.resolve([])
|
||||
]);
|
||||
const onlineBookIds: Set<string> = new Set(onlineBooks.map((book: BookListProps): string => book.id));
|
||||
const uniqueLocalBooks: BookListProps[] = localBooks.filter((book: BookListProps): boolean => !onlineBookIds.has(book.id));
|
||||
const onlineBookIds: Set<string> = new Set(onlineBooks.map((book: BookProps): string => book.bookId));
|
||||
const uniqueLocalBooks: BookProps[] = localBooks.filter((book: BookProps): boolean => !onlineBookIds.has(book.bookId));
|
||||
bookResponse = [
|
||||
...onlineBooks.map((book: BookListProps): BookListProps & { itIsLocal: boolean } => ({ ...book, itIsLocal: false })),
|
||||
...uniqueLocalBooks.map((book: BookListProps): BookListProps & { itIsLocal: boolean } => ({ ...book, itIsLocal: true }))
|
||||
...onlineBooks.map((book: BookProps): BookProps & { itIsLocal: boolean } => ({ ...book, itIsLocal: false })),
|
||||
...uniqueLocalBooks.map((book: BookProps): BookProps & { itIsLocal: boolean } => ({ ...book, itIsLocal: true }))
|
||||
];
|
||||
} else {
|
||||
if (!offlineMode.isDatabaseInitialized) {
|
||||
setIsLoadingBooks(false);
|
||||
return;
|
||||
}
|
||||
const localBooks: BookListProps[] = await window.electron.invoke<BookListProps[]>('db:book:books');
|
||||
bookResponse = localBooks.map((book: BookListProps): BookListProps & { itIsLocal: boolean } => ({ ...book, itIsLocal: true }));
|
||||
const localBooks: BookProps[] = await window.electron.invoke<BookProps[]>('db:book:books');
|
||||
bookResponse = localBooks.map((book: BookProps): BookProps & { itIsLocal: boolean } => ({ ...book, itIsLocal: true }));
|
||||
}
|
||||
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 categoryLabel: string = Book.getBookTypeLabel(book.type);
|
||||
const transformedBook: BookProps = {
|
||||
bookId: book.id,
|
||||
bookId: book.bookId,
|
||||
type: categoryLabel,
|
||||
title: book.title,
|
||||
subTitle: book.subTitle,
|
||||
summary: book.summary,
|
||||
serie: book.serieId,
|
||||
publicationDate: book.desiredReleaseDate,
|
||||
serie: book.serie,
|
||||
publicationDate: book.publicationDate,
|
||||
desiredWordCount: book.desiredWordCount,
|
||||
totalWordCount: 0,
|
||||
coverImage: imageDataUrl,
|
||||
@@ -229,7 +229,7 @@ export default function BookList() {
|
||||
async function getBook(bookId: string): Promise<void> {
|
||||
try {
|
||||
let localBookOnly: boolean = false;
|
||||
let bookResponse: BookListProps|null = null;
|
||||
let bookResponse: BookProps|null = null;
|
||||
if (isCurrentlyOffline()){
|
||||
if (!offlineMode.isDatabaseInitialized) {
|
||||
errorMessage(t("bookList.errorBookDetails"));
|
||||
@@ -246,7 +246,7 @@ export default function BookList() {
|
||||
localBookOnly = true;
|
||||
}
|
||||
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) {
|
||||
@@ -260,8 +260,8 @@ export default function BookList() {
|
||||
subTitle: bookResponse?.subTitle || '',
|
||||
summary: bookResponse?.summary || '',
|
||||
type: bookResponse?.type || '',
|
||||
serie: bookResponse?.serieId,
|
||||
publicationDate: bookResponse?.desiredReleaseDate || '',
|
||||
serie: bookResponse?.serie,
|
||||
publicationDate: bookResponse?.publicationDate || '',
|
||||
desiredWordCount: bookResponse?.desiredWordCount || 0,
|
||||
totalWordCount: 0,
|
||||
localBook: localBookOnly,
|
||||
|
||||
Reference in New Issue
Block a user