Refactor and extend offline synchronization logic across components and services
- Integrated sync queue mechanisms with `LocalSyncQueueContext` for offline data handling. - Updated key sync-related services (e.g., book, chapter, series) to support offline-first functionality. - Removed redundant database fetch methods to optimize repository logic and improve maintainability. - Enhanced Tauri IPC usage for sync operations and removed legacy methods in Rust services.
This commit is contained in:
@@ -30,8 +30,10 @@ export default function AddNewSeriesForm({setCloseForm, onSeriesCreated}: AddNew
|
||||
const {isCurrentlyOffline} = useContext(OfflineContext);
|
||||
const {
|
||||
serverSyncedBooks,
|
||||
setServerSyncedBooks
|
||||
setServerSyncedBooks,
|
||||
localSyncedBooks
|
||||
}: BooksSyncContextProps = useContext<BooksSyncContextProps>(BooksSyncContext);
|
||||
const useLocal: boolean = isDesktop && isCurrentlyOffline();
|
||||
const [name, setName] = useState<string>('');
|
||||
const [description, setDescription] = useState<string>('');
|
||||
const [selectedBookIds, setSelectedBookIds] = useState<string[]>([]);
|
||||
@@ -83,6 +85,8 @@ export default function AddNewSeriesForm({setCloseForm, onSeriesCreated}: AddNew
|
||||
: book
|
||||
)
|
||||
);
|
||||
} else {
|
||||
setServerSyncedBooks((prev: SyncedBook[]): SyncedBook[] => [...prev]);
|
||||
}
|
||||
|
||||
if (onSeriesCreated) {
|
||||
@@ -150,7 +154,7 @@ export default function AddNewSeriesForm({setCloseForm, onSeriesCreated}: AddNew
|
||||
)}
|
||||
</div>
|
||||
|
||||
{serverSyncedBooks.length === 0 ? (
|
||||
{(useLocal ? localSyncedBooks : serverSyncedBooks).length === 0 ? (
|
||||
<div className="text-center py-6 text-muted">
|
||||
<Book className="w-8 h-8 mb-2 opacity-50" strokeWidth={1.75}/>
|
||||
<p>{t("addNewSeriesForm.noBooks")}</p>
|
||||
@@ -158,7 +162,7 @@ export default function AddNewSeriesForm({setCloseForm, onSeriesCreated}: AddNew
|
||||
) : (
|
||||
<div
|
||||
className="max-h-48 overflow-y-auto rounded-xl border border-secondary bg-tertiary">
|
||||
{serverSyncedBooks.map((book: SyncedBook) => {
|
||||
{(useLocal ? localSyncedBooks : serverSyncedBooks).map((book: SyncedBook) => {
|
||||
const isSelected: boolean = selectedBookIds.includes(book.id);
|
||||
return (
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user