Remove ExportBook component and integrate new export workflows
- Deleted `ExportBook` component and its usage in `BookCard.tsx`. - Integrated improved book export workflows in `BookSettingOption` for better user experience. - Updated database models and repositories to support export options with chapter/version selection. - Added localization support for export-related messages and tooltips. - Upgraded dependencies to include libraries required for export formats (e.g., DOCX, PDF, EPUB). - Bumped app version to 0.4.1.
This commit is contained in:
@@ -82,6 +82,26 @@ export interface ChapterBookResult extends Record<string, SQLiteValue> {
|
||||
content: string | null;
|
||||
}
|
||||
|
||||
export interface ChapterExportInfoResult extends Record<string, SQLiteValue> {
|
||||
chapter_id: string;
|
||||
title: string;
|
||||
chapter_order: number;
|
||||
available_versions: string;
|
||||
}
|
||||
|
||||
export interface SelectedChapterContentResult extends Record<string, SQLiteValue> {
|
||||
chapter_id: string;
|
||||
title: string;
|
||||
chapter_order: number;
|
||||
content: string;
|
||||
version: number;
|
||||
}
|
||||
|
||||
export interface ChapterSelectionParam {
|
||||
chapterId: string;
|
||||
version: number;
|
||||
}
|
||||
|
||||
export default class ChapterRepo {
|
||||
/**
|
||||
* Checks if a chapter name already exists for a book.
|
||||
@@ -698,4 +718,38 @@ export default class ChapterRepo {
|
||||
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
|
||||
}
|
||||
}
|
||||
|
||||
static fetchChaptersExportInfo(userId: string, bookId: string, lang: 'fr' | 'en'): ChapterExportInfoResult[] {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const query: string = `SELECT bc.chapter_id, bc.title, bc.chapter_order, GROUP_CONCAT(DISTINCT bcc.version) AS available_versions FROM book_chapters bc LEFT JOIN book_chapter_content bcc ON bc.chapter_id = bcc.chapter_id WHERE bc.author_id = ? AND bc.book_id = ? GROUP BY bc.chapter_id, bc.title, bc.chapter_order ORDER BY bc.chapter_order`;
|
||||
const params: SQLiteValue[] = [userId, bookId];
|
||||
return db.all(query, params) as ChapterExportInfoResult[];
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
console.error(`DB Error: ${error.message}`);
|
||||
throw new Error(lang === 'fr' ? "Impossible de récupérer les informations d'export des chapitres." : 'Unable to retrieve chapters export info.');
|
||||
}
|
||||
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
|
||||
}
|
||||
}
|
||||
|
||||
static fetchSelectedChaptersContent(bookId: string, selections: ChapterSelectionParam[], lang: 'fr' | 'en'): SelectedChapterContentResult[] {
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
const conditions: string[] = selections.map((): string => '(chapter.chapter_id = ? AND content.version = ?)');
|
||||
const query: string = `SELECT chapter.chapter_id, chapter.title, chapter.chapter_order, content.content, content.version FROM book_chapters AS chapter INNER JOIN book_chapter_content AS content ON chapter.chapter_id = content.chapter_id WHERE chapter.book_id = ? AND (${conditions.join(' OR ')}) ORDER BY chapter.chapter_order`;
|
||||
const params: SQLiteValue[] = [bookId];
|
||||
for (const selection of selections) {
|
||||
params.push(selection.chapterId, selection.version);
|
||||
}
|
||||
return db.all(query, params) as SelectedChapterContentResult[];
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
console.error(`DB Error: ${error.message}`);
|
||||
throw new Error(lang === 'fr' ? 'Impossible de récupérer le contenu des chapitres sélectionnés.' : 'Unable to retrieve selected chapters content.');
|
||||
}
|
||||
throw new Error(lang === 'fr' ? "Une erreur inconnue s'est produite." : "An unknown error occurred.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user