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:
@@ -1,131 +1,115 @@
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faCloud, faCloudArrowDown, faCloudArrowUp, faSpinner } from "@fortawesome/free-solid-svg-icons";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useState, useContext, useEffect } from "react";
|
||||
import OfflineContext, { OfflineContextType } from "@/context/OfflineContext";
|
||||
import { SeriesSyncType } from "@/context/SeriesSyncContext";
|
||||
import useSyncSeries from "@/hooks/useSyncSeries";
|
||||
|
||||
interface SyncSeriesProps {
|
||||
seriesId: string;
|
||||
status: SeriesSyncType;
|
||||
}
|
||||
|
||||
export default function SyncSeries({ seriesId, status }: SyncSeriesProps) {
|
||||
const t = useTranslations();
|
||||
const { isCurrentlyOffline } = useContext<OfflineContextType>(OfflineContext);
|
||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||
const [currentStatus, setCurrentStatus] = useState<SeriesSyncType>(status);
|
||||
const { upload: hookUpload, download: hookDownload, syncFromServer: hookSyncFromServer, syncToServer: hookSyncToServer } = useSyncSeries();
|
||||
|
||||
// Synchroniser le state local avec le prop quand il change (ex: après sync auto)
|
||||
useEffect(() => {
|
||||
setCurrentStatus(status);
|
||||
}, [status]);
|
||||
|
||||
const isOffline: boolean = isCurrentlyOffline();
|
||||
|
||||
async function upload(event: React.MouseEvent): Promise<void> {
|
||||
event.stopPropagation();
|
||||
if (isOffline) return;
|
||||
setIsLoading(true);
|
||||
const success: boolean = await hookUpload(seriesId);
|
||||
if (success) setCurrentStatus('synced');
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
async function download(event: React.MouseEvent): Promise<void> {
|
||||
event.stopPropagation();
|
||||
if (isOffline) return;
|
||||
setIsLoading(true);
|
||||
const success = await hookDownload(seriesId);
|
||||
if (success) setCurrentStatus('synced');
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
async function syncFromServer(event: React.MouseEvent): Promise<void> {
|
||||
event.stopPropagation();
|
||||
if (isOffline) return;
|
||||
setIsLoading(true);
|
||||
const success = await hookSyncFromServer(seriesId);
|
||||
if (success) setCurrentStatus('synced');
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
async function syncToServer(event: React.MouseEvent): Promise<void> {
|
||||
event.stopPropagation();
|
||||
if (isOffline || isLoading) return;
|
||||
setIsLoading(true);
|
||||
const success = await hookSyncToServer(seriesId);
|
||||
if (success) setCurrentStatus('synced');
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-primary">
|
||||
<FontAwesomeIcon icon={faSpinner} className="w-4 h-4 animate-spin"/>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
{currentStatus === 'synced' && (
|
||||
<span
|
||||
className="text-gray-light"
|
||||
title={t("seriesCard.synced")}
|
||||
>
|
||||
<FontAwesomeIcon icon={faCloud} className="w-4 h-4"/>
|
||||
</span>
|
||||
)}
|
||||
|
||||
{currentStatus === 'local-only' && (
|
||||
<button
|
||||
onClick={upload}
|
||||
className={`transition-colors ${isOffline ? 'text-gray-dark cursor-not-allowed' : 'text-gray hover:text-primary cursor-pointer'}`}
|
||||
title={t("seriesCard.localOnly")}
|
||||
type="button"
|
||||
disabled={isOffline}
|
||||
>
|
||||
<FontAwesomeIcon icon={faCloudArrowUp} className="w-4 h-4"/>
|
||||
</button>
|
||||
)}
|
||||
{currentStatus === 'server-only' && (
|
||||
<button
|
||||
onClick={download}
|
||||
className={`transition-colors ${isOffline ? 'text-gray-dark cursor-not-allowed' : 'text-gray hover:text-primary cursor-pointer'}`}
|
||||
title={t("seriesCard.serverOnly")}
|
||||
type="button"
|
||||
disabled={isOffline}
|
||||
>
|
||||
<FontAwesomeIcon icon={faCloudArrowDown} className="w-4 h-4"/>
|
||||
</button>
|
||||
)}
|
||||
{currentStatus === 'to-sync-from-server' && (
|
||||
<button
|
||||
onClick={syncFromServer}
|
||||
className={`transition-colors ${isOffline ? 'text-gray-dark cursor-not-allowed' : 'text-warning hover:text-primary cursor-pointer'}`}
|
||||
title={t("seriesCard.toSyncFromServer")}
|
||||
type="button"
|
||||
disabled={isOffline}
|
||||
>
|
||||
<FontAwesomeIcon icon={faCloudArrowDown} className="w-4 h-4"/>
|
||||
</button>
|
||||
)}
|
||||
{currentStatus === 'to-sync-to-server' && (
|
||||
<button
|
||||
onClick={syncToServer}
|
||||
className={`transition-colors ${isOffline ? 'text-gray-dark cursor-not-allowed' : 'text-warning hover:text-primary cursor-pointer'}`}
|
||||
title={t("seriesCard.toSyncToServer")}
|
||||
type="button"
|
||||
disabled={isOffline}
|
||||
>
|
||||
<FontAwesomeIcon icon={faCloudArrowUp} className="w-4 h-4"/>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
import {Cloud, CloudDownload, CloudUpload, Loader2} from "lucide-react";
|
||||
import {useTranslations} from "@/lib/i18n";
|
||||
import {useState, useContext, useEffect} from "react";
|
||||
import OfflineContext, {OfflineContextType} from "@/context/OfflineContext";
|
||||
import {SeriesSyncType} from "@/context/SeriesSyncContext";
|
||||
import useSyncSeries from "@/hooks/useSyncSeries";
|
||||
import IconButton from "@/components/ui/IconButton";
|
||||
|
||||
interface SyncSeriesProps {
|
||||
seriesId: string;
|
||||
status: SeriesSyncType;
|
||||
}
|
||||
|
||||
export default function SyncSeries({seriesId, status}: SyncSeriesProps) {
|
||||
const t = useTranslations();
|
||||
const {isCurrentlyOffline} = useContext<OfflineContextType>(OfflineContext);
|
||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||
const [currentStatus, setCurrentStatus] = useState<SeriesSyncType>(status);
|
||||
const {upload: hookUpload, download: hookDownload, syncFromServer: hookSyncFromServer, syncToServer: hookSyncToServer} = useSyncSeries();
|
||||
|
||||
useEffect(() => {
|
||||
setCurrentStatus(status);
|
||||
}, [status]);
|
||||
|
||||
const isOffline: boolean = isCurrentlyOffline();
|
||||
|
||||
async function upload(): Promise<void> {
|
||||
if (isOffline) return;
|
||||
setIsLoading(true);
|
||||
const success: boolean = await hookUpload(seriesId);
|
||||
if (success) setCurrentStatus('synced');
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
async function download(): Promise<void> {
|
||||
if (isOffline) return;
|
||||
setIsLoading(true);
|
||||
const success = await hookDownload(seriesId);
|
||||
if (success) setCurrentStatus('synced');
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
async function syncFromServer(): Promise<void> {
|
||||
if (isOffline) return;
|
||||
setIsLoading(true);
|
||||
const success = await hookSyncFromServer(seriesId);
|
||||
if (success) setCurrentStatus('synced');
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
async function syncToServer(): Promise<void> {
|
||||
if (isOffline || isLoading) return;
|
||||
setIsLoading(true);
|
||||
const success = await hookSyncToServer(seriesId);
|
||||
if (success) setCurrentStatus('synced');
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center gap-2" onClick={(e) => e.stopPropagation()}>
|
||||
<Loader2 className="w-4 h-4 text-primary animate-spin"/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2" onClick={(e) => e.stopPropagation()}>
|
||||
{currentStatus === 'synced' && (
|
||||
<Cloud className="w-4 h-4 text-gray-light" title={t("seriesCard.synced")}/>
|
||||
)}
|
||||
|
||||
{currentStatus === 'local-only' && (
|
||||
<IconButton
|
||||
icon={CloudUpload}
|
||||
variant={isOffline ? 'muted' : 'primary'}
|
||||
size="sm"
|
||||
onClick={upload}
|
||||
disabled={isOffline}
|
||||
tooltip={t("seriesCard.localOnly")}
|
||||
/>
|
||||
)}
|
||||
{currentStatus === 'server-only' && (
|
||||
<IconButton
|
||||
icon={CloudDownload}
|
||||
variant={isOffline ? 'muted' : 'primary'}
|
||||
size="sm"
|
||||
onClick={download}
|
||||
disabled={isOffline}
|
||||
tooltip={t("seriesCard.serverOnly")}
|
||||
/>
|
||||
)}
|
||||
{currentStatus === 'to-sync-from-server' && (
|
||||
<IconButton
|
||||
icon={CloudDownload}
|
||||
variant={isOffline ? 'muted' : 'primary'}
|
||||
size="sm"
|
||||
onClick={syncFromServer}
|
||||
disabled={isOffline}
|
||||
tooltip={t("seriesCard.toSyncFromServer")}
|
||||
/>
|
||||
)}
|
||||
{currentStatus === 'to-sync-to-server' && (
|
||||
<IconButton
|
||||
icon={CloudUpload}
|
||||
variant={isOffline ? 'muted' : 'primary'}
|
||||
size="sm"
|
||||
onClick={syncToServer}
|
||||
disabled={isOffline}
|
||||
tooltip={t("seriesCard.toSyncToServer")}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user