Remove unused components and models for improved maintainability

- Deleted redundant components (`AddActionButton`, `AlertBox`, `AlertStack`, `BackButton`, `CancelButton`, and `CollapsableArea`) and related files.
- Removed unused models (`Book`, `BookSerie`, `BookTables`, `Character`, and `Chapter`) to reduce codebase clutter.
- Updated project structure and references to reflect these removals.
This commit is contained in:
natreex
2026-03-22 22:37:31 -04:00
parent e8aaef108b
commit 64ed90d993
229 changed files with 15091 additions and 21289 deletions

View File

@@ -1,22 +1,21 @@
'use client'
import {createContext, forwardRef, useContext, useEffect, useImperativeHandle, useState} from 'react';
import {BookContext} from '@/context/BookContext';
import {SessionContext} from '@/context/SessionContext';
import {AlertContext} from '@/context/AlertContext';
import System from '@/lib/models/System';
import {Act as ActType, Issue} from '@/lib/models/Book';
import {ActChapter, ChapterListProps} from '@/lib/models/Chapter';
import React, {createContext, forwardRef, useContext, useEffect, useImperativeHandle, useState} from 'react';
import {BookContext, BookContextProps} from '@/context/BookContext';
import {SessionContext, SessionContextProps} from '@/context/SessionContext';
import {AlertContext, AlertContextProps} from '@/context/AlertContext';
import {apiGet, apiPost} from '@/lib/api/client';
import {isDesktop} from '@/lib/configs';
import * as tauri from '@/lib/tauri';
import OfflineContext, {OfflineContextType} from '@/context/OfflineContext';
import {Act as ActType, Incident, Issue, PlotPoint} from '@/lib/types/book';
import {ActChapter, ChapterListProps} from '@/lib/types/chapter';
import MainChapter from "@/components/book/settings/story/MainChapter";
import Issues from "@/components/book/settings/story/Issue";
import Act from "@/components/book/settings/story/Act";
import {useTranslations} from "next-intl";
import {useTranslations} from '@/lib/i18n';
import {LangContext, LangContextProps} from "@/context/LangContext";
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';
import {SettingRef} from "@/lib/types/settings";
export const StoryContext = createContext<{
acts: ActType[];
@@ -43,24 +42,22 @@ interface StoryFetchData {
issues: Issue[];
}
export function Story(props: any, ref: any) {
export function Story(_props: object, ref: React.ForwardedRef<SettingRef>): React.JSX.Element {
const t = useTranslations();
const {lang} = useContext<LangContextProps>(LangContext);
const {isCurrentlyOffline} = useContext<OfflineContextType>(OfflineContext);
const {addToQueue} = useContext<LocalSyncQueueContextProps>(LocalSyncQueueContext);
const {localSyncedBooks} = useContext<BooksSyncContextProps>(BooksSyncContext);
const {book} = useContext(BookContext);
const {lang}: LangContextProps = useContext<LangContextProps>(LangContext);
const {book}: BookContextProps = useContext<BookContextProps>(BookContext);
const bookId: string = book?.bookId ? book.bookId.toString() : '';
const {session} = useContext(SessionContext);
const {session}: SessionContextProps = useContext<SessionContextProps>(SessionContext);
const userToken: string = session.accessToken;
const {errorMessage, successMessage} = useContext(AlertContext);
const {errorMessage, successMessage}: AlertContextProps = useContext<AlertContextProps>(AlertContext);
const {isCurrentlyOffline}: OfflineContextType = useContext<OfflineContextType>(OfflineContext);
const [acts, setActs] = useState<ActType[]>([]);
const [issues, setIssues] = useState<Issue[]>([]);
const [mainChapters, setMainChapters] = useState<ChapterListProps[]>([]);
const [isLoading, setIsLoading] = useState<boolean>(true);
useImperativeHandle(ref, function () {
useImperativeHandle(ref, function (): SettingRef {
return {
handleSave: handleSave
};
@@ -77,10 +74,10 @@ export function Story(props: any, ref: any) {
async function getStoryData(): Promise<void> {
try {
let response: StoryFetchData;
if (isCurrentlyOffline() || book?.localBook) {
if (isDesktop && (isCurrentlyOffline() || book?.localBook)) {
response = await tauri.getBookStory(bookId) as StoryFetchData;
} else {
response = await System.authGetQueryToServer<StoryFetchData>(`book/story`, userToken, lang, {
response = await apiGet<StoryFetchData>(`book/story`, userToken, lang, {
bookid: bookId,
});
}
@@ -101,22 +98,22 @@ export function Story(props: any, ref: any) {
}
function cleanupDeletedChapters(): void {
const existingChapterIds: string[] = mainChapters.map(ch => ch.chapterId);
const existingChapterIds: string[] = mainChapters.map((ch: ChapterListProps): string => ch.chapterId);
const updatedActs = acts.map((act: ActType) => {
const updatedActs: ActType[] = acts.map((act: ActType): ActType => {
const filteredChapters: ActChapter[] = act.chapters?.filter((chapter: ActChapter): boolean =>
existingChapterIds.includes(chapter.chapterId)) || [];
const updatedIncidents = act.incidents?.map(incident => {
const updatedIncidents: Incident[] = act.incidents?.map((incident: Incident): Incident => {
return {
...incident,
chapters: incident.chapters?.filter(chapter =>
chapters: incident.chapters?.filter((chapter: ActChapter): boolean =>
existingChapterIds.includes(chapter.chapterId)) || []
};
}) || [];
const updatedPlotPoints = act.plotPoints?.map(plotPoint => {
const updatedPlotPoints: PlotPoint[] = act.plotPoints?.map((plotPoint: PlotPoint): PlotPoint => {
return {
...plotPoint,
chapters: plotPoint.chapters?.filter(chapter =>
chapters: plotPoint.chapters?.filter((chapter: ActChapter): boolean =>
existingChapterIds.includes(chapter.chapterId)) || []
};
}) || [];
@@ -133,20 +130,20 @@ export function Story(props: any, ref: any) {
async function handleSave(): Promise<void> {
try {
let response: boolean;
const storyData = {
bookId,
acts,
mainChapters,
issues,
};
if (isCurrentlyOffline() || book?.localBook) {
response = await tauri.updateBookStory(storyData);
if (isDesktop && (isCurrentlyOffline() || book?.localBook)) {
response = await tauri.updateBookStory({
bookId,
acts,
mainChapters,
issues,
});
} else {
response = await System.authPostToServer<boolean>('book/story', storyData, userToken, lang);
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
addToQueue('update_book_story', {data: storyData});
}
response = await apiPost<boolean>('book/story', {
bookId,
acts,
mainChapters,
issues,
}, userToken, lang);
}
if (!response) {
errorMessage(t("story.errorSave"))
@@ -186,4 +183,4 @@ export function Story(props: any, ref: any) {
);
}
export default forwardRef(Story);
export default forwardRef<SettingRef, object>(Story);