Skip to content

Commit

Permalink
fix: don’t use nested ternaries
Browse files Browse the repository at this point in the history
  • Loading branch information
compojoom committed Oct 25, 2024
1 parent e089cce commit cde6f8e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/components/sidebar/IndexingStatus/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,26 @@ const STATUSES = {
},
}

const getStatus = (synced: boolean, lastSync: number) => {
let status = STATUSES.outOfSync

if (synced) {
status = STATUSES.synced
} else if (Date.now() - lastSync > MAX_SYNC_DELAY) {
status = STATUSES.slow
}

return status
}

const IndexingStatus = () => {
const [data] = useIndexingStatus()

if (!data) {
return null
}

const status = data.synced
? STATUSES.synced
: Date.now() - data.lastSync > MAX_SYNC_DELAY
? STATUSES.slow
: STATUSES.outOfSync
const status = getStatus(data.synced, data.lastSync)

const time = formatDistanceToNow(data.lastSync, { addSuffix: true })

Expand Down

0 comments on commit cde6f8e

Please sign in to comment.