MCPcopy Create free account
hub / github.com/PaperDebugger/paperdebugger / useSync

Function useSync

webapp/_webapp/src/hooks/useSync.ts:32–85  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30}
31
32export function useSync() {
33 const adapter = useAdapter();
34 const { user } = useAuthStore();
35 const { sync: overleafSync, syncing, syncingProgress } = useSocketStore();
36
37 /**
38 * Sync document content to server based on platform
39 */
40 const sync = useCallback(
41 async (options?: SyncOptions): Promise<SyncResult> => {
42 const projectId = adapter.getDocumentId?.() || getProjectId();
43 const userId = user?.id || "";
44
45 googleAnalytics.fireEvent(userId, "sync_documents", {
46 projectId: projectId,
47 platform: adapter.platform,
48 });
49
50 try {
51 if (adapter.platform === "overleaf") {
52 // Overleaf: Use existing socket-based sync
53 const { session, gclb } = await getCookies(window.location.hostname);
54 await overleafSync(
55 userId,
56 projectId,
57 {
58 cookieOverleafSession2: session,
59 cookieGCLB: gclb,
60 },
61 "unused",
62 );
63 return { success: true };
64 } else if (adapter.platform === "word") {
65 // Word: Get full text directly and upload to server
66 return await syncWordDocument(projectId, adapter, options);
67 } else {
68 // Browser or other platforms: Try to use adapter's getFullText
69 return await syncGenericDocument(projectId, adapter, options);
70 }
71 } catch (error) {
72 logError("Sync failed:", error);
73 return { success: false, error: error as Error };
74 }
75 },
76 [adapter, user?.id, overleafSync],
77 );
78
79 return {
80 sync,
81 syncing,
82 syncingProgress,
83 platform: adapter.platform,
84 };
85}
86
87/**
88 * Sync Word document content to server

Callers 1

useSendMessageStreamFunction · 0.90

Calls 7

useAdapterFunction · 0.90
getProjectIdFunction · 0.90
logErrorFunction · 0.90
syncWordDocumentFunction · 0.85
syncGenericDocumentFunction · 0.85
fireEventMethod · 0.80
getDocumentIdMethod · 0.65

Tested by

no test coverage detected