- Introduce `BooksSyncContext` for managing book synchronization states (server-only, local-only, to-sync, etc.). - Remove `UserContext` and related dependencies. - Refine localization strings (`en.json`) with sync-related updates (e.g., "toSyncFromServer", "toSyncToServer"). - Extend database schema with additional tables and fields for syncing books, chapters, and related entities. - Add `last_update` fields and update corresponding repository methods to support synchronization logic. - Enhance IPC handlers with stricter typing, data validation, and sync-aware operations.
92 lines
2.5 KiB
TypeScript
92 lines
2.5 KiB
TypeScript
import {SelectBoxProps} from "@/shared/interface";
|
|
import {BookProps} from "@/lib/models/Book";
|
|
import {SessionProps} from "@/lib/models/Session";
|
|
|
|
export interface Author {
|
|
id: string;
|
|
name: string;
|
|
}
|
|
|
|
export interface UserProps {
|
|
id: string;
|
|
name: string;
|
|
lastName: string;
|
|
username: string;
|
|
authorName?: string;
|
|
email?: string;
|
|
accountVerified?: boolean;
|
|
termsAccepted?: boolean;
|
|
aiUsage: number,
|
|
apiKeys: {
|
|
gemini: boolean
|
|
openai: boolean,
|
|
anthropic: boolean,
|
|
},
|
|
guideTour?: GuideTour[];
|
|
subscription?: Subscription[];
|
|
writingLang: number;
|
|
writingLevel: number;
|
|
ritePoints: number;
|
|
creditsBalance:number;
|
|
groupId: number;
|
|
}
|
|
|
|
export interface GuideTour {
|
|
[key: string]: boolean;
|
|
}
|
|
|
|
export interface Subscription {
|
|
subType: string;
|
|
subTier: number;
|
|
status: boolean;
|
|
}
|
|
|
|
export const writingLevel: SelectBoxProps[] = [
|
|
{value: '0', label: 'Sélectionner un niveau d\'écriture'},
|
|
{value: '1', label: 'Je suis débutant'},
|
|
{value: '2', label: 'Je suis intermédiaire'},
|
|
{value: '3', label: 'Je suis avancé'},
|
|
];
|
|
|
|
export default class User {
|
|
static getCurrentSubscription(user: UserProps | null, type: "quill-sense" | "use-your-keys"): Subscription | null {
|
|
if (!user || !user.subscription || user.subscription.length === 0) {
|
|
return null;
|
|
}
|
|
return user.subscription.find((sub: Subscription): boolean => {
|
|
return sub.subType === type && sub.status;
|
|
}) || null;
|
|
}
|
|
static getWritingLevel(level: number): string {
|
|
switch (level) {
|
|
case 1:
|
|
return 'Débutant';
|
|
case 2:
|
|
return 'Intermédiaire';
|
|
case 3:
|
|
return 'Avancé';
|
|
default:
|
|
return 'Débutant';
|
|
}
|
|
}
|
|
|
|
static guideTourDone(guide: GuideTour[], tour: string): boolean {
|
|
if (!guide || !tour) return false;
|
|
return guide.find((guide: GuideTour): boolean => guide[tour]) === undefined;
|
|
}
|
|
|
|
static setNewGuideTour(session: SessionProps, tour: string): SessionProps {
|
|
const newGuideTour: { [key: string]: boolean }[] = [
|
|
...(session?.user?.guideTour ?? []),
|
|
{[tour]: true}
|
|
];
|
|
return {
|
|
...session,
|
|
user: {
|
|
...session?.user as UserProps,
|
|
guideTour: newGuideTour
|
|
}
|
|
}
|
|
}
|
|
}
|