Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into feat/mobile-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
andyesp committed Oct 18, 2023
2 parents b811feb + 2476920 commit 90b1020
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 30 deletions.
50 changes: 47 additions & 3 deletions src/components/Debug/SnapshotStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,62 @@
import { useEffect, useState } from 'react'

import classNames from 'classnames'

import { Governance } from '../../clients/Governance'
import { ServiceHealth, SnapshotStatus as SnapshotServiceStatus } from '../../clients/SnapshotTypes'
import { SNAPSHOT_STATUS_ENABLED } from '../../constants'
import useFormatMessage from '../../hooks/useFormatMessage'
import useSnapshotStatus from '../../hooks/useSnapshotStatus'
import Markdown from '../Common/Typography/Markdown'
import WarningTriangle from '../Icon/WarningTriangle'

import './SnapshotStatus.css'

const PING_INTERVAL_IN_MS = 30000 // 30 seconds

function logIfNotNormal(status: SnapshotServiceStatus) {
if (status.scoresStatus.health !== ServiceHealth.Normal || status.graphQlStatus.health !== ServiceHealth.Normal) {
console.log('Snapshot Status', status)
}
}

export default function SnapshotStatus() {
const t = useFormatMessage()
const showSnapshotStatus = useSnapshotStatus()
const [showTopBar, setShowTopBar] = useState(false)
const [ping, setPing] = useState(false)

const updateServiceStatus = async () => {
const status = await Governance.get().getSnapshotStatus()
logIfNotNormal(status)
const show = status.scoresStatus.health === ServiceHealth.Failing && SNAPSHOT_STATUS_ENABLED
setShowTopBar(show)
}

useEffect(() => {
if (typeof document !== 'undefined') {
const handleVisibilityChange = () => {
setPing(!document.hidden)
}

document.addEventListener('visibilitychange', handleVisibilityChange)

return () => {
document.removeEventListener('visibilitychange', handleVisibilityChange)
}
}
}, [])

useEffect(() => {
const intervalId = setInterval(() => {
if (ping) {
updateServiceStatus()
}
}, PING_INTERVAL_IN_MS)

return () => clearInterval(intervalId)
}, [ping])

return (
<div className={classNames(`SnapshotStatus__TopBar`, showSnapshotStatus && 'SnapshotStatus__TopBar--visible')}>
<div className={classNames(`SnapshotStatus__TopBar`, showTopBar && 'SnapshotStatus__TopBar--visible')}>
<WarningTriangle size="18" />
<Markdown size="sm" componentsClassNames={{ p: 'SnapshotStatus__Text', strong: 'SnapshotStatus__Text' }}>
{t('page.debug.snapshot_status.label')}
Expand Down
27 changes: 0 additions & 27 deletions src/hooks/useSnapshotStatus.ts

This file was deleted.

0 comments on commit 90b1020

Please sign in to comment.