Skip to content

Commit

Permalink
fix: edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiMez committed Apr 21, 2024
1 parent c893db7 commit 2e4aa39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/lib/_components/Message.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
// Function to refresh the time
const refresh = () => {
const now = new Date();
const diff = now.getTime() - new Date(msg.timestamp).getTime();
const diff = now.getTime() - new Date(msg.timestamp ?? 0).getTime();
time = prettyMilliseconds(diff, { compact: true });
};
const refreshInterval = setInterval(refresh, 10000);
onMount(() => {
const timestamp = new Date(msg.timestamp);
const timestamp = new Date(msg.timestamp ?? 0);
const now = new Date();
const diff = now.getTime() - timestamp.getTime();
time = prettyMilliseconds(diff, { compact: true });
Expand Down
11 changes: 6 additions & 5 deletions src/routes/li/[room]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
const msgObj = {
msg: String(decrypted),
r: encryptedMessage.r,
timestamp: encryptedMessage.timestamp
timestamp: encryptedMessage.timestamp ?? new Date(0).toISOString()
};
// If 'decryptedMessages' doesn't already contain this message, add it
Expand All @@ -125,7 +125,7 @@
async function copyLink() {
await navigator.clipboard.writeText($page.url.origin + '/b/' + rid);
copied = true;
setTimeout(() => (copied = false), 2000); // Reset after 2 seconds
setTimeout(() => (copied = false), 2000);
}
let pollingInterval = 10;
Expand All @@ -148,6 +148,7 @@
if (intervalId) clearInterval(intervalId);
intervalId = setInterval(unpack, pollingInterval * 1000);
}
return clearInterval(intervalId);
});
</script>

Expand Down Expand Up @@ -199,15 +200,15 @@

<div class="flex w-full flex-col gap-3 p-4">
{#if unlocked}
{#each [...decryptedMessages].reverse() as msg (msg.timestamp)}
{#each [...decryptedMessages].reverse() as msg (msg)}
{@const color = generateConsistentIndices(msg.r)}

<Message {msg} {color} />
{/each}

{#if !decryptedMessages.length}
<span class="p-12"> No messages sent to your inbox yet </span>
{/if}

<!-- else if content here -->
{/if}
</div>
</div>
Expand Down

0 comments on commit 2e4aa39

Please sign in to comment.