Skip to content

Commit

Permalink
Adjust sync details information to follow BE data
Browse files Browse the repository at this point in the history
  • Loading branch information
WRadoslaw committed Oct 3, 2023
1 parent a65351f commit c6b4fe2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { YppStatusDot } from '@/components/_ypp/YppStatusPill'
import { atlasConfig } from '@/config'
import { cVar, sizes } from '@/styles'
import { ConsoleLogger } from '@/utils/logs'
import { YppChannelStatus } from '@/views/global/YppLandingView/YppLandingView.types'
import { formatDurationShort } from '@/utils/time'
import { YppChannelStatus, YppSyncedChannel } from '@/views/global/YppLandingView/YppLandingView.types'

type YppStatusDto = {
version: string
Expand All @@ -24,39 +25,44 @@ const YPP_DELAY_THRESHOLD = atlasConfig.features.ypp.yppDelayThreshold ?? 500

export type ServiceStatusWidgetProps = {
status?: YppChannelStatus
syncStatus?: YppSyncedChannel['syncStatus']
}

export const ServiceStatusWidget = ({ status }: ServiceStatusWidgetProps) => {
export const ServiceStatusWidget = ({ status, syncStatus }: ServiceStatusWidgetProps) => {
const { data } = useQuery('ypp-status', () =>
axiosInstance<YppStatusDto>(`${YOUTUBE_BACKEND_URL}/status`).catch(() =>
ConsoleLogger.warn('Failed to fetch YPP status')
)
)

const details = useMemo(() => {
if (!data) return []
if (!syncStatus) return []
const hideData = !status || !status.startsWith('Verified')
const output: [number | string, string, string][] = [] // [value, title, tooltip]

// todo: all this data needs to be user scoped, rn backend does not support it
output.push([
hideData ? '-' : data.data.syncBacklog,
hideData ? '-' : syncStatus.backlogCount || 'All synced',
'VIDEOS IN QUEUE',
'This is the total amount of your YouTube videos that are waiting to be synced',
])
output.push([
hideData ? '-' : data.data.syncBacklog * 2 === 0 ? 'Syncing...' : data.data.syncBacklog * 2, // no info bout it
hideData
? '-'
: syncStatus.placeInSyncQueue === 0
? syncStatus.backlogCount > 0
? 'Syncing...'
: '-'
: syncStatus.placeInSyncQueue, // no info bout it
'PLACE IN THE QUEUE',
'Sync system is based on queue as we sync channels one at a time. When you reach place 1 in queue your sync will start.',
])
output.push([
// isOptedIn ? `In ${Math.round(data.data.syncBacklog / YPP_DELAY_THRESHOLD)} days` : '-',
'-',
hideData ? '-' : syncStatus.backlogCount > 0 ? `In ${formatDurationShort(syncStatus.fullSyncEta)} hours` : '-',
'ETA TO FULL SYNC',
'Estimated time of full sync of your videos may change based on YPP service status or service overload.',
])
return output
}, [data, status])
}, [status, syncStatus])

return (
<LayoutBox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ export type YppSyncedChannel = {
yppStatus: 'Unverified' | 'Suspended' | 'Verified'
}[]
referrerChannelId: string
syncStatus: {
backlogCount: number
fullSyncEta: number
placeInSyncQueue: number
}
}

0 comments on commit c6b4fe2

Please sign in to comment.