Force callers of getTimeAgo to pass in the 'now' value
This commit is contained in:
@@ -12,10 +12,11 @@ export function useGetTimeAgo() {
|
||||
const {_} = useLingui()
|
||||
return useCallback(
|
||||
(
|
||||
date: number | string | Date,
|
||||
earlier: number | string | Date,
|
||||
later: number | string | Date,
|
||||
options?: Omit<TimeAgoOptions, 'lingui'>,
|
||||
) => {
|
||||
return dateDiff(date, Date.now(), {lingui: _, format: options?.format})
|
||||
return dateDiff(earlier, later, {lingui: _, format: options?.format})
|
||||
},
|
||||
[_],
|
||||
)
|
||||
|
||||
@@ -15,12 +15,14 @@ export function TimeElapsed({
|
||||
const ago = useGetTimeAgo()
|
||||
const format = timeToString ?? ago
|
||||
const tick = useTickEveryMinute()
|
||||
const [timeElapsed, setTimeAgo] = React.useState(() => format(timestamp))
|
||||
const [timeElapsed, setTimeAgo] = React.useState(() =>
|
||||
format(timestamp, tick),
|
||||
)
|
||||
|
||||
const [prevTick, setPrevTick] = React.useState(tick)
|
||||
if (prevTick !== tick) {
|
||||
setPrevTick(tick)
|
||||
setTimeAgo(format(timestamp))
|
||||
setTimeAgo(format(timestamp, tick))
|
||||
}
|
||||
|
||||
return children({timeElapsed})
|
||||
|
||||
@@ -7,6 +7,7 @@ import {useFocusEffect} from '@react-navigation/native'
|
||||
|
||||
import {useGetTimeAgo} from '#/lib/hooks/useTimeAgo'
|
||||
import {getEntries} from '#/logger/logDump'
|
||||
import {useTickEveryMinute} from '#/state/shell'
|
||||
import {useSetMinimalShellMode} from '#/state/shell'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {CommonNavigatorParams, NativeStackScreenProps} from 'lib/routes/types'
|
||||
@@ -24,6 +25,7 @@ export function LogScreen({}: NativeStackScreenProps<
|
||||
const setMinimalShellMode = useSetMinimalShellMode()
|
||||
const [expanded, setExpanded] = React.useState<string[]>([])
|
||||
const timeAgo = useGetTimeAgo()
|
||||
const tick = useTickEveryMinute()
|
||||
|
||||
useFocusEffect(
|
||||
React.useCallback(() => {
|
||||
@@ -72,7 +74,7 @@ export function LogScreen({}: NativeStackScreenProps<
|
||||
/>
|
||||
) : undefined}
|
||||
<Text type="sm" style={[styles.ts, pal.textLight]}>
|
||||
{timeAgo(entry.timestamp)}
|
||||
{timeAgo(entry.timestamp, tick)}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
{expanded.includes(entry.id) ? (
|
||||
|
||||
Reference in New Issue
Block a user