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,30 +1,21 @@
import {Dispatch, SetStateAction, useContext, useState} from 'react';
import {
faFire,
faFlag,
faPuzzlePiece,
faScaleBalanced,
faTrophy,
IconDefinition,
} from '@fortawesome/free-solid-svg-icons';
import {Act as ActType, Incident, PlotPoint} from '@/lib/models/Book';
import {ActChapter, ChapterListProps} from '@/lib/models/Chapter';
import System from '@/lib/models/System';
import {BookContext} from '@/context/BookContext';
import {SessionContext} from '@/context/SessionContext';
import {AlertContext} from '@/context/AlertContext';
import CollapsableArea from '@/components/CollapsableArea';
import React, {Dispatch, SetStateAction, useContext, useState} from 'react';
import {Flag, Flame, LucideIcon, Puzzle, Scale, Trophy} from 'lucide-react';
import {Act as ActType, Incident, PlotPoint} from '@/lib/types/book';
import {ActChapter, ChapterListProps} from '@/lib/types/chapter';
import {apiDelete, apiPost} from '@/lib/api/client';
import {isDesktop} from '@/lib/configs';
import * as tauri from '@/lib/tauri';
import OfflineContext, {OfflineContextType} from '@/context/OfflineContext';
import {BookContext, BookContextProps} from '@/context/BookContext';
import {SessionContext, SessionContextProps} from '@/context/SessionContext';
import {AlertContext, AlertContextProps} from '@/context/AlertContext';
import Collapse from '@/components/ui/Collapse';
import ActDescription from '@/components/book/settings/story/act/ActDescription';
import ActChaptersSection from '@/components/book/settings/story/act/ActChaptersSection';
import ActIncidents from '@/components/book/settings/story/act/ActIncidents';
import ActPlotPoints from '@/components/book/settings/story/act/ActPlotPoints';
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';
interface ActProps {
acts: ActType[];
@@ -34,14 +25,12 @@ interface ActProps {
export default function Act({acts, setActs, mainChapters}: ActProps) {
const t = useTranslations('actComponent');
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 {session} = useContext(SessionContext);
const {errorMessage, successMessage} = useContext(AlertContext);
const {lang}: LangContextProps = useContext<LangContextProps>(LangContext);
const {book}: BookContextProps = useContext<BookContextProps>(BookContext);
const {session}: SessionContextProps = useContext<SessionContextProps>(SessionContext);
const {errorMessage, successMessage}: AlertContextProps = useContext<AlertContextProps>(AlertContext);
const {isCurrentlyOffline}: OfflineContextType = useContext<OfflineContextType>(OfflineContext);
const bookId: string | undefined = book?.bookId;
const token: string = session.accessToken;
@@ -77,24 +66,16 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
async function addIncident(actId: number): Promise<void> {
if (newIncidentTitle.trim() === '') return;
try {
let incidentId: string;
if (isCurrentlyOffline() || book?.localBook) {
incidentId = await tauri.addIncident(bookId!, newIncidentTitle);
if (isDesktop && (isCurrentlyOffline() || book?.localBook)) {
incidentId = await tauri.addIncident(bookId ?? '', newIncidentTitle);
} else {
incidentId = await System.authPostToServer<string>('book/incident/new', {
incidentId = await apiPost<string>('book/incident/new', {
bookId,
name: newIncidentTitle,
}, token, lang);
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
addToQueue('add_incident', {data: {
bookId,
incidentId,
name: newIncidentTitle,
}});
}
}
if (!incidentId) {
errorMessage(t('errorAddIncident'));
@@ -108,7 +89,7 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
summary: '',
chapters: [],
};
return {
...act,
incidents: [...(act.incidents || []), newIncident],
@@ -130,15 +111,13 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
async function deleteIncident(actId: number, incidentId: string): Promise<void> {
try {
let response: boolean;
const deleteData = { bookId, incidentId, deletedAt: System.timeStampInSeconds() };
if (isCurrentlyOffline() || book?.localBook) {
response = await tauri.removeIncident(deleteData.bookId!, deleteData.incidentId, deleteData.deletedAt);
if (isDesktop && (isCurrentlyOffline() || book?.localBook)) {
response = await tauri.removeIncident(bookId ?? '', incidentId, Date.now());
} else {
response = await System.authDeleteToServer<boolean>('book/incident/remove', deleteData, token, lang);
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
addToQueue('remove_incident', {data: deleteData});
}
response = await apiDelete<boolean>('book/incident/remove', {
bookId,
incidentId,
}, token, lang);
}
if (!response) {
errorMessage(t('errorDeleteIncident'));
@@ -169,22 +148,14 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
if (newPlotPointTitle.trim() === '') return;
try {
let plotId: string;
const plotData = {
bookId,
name: newPlotPointTitle,
incidentId: selectedIncidentId,
};
if (isCurrentlyOffline() || book?.localBook) {
plotId = await tauri.addPlotPoint(plotData.bookId!, plotData.name, plotData.incidentId);
if (isDesktop && (isCurrentlyOffline() || book?.localBook)) {
plotId = await tauri.addPlotPoint(bookId ?? '', newPlotPointTitle, selectedIncidentId);
} else {
plotId = await System.authPostToServer<string>('book/plot/new', plotData, token, lang);
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
addToQueue('add_plot_point', {data: {
...plotData,
plotId,
}});
}
plotId = await apiPost<string>('book/plot/new', {
bookId,
name: newPlotPointTitle,
incidentId: selectedIncidentId,
}, token, lang);
}
if (!plotId) {
errorMessage(t('errorAddPlotPoint'));
@@ -221,15 +192,12 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
async function deletePlotPoint(actId: number, plotPointId: string): Promise<void> {
try {
let response: boolean;
const deleteData = { plotId: plotPointId, bookId, deletedAt: System.timeStampInSeconds() };
if (isCurrentlyOffline() || book?.localBook) {
response = await tauri.removePlotPoint(deleteData.plotId, deleteData.bookId!, deleteData.deletedAt);
if (isDesktop && (isCurrentlyOffline() || book?.localBook)) {
response = await tauri.removePlotPoint(plotPointId, bookId ?? '', Date.now());
} else {
response = await System.authDeleteToServer<boolean>('book/plot/remove', deleteData, token, lang);
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
addToQueue('remove_plot_point', {data: deleteData});
}
response = await apiDelete<boolean>('book/plot/remove', {
plotId: plotPointId,
}, token, lang);
}
if (!response) {
errorMessage(t('errorDeletePlotPoint'));
@@ -269,24 +237,22 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
}
try {
let linkId: string;
const linkData = {
bookId,
chapterId: chapterId,
actId: actId,
plotId: destination === 'plotPoint' ? itemId : null,
incidentId: destination === 'incident' ? itemId : null,
};
if (isCurrentlyOffline() || book?.localBook) {
linkId = await tauri.addChapterInformation(linkData as any);
if (isDesktop && (isCurrentlyOffline() || book?.localBook)) {
linkId = await tauri.addChapterInformation({
chapterId: chapterId,
actId: actId,
bookId: bookId ?? '',
plotId: destination === 'plotPoint' ? itemId : undefined,
incidentId: destination === 'incident' ? itemId : undefined,
});
} else {
linkId = await System.authPostToServer<string>('chapter/resume/add', linkData, token, lang);
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
addToQueue('add_chapter_information', {data: {
...linkData,
chapterInfoId: linkId,
}});
}
linkId = await apiPost<string>('chapter/resume/add', {
bookId,
chapterId: chapterId,
actId: actId,
plotId: destination === 'plotPoint' ? itemId : null,
incidentId: destination === 'incident' ? itemId : null,
}, token, lang);
}
if (!linkId) {
errorMessage(t('errorLinkChapter'));
@@ -363,15 +329,12 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
): Promise<void> {
try {
let response: boolean;
const unlinkData = { chapterInfoId, bookId, deletedAt: System.timeStampInSeconds() };
if (isCurrentlyOffline() || book?.localBook) {
response = await tauri.removeChapterInformation(unlinkData.chapterInfoId, unlinkData.bookId!, unlinkData.deletedAt);
if (isDesktop && (isCurrentlyOffline() || book?.localBook)) {
response = await tauri.removeChapterInformation(chapterInfoId, bookId ?? '', Date.now());
} else {
response = await System.authDeleteToServer<boolean>('chapter/resume/remove', unlinkData, token, lang);
if (localSyncedBooks.find((syncedBook: SyncedBook): boolean => syncedBook.id === bookId)) {
addToQueue('remove_chapter_information', {data: unlinkData});
}
response = await apiDelete<boolean>('chapter/resume/remove', {
chapterInfoId,
}, token, lang);
}
if (!response) {
errorMessage(t('errorUnlinkChapter'));
@@ -621,20 +584,20 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
);
}
function renderActIcon(actId: number): IconDefinition {
function renderActIcon(actId: number): LucideIcon {
switch (actId) {
case 1:
return faFlag;
return Flag;
case 2:
return faFire;
return Flame;
case 3:
return faPuzzlePiece;
return Puzzle;
case 4:
return faScaleBalanced;
return Scale;
case 5:
return faTrophy;
return Trophy;
default:
return faFlag;
return Flag;
}
}
@@ -658,7 +621,7 @@ export default function Act({acts, setActs, mainChapters}: ActProps) {
return (
<div className="space-y-6">
{acts.map((act: ActType) => (
<CollapsableArea key={`act-${act.id}`}
<Collapse variant="card" key={`act-${act.id}`}
title={renderActTitle(act.id)}
icon={renderActIcon(act.id)}
children={