mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-16 07:59:39 +02:00
fix(matrix): validate lastMessageTime before formatting in RoomItem
Add date validation to prevent "Invalid time value" errors when rooms have invalid or zero timestamps. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
68a8ad60b9
commit
d37f5894dc
1 changed files with 9 additions and 8 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<script lang="ts">
|
||||
import type { SimpleRoom } from '$lib/matrix';
|
||||
import { formatDistanceToNow } from 'date-fns';
|
||||
import { formatDistanceToNow, isValid } from 'date-fns';
|
||||
import { de } from 'date-fns/locale';
|
||||
import { Lock, Users } from '@manacore/shared-icons';
|
||||
|
||||
|
|
@ -12,11 +12,12 @@
|
|||
|
||||
let { room, selected, onclick }: Props = $props();
|
||||
|
||||
let timeAgo = $derived(
|
||||
room.lastMessageTime
|
||||
? formatDistanceToNow(room.lastMessageTime, { addSuffix: false, locale: de })
|
||||
: ''
|
||||
);
|
||||
let timeAgo = $derived(() => {
|
||||
if (!room.lastMessageTime) return '';
|
||||
const date = new Date(room.lastMessageTime);
|
||||
if (!isValid(date) || date.getTime() === 0) return '';
|
||||
return formatDistanceToNow(date, { addSuffix: false, locale: de });
|
||||
});
|
||||
|
||||
let initials = $derived(
|
||||
room.name
|
||||
|
|
@ -75,8 +76,8 @@
|
|||
|
||||
<!-- Meta -->
|
||||
<div class="flex flex-shrink-0 flex-col items-end gap-1">
|
||||
{#if timeAgo}
|
||||
<span class="text-xs text-muted-foreground">{timeAgo}</span>
|
||||
{#if timeAgo()}
|
||||
<span class="text-xs text-muted-foreground">{timeAgo()}</span>
|
||||
{/if}
|
||||
{#if room.unreadCount > 0}
|
||||
<span
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue