Remove CharacterComponent and CharacterDetail components
- Deleted `CharacterComponent` and `CharacterDetail` files from the project. - Refactored related logic to improve code maintainability and reduce redundancy.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import type {Context, Dispatch, JSX, ReactNode, SetStateAction} from 'react';
|
||||
import {createContext, useCallback, useState} from 'react';
|
||||
import React, {createContext, useCallback, useState} from 'react';
|
||||
import AlertStack from '@/components/AlertStack';
|
||||
import {cleanErrorMessage} from '@/lib/errors';
|
||||
|
||||
@@ -38,10 +38,11 @@ export const AlertContext: Context<AlertContextProps> = createContext<AlertConte
|
||||
export function AlertProvider({children}: AlertProviderProps): JSX.Element {
|
||||
const [alerts, setAlerts]: [Alert[], Dispatch<SetStateAction<Alert[]>>] = useState<Alert[]>([]);
|
||||
|
||||
const addAlert: (type: AlertType, message: string) => void = useCallback((type: AlertType, message: string): void => {
|
||||
const addAlert: (type: AlertType, message: string) => void = useCallback((type: AlertType, message: unknown): void => {
|
||||
const safeMessage: string = typeof message === 'string' ? message : String(message ?? 'Une erreur est survenue');
|
||||
const id: string = `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
|
||||
const newAlert: Alert = {id, type, message};
|
||||
|
||||
const newAlert: Alert = {id, type, message: safeMessage};
|
||||
|
||||
setAlerts((prev: Alert[]): Alert[] => [...prev, newAlert]);
|
||||
}, []);
|
||||
|
||||
@@ -54,7 +55,7 @@ export function AlertProvider({children}: AlertProviderProps): JSX.Element {
|
||||
}, [addAlert]);
|
||||
|
||||
const errorMessage: (message: string) => void = useCallback((message: string): void => {
|
||||
addAlert('error', cleanErrorMessage(message));
|
||||
addAlert('error', message);
|
||||
}, [addAlert]);
|
||||
|
||||
const infoMessage: (message: string) => void = useCallback((message: string): void => {
|
||||
|
||||
@@ -12,6 +12,8 @@ export interface BooksSyncContextProps {
|
||||
setLocalSyncedBooks:Dispatch<SetStateAction<SyncedBook[]>>;
|
||||
setServerOnlyBooks:Dispatch<SetStateAction<SyncedBook[]>>;
|
||||
setLocalOnlyBooks:Dispatch<SetStateAction<SyncedBook[]>>;
|
||||
setBooksToSyncFromServer:Dispatch<SetStateAction<BookSyncCompare[]>>;
|
||||
setBooksToSyncToServer:Dispatch<SetStateAction<BookSyncCompare[]>>;
|
||||
serverOnlyBooks:SyncedBook[];
|
||||
localOnlyBooks:SyncedBook[];
|
||||
}
|
||||
@@ -25,6 +27,8 @@ export const BooksSyncContext:Context<BooksSyncContextProps> = createContext<Boo
|
||||
setLocalSyncedBooks:():void => {},
|
||||
setServerOnlyBooks:():void => {},
|
||||
setLocalOnlyBooks:():void => {},
|
||||
setBooksToSyncFromServer:():void => {},
|
||||
setBooksToSyncToServer:():void => {},
|
||||
serverOnlyBooks:[],
|
||||
localOnlyBooks:[]
|
||||
})
|
||||
11
context/SeriesContext.ts
Normal file
11
context/SeriesContext.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import {Context, createContext} from "react";
|
||||
|
||||
export interface SeriesContextProps {
|
||||
seriesId: string;
|
||||
localSeries: boolean;
|
||||
}
|
||||
|
||||
export const SeriesContext: Context<SeriesContextProps> = createContext<SeriesContextProps>({
|
||||
seriesId: '',
|
||||
localSeries: false
|
||||
});
|
||||
42
context/SeriesSyncContext.ts
Normal file
42
context/SeriesSyncContext.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { SeriesSyncCompare, SyncedSeries } from "@/lib/models/SyncedSeries";
|
||||
import { Context, createContext, Dispatch, SetStateAction } from "react";
|
||||
|
||||
/**
|
||||
* Sync status types for series synchronization.
|
||||
* - 'server-only': Series exists only on server, needs download
|
||||
* - 'local-only': Series exists only locally, needs upload
|
||||
* - 'to-sync-from-server': Series has newer data on server
|
||||
* - 'to-sync-to-server': Series has newer data locally
|
||||
* - 'synced': Series is synchronized between server and local
|
||||
*/
|
||||
export type SeriesSyncType = 'server-only' | 'local-only' | 'to-sync-from-server' | 'to-sync-to-server' | 'synced';
|
||||
|
||||
export interface SeriesSyncContextProps {
|
||||
serverSyncedSeries: SyncedSeries[];
|
||||
localSyncedSeries: SyncedSeries[];
|
||||
seriesToSyncFromServer: SeriesSyncCompare[];
|
||||
seriesToSyncToServer: SeriesSyncCompare[];
|
||||
setServerSyncedSeries: Dispatch<SetStateAction<SyncedSeries[]>>;
|
||||
setLocalSyncedSeries: Dispatch<SetStateAction<SyncedSeries[]>>;
|
||||
setServerOnlySeries: Dispatch<SetStateAction<SyncedSeries[]>>;
|
||||
setLocalOnlySeries: Dispatch<SetStateAction<SyncedSeries[]>>;
|
||||
setSeriesToSyncFromServer: Dispatch<SetStateAction<SeriesSyncCompare[]>>;
|
||||
setSeriesToSyncToServer: Dispatch<SetStateAction<SeriesSyncCompare[]>>;
|
||||
serverOnlySeries: SyncedSeries[];
|
||||
localOnlySeries: SyncedSeries[];
|
||||
}
|
||||
|
||||
export const SeriesSyncContext: Context<SeriesSyncContextProps> = createContext<SeriesSyncContextProps>({
|
||||
serverSyncedSeries: [],
|
||||
localSyncedSeries: [],
|
||||
seriesToSyncFromServer: [],
|
||||
seriesToSyncToServer: [],
|
||||
setServerSyncedSeries: (): void => {},
|
||||
setLocalSyncedSeries: (): void => {},
|
||||
setServerOnlySeries: (): void => {},
|
||||
setLocalOnlySeries: (): void => {},
|
||||
setSeriesToSyncFromServer: (): void => {},
|
||||
setSeriesToSyncToServer: (): void => {},
|
||||
serverOnlySeries: [],
|
||||
localOnlySeries: []
|
||||
});
|
||||
@@ -5,6 +5,7 @@ export interface WorldContextProps {
|
||||
worlds: WorldProps[];
|
||||
setWorlds: Dispatch<SetStateAction<WorldProps[]>>;
|
||||
selectedWorldIndex: number;
|
||||
isSeriesMode?: boolean;
|
||||
}
|
||||
|
||||
export const WorldContext = createContext<WorldContextProps>({} as WorldContextProps);
|
||||
|
||||
Reference in New Issue
Block a user