diff options
author | Eric Bailey <git@esb.lol> | 2023-07-19 12:16:57 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-19 12:16:57 -0500 |
commit | 0ae52e91ceaf1af41f12bfa6e76c7d719be5e0e5 (patch) | |
tree | a395def20fc038da3f41920733d18f3a93b07541 /src/view/com/util/TimeElapsed.tsx | |
parent | 4515559b1a7db493188cfe92abf8ea5cfd53c6dc (diff) | |
download | voidsky-0ae52e91ceaf1af41f12bfa6e76c7d719be5e0e5.tar.zst |
* add TimeElapsed util component, integrate into PostThreadItem * integrate into posts * use consistent naming * use mobx and single interval for TimeElapsed
Diffstat (limited to 'src/view/com/util/TimeElapsed.tsx')
-rw-r--r-- | src/view/com/util/TimeElapsed.tsx | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/view/com/util/TimeElapsed.tsx b/src/view/com/util/TimeElapsed.tsx new file mode 100644 index 000000000..7b2dd61f3 --- /dev/null +++ b/src/view/com/util/TimeElapsed.tsx @@ -0,0 +1,21 @@ +import React from 'react' +import {observer} from 'mobx-react-lite' +import {ago} from 'lib/strings/time' +import {useStores} from 'state/index' + +export const TimeElapsed = observer(function TimeElapsed({ + timestamp, + children, +}: { + timestamp: string + children: ({timeElapsed}: {timeElapsed: string}) => JSX.Element +}) { + const stores = useStores() + const [timeElapsed, setTimeAgo] = React.useState(ago(timestamp)) + + React.useEffect(() => { + setTimeAgo(ago(timestamp)) + }, [timestamp, setTimeAgo, stores.shell.tickEveryMinute]) + + return children({timeElapsed}) +}) |