Skip to content

Commit

Permalink
feat: Add "Force sync" button for debuging purpose
Browse files Browse the repository at this point in the history
  • Loading branch information
Ldoppea committed Nov 6, 2024
1 parent 3ecb3e8 commit 10d0b07
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Minilog.enable()

const App = (): JSX.Element => {
const client = useClient()
const { workerState } = useSharedWorker()
const { worker, workerState } = useSharedWorker()

return (
<div className="content">
Expand All @@ -28,6 +28,13 @@ const App = (): JSX.Element => {
</p>
)
})}
<button
onClick={() => {
worker.forceSyncPouch()
}}
>
Force sync
</button>
</div>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/dataproxy/common/DataProxyInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ClientCapabilities } from 'cozy-client/types/types'
export interface DataProxyWorker {
search: (query: string) => unknown
setup: (clientData: ClientData) => Promise<void>
forceSyncPouch: () => void
}

export interface DataProxyWorkerPartialState {
Expand Down
12 changes: 12 additions & 0 deletions src/dataproxy/worker/shared-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ const dataProxy: DataProxyWorker = {
const endSearchTime = performance.now()
log.debug(`Search took ${endSearchTime - startSearchTime} ms`)
return results
},

forceSyncPouch: () => {
if (!client) {
throw new Error(
'Client is required to execute a forceSyncPouch, please initialize CozyClient'
)
}
const pouchLink = getPouchLink(client)
if (pouchLink) {
pouchLink.startReplication()
}
}
}

Expand Down

0 comments on commit 10d0b07

Please sign in to comment.