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