From b85dcad22f89de7ec8d07ab1776fa2f51a08ae24 Mon Sep 17 00:00:00 2001
From: Kit La Touche <kit@transneptune.net>
Date: Fri, 29 Nov 2024 14:32:00 -0500
Subject: Use Luxon dates on Message store and component

This includes jamming the "at" of a message into a data- attribute on
the Message component, so that it can later be used by parent components
via Plain Old Javascript and the .dataset attribute of an HTML node.
---
 ui/lib/components/Message.svelte | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

(limited to 'ui/lib/components/Message.svelte')

diff --git a/ui/lib/components/Message.svelte b/ui/lib/components/Message.svelte
index 1663696..5673248 100644
--- a/ui/lib/components/Message.svelte
+++ b/ui/lib/components/Message.svelte
@@ -1,4 +1,5 @@
 <script>
+  import { DateTime } from 'luxon';
   import { deleteMessage } from '$lib/apiServer';
 
   function scroll(message) {
@@ -7,6 +8,7 @@
 
   let { id, at, body, renderedBody, editable = false } = $props();
   let deleteArmed = $state(false);
+  let atFormatted = $derived(at.toLocaleString(DateTime.DATETIME_SHORT));
 
   function onDelete(event) {
     event.preventDefault();
@@ -23,9 +25,15 @@
   }
 </script>
 
-<div class="message relative" class:bg-warning-800={deleteArmed} {onmouseleave} role="article">
+<div
+    class="message relative"
+    class:bg-warning-800={deleteArmed}
+    role="article"
+    data-at={at}
+    {onmouseleave}
+    >
   <div class="handle chip bg-surface-700 absolute -top-6 right-0">
-    {at}
+    {atFormatted}
     {#if editable}
       <button onclick={onDelete}>&#x1F5D1;&#xFE0F;</button>
     {/if}
-- 
cgit v1.2.3

