Add terms of use translations, sync detection, and refactor book components
- Introduced new translations for terms of use in French and English locales. - Added sync status detection logic for books in `BookList` and `BookCard` components. - Refactored `BookCard` to handle additional props and improve layout flexibility. - Enhanced `TermsOfUse` component with complete localization support and refuse functionality. - Updated data decryption logic in Rust services to handle optional fields and additional metadata consistently. - Improved offline/online synchronization workflows with extended context properties.
This commit is contained in:
@@ -1,13 +1,34 @@
|
||||
import {SyncedBook} from "@/lib/types/synced-book";
|
||||
import {BookSyncCompare, SyncedBook} from "@/lib/types/synced-book";
|
||||
import {Context, createContext, Dispatch, SetStateAction} from "react";
|
||||
|
||||
export type SyncType = 'server-only' | 'local-only' | 'to-sync-from-server' | 'to-sync-to-server' | 'synced'
|
||||
|
||||
export interface BooksSyncContextProps {
|
||||
setServerSyncedBooks: Dispatch<SetStateAction<SyncedBook[]>>;
|
||||
serverSyncedBooks: SyncedBook[];
|
||||
setServerSyncedBooks: Dispatch<SetStateAction<SyncedBook[]>>;
|
||||
localSyncedBooks: SyncedBook[];
|
||||
setLocalSyncedBooks: Dispatch<SetStateAction<SyncedBook[]>>;
|
||||
booksToSyncFromServer: BookSyncCompare[];
|
||||
setBooksToSyncFromServer: Dispatch<SetStateAction<BookSyncCompare[]>>;
|
||||
booksToSyncToServer: BookSyncCompare[];
|
||||
setBooksToSyncToServer: Dispatch<SetStateAction<BookSyncCompare[]>>;
|
||||
setServerOnlyBooks: Dispatch<SetStateAction<SyncedBook[]>>;
|
||||
setLocalOnlyBooks: Dispatch<SetStateAction<SyncedBook[]>>;
|
||||
serverOnlyBooks: SyncedBook[];
|
||||
localOnlyBooks: SyncedBook[];
|
||||
}
|
||||
|
||||
export const BooksSyncContext: Context<BooksSyncContextProps> = createContext<BooksSyncContextProps>({
|
||||
serverSyncedBooks: [],
|
||||
setServerSyncedBooks: (): void => {
|
||||
}
|
||||
})
|
||||
setServerSyncedBooks: (): void => {},
|
||||
localSyncedBooks: [],
|
||||
setLocalSyncedBooks: (): void => {},
|
||||
booksToSyncFromServer: [],
|
||||
setBooksToSyncFromServer: (): void => {},
|
||||
booksToSyncToServer: [],
|
||||
setBooksToSyncToServer: (): void => {},
|
||||
setServerOnlyBooks: (): void => {},
|
||||
setLocalOnlyBooks: (): void => {},
|
||||
serverOnlyBooks: [],
|
||||
localOnlyBooks: []
|
||||
});
|
||||
|
||||
@@ -1,11 +1,35 @@
|
||||
import {createContext} from 'react';
|
||||
import {createContext, Dispatch, SetStateAction} from 'react';
|
||||
|
||||
export interface OfflineMode {
|
||||
isManuallyOffline: boolean;
|
||||
isNetworkOnline: boolean;
|
||||
isOffline: boolean;
|
||||
isDatabaseInitialized: boolean;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
export interface OfflineContextType {
|
||||
offlineMode: OfflineMode;
|
||||
setOfflineMode: Dispatch<SetStateAction<OfflineMode>>;
|
||||
toggleOfflineMode: () => void;
|
||||
initializeDatabase: (userId: string, encryptionKey?: string) => Promise<boolean>;
|
||||
isCurrentlyOffline: () => boolean;
|
||||
}
|
||||
|
||||
export const defaultOfflineMode: OfflineMode = {
|
||||
isManuallyOffline: false,
|
||||
isNetworkOnline: typeof navigator !== 'undefined' ? navigator.onLine : true,
|
||||
isOffline: false,
|
||||
isDatabaseInitialized: false,
|
||||
error: null
|
||||
};
|
||||
|
||||
const OfflineContext = createContext<OfflineContextType>({
|
||||
isCurrentlyOffline: () => false,
|
||||
offlineMode: defaultOfflineMode,
|
||||
setOfflineMode: () => {},
|
||||
toggleOfflineMode: () => {},
|
||||
initializeDatabase: async () => false,
|
||||
isCurrentlyOffline: () => false
|
||||
});
|
||||
|
||||
export default OfflineContext;
|
||||
|
||||
@@ -33,7 +33,7 @@ export default function OfflineProvider({ children }: OfflineProviderProps) {
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize database:', error, 'userId:', userId, 'hasKey:', !!userKey);
|
||||
console.error('Failed to initialize database:', error, 'userId:', userId, 'hasKey:', !!encryptionKey);
|
||||
setOfflineMode(prev => ({
|
||||
...prev,
|
||||
isDatabaseInitialized: false,
|
||||
|
||||
Reference in New Issue
Block a user