-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated dependencies and added human time display to consentos
- Loading branch information
1 parent
8019ee2
commit a805882
Showing
9 changed files
with
10,542 additions
and
4,665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useState } from 'react' | ||
import Timespan from 'readable-timespan' | ||
import useInterval from '@use-it/interval' | ||
|
||
const timespan = new Timespan() | ||
|
||
function stringify (timestamp): string { | ||
return `${timespan.parse(Date.now() - timestamp)} ago` | ||
} | ||
|
||
export function useHumanSince (timestamp: number): string { | ||
const [humanTime, setHumanTime] = useState<string>(() => stringify(timestamp)) | ||
useInterval(() => { | ||
const newTimestamp = stringify(timestamp) | ||
if (newTimestamp !== humanTime) { | ||
setHumanTime(newTimestamp) | ||
} | ||
}, 250) | ||
return humanTime | ||
} |