Skip to content

Commit

Permalink
Merge pull request #284 from kse-publications/fix/sync-poling
Browse files Browse the repository at this point in the history
fix-(client): sync pooling
  • Loading branch information
DmytroKolisnyk2 authored Jul 5, 2024
2 parents f1f2f81 + 3195a92 commit 7232eaf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 additions & 1 deletion client/src/components/ui/sync-status.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
import { useEffect, useState } from 'react'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './tooltip'
import { getSyncStatus } from '@/services/sync/get-sync-status'

interface SyncStatusProps {
isSync: boolean
}

export const SyncStatus = ({ isSync }: SyncStatusProps) => {
const SYNC_POLL_INTERVAL = 10000

export const SyncStatus = ({ isSync: isSyncProps }: SyncStatusProps) => {
const [isSync, setIsSync] = useState(isSyncProps)

useEffect(() => {
if (!isSync) return

const pollSyncStatus = async () => {
try {
const isSync = await getSyncStatus()
setIsSync(isSync)
} catch (error) {
console.error('Error polling sync status:', error)
}
}

const timeout = setTimeout(pollSyncStatus, SYNC_POLL_INTERVAL)

return () => clearTimeout(timeout)
}, [isSync])

if (!isSync) return null

return (
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/publications/[id].astro
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const data = await getPublication(id, clientUuid?.value).catch((error) => {
})
interface AuthorData {
id: number,
id: number
name: string
}
Expand Down

0 comments on commit 7232eaf

Please sign in to comment.