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:
natreex
2026-03-30 21:06:58 -04:00
parent b9606e899a
commit dbbe33b19b
22 changed files with 295 additions and 293 deletions

View File

@@ -14,6 +14,9 @@ import {LangContext, LangContextProps} from "@/context/LangContext";
import {SeriesContext, SeriesContextProps} from "@/context/SeriesContext";
import {SeriesDetailResponse, SeriesUpdateResponse} from "@/lib/types/series";
import PulseLoader from '@/components/ui/PulseLoader';
import {SeriesSyncContext, SeriesSyncContextProps} from '@/context/SeriesSyncContext';
import {SyncedSeries} from '@/lib/types/synced-series';
import {LocalSyncQueueContext, LocalSyncQueueContextProps} from '@/context/SyncQueueContext';
function BasicSeriesInformation(props: object, ref: React.Ref<{ handleSave: () => Promise<void> }>) {
const t = useTranslations();
@@ -24,6 +27,8 @@ function BasicSeriesInformation(props: object, ref: React.Ref<{ handleSave: () =
const userToken: string = session?.accessToken ? session?.accessToken : '';
const {errorMessage, successMessage}: AlertContextProps = useContext<AlertContextProps>(AlertContext);
const {isCurrentlyOffline} = useContext(OfflineContext);
const {localSyncedSeries}: SeriesSyncContextProps = useContext<SeriesSyncContextProps>(SeriesSyncContext);
const {addToQueue}: LocalSyncQueueContextProps = useContext<LocalSyncQueueContextProps>(LocalSyncQueueContext);
const useLocal: boolean = isDesktop && isCurrentlyOffline();
const [isLoading, setIsLoading] = useState<boolean>(true);
@@ -69,9 +74,16 @@ function BasicSeriesInformation(props: object, ref: React.Ref<{ handleSave: () =
return;
}
try {
const response: SeriesUpdateResponse = useLocal
? {success: await updateSeries({seriesId, name, description})} as SeriesUpdateResponse
: await apiPut<SeriesUpdateResponse>('series/update', {seriesId, name, description}, userToken, lang);
let response: SeriesUpdateResponse;
const updateData = {seriesId, name, description};
if (useLocal) {
response = {success: await updateSeries(updateData)} as SeriesUpdateResponse;
} else {
response = await apiPut<SeriesUpdateResponse>('series/update', updateData, userToken, lang);
if (isDesktop && localSyncedSeries.find((s: SyncedSeries): boolean => s.id === seriesId)) {
addToQueue('update_series', updateData);
}
}
if (!response.success) {
errorMessage(t('seriesBasicInformation.error.update'));
return;