fix: add fallback to note time

This commit is contained in:
Alejandro Gomez 2023-01-16 11:38:30 +01:00
parent 6ce852e888
commit cd8d4cf2ea
No known key found for this signature in database
GPG Key ID: 4DF39E566658C817
2 changed files with 3 additions and 3 deletions

View File

@ -38,7 +38,7 @@ export default function DM(props: DMProps) {
return (
<div className={`flex dm f-col${props.data.pubkey === pubKey ? " me" : ""}`} ref={ref}>
<div><NoteTime from={props.data.created_at * 1000} /></div>
<div><NoteTime from={props.data.created_at * 1000} fallback={'Just now'} /></div>
<div className="w-max">
<Text content={content} />
</div>

View File

@ -4,7 +4,7 @@ const MinuteInMs = 1_000 * 60;
const HourInMs = MinuteInMs * 60;
const DayInMs = HourInMs * 24;
export default function NoteTime({ from }) {
export default function NoteTime({ from, fallback = '' }) {
const [time, setTime] = useState("");
function calcTime() {
@ -16,7 +16,7 @@ export default function NoteTime({ from }) {
} else if (absAgo > HourInMs) {
return `${fromDate.getHours().toString().padStart(2, '0')}:${fromDate.getMinutes().toString().padStart(2, '0')}`;
} else if (absAgo < MinuteInMs) {
return ''
return fallback
} else {
let mins = parseInt(absAgo / MinuteInMs);
let minutes = mins === 1 ? 'min' : 'mins'