From fc0f1654a56d2247728a766f43e72ff169704888 Mon Sep 17 00:00:00 2001
From: Owen Jacobson <owen@grimoire.ca>
Date: Sat, 15 Feb 2025 15:17:03 -0500
Subject: Hoist global state access out of individual components.

Access to "global" (maybe "external?") state is now handled at the top level of the component hierarchy, in `+page.svelte`, `+layout.svelte`, and their associated scripts. State is otherwise passed down through props, and changes are passed up through callbacks.

This is - hopefully - groundwork for refactoring state management a bit. I wanted to move access to state out to a smaller number of places, so that I have fewer places to update to implement reconnect logic. My broader goal is to make it easier to refactor these kinds of external side effects, as well, though no such changes are in this branch.

This change also makes testing a mile easier, since tests can interact with props and callbacks instead of emulating the whole HTTP request stack and the Pilcrow API. This change removes do-very-little tests.
---
 ui/lib/components/Message.svelte | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

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

diff --git a/ui/lib/components/Message.svelte b/ui/lib/components/Message.svelte
index 1b1598b..dacd900 100644
--- a/ui/lib/components/Message.svelte
+++ b/ui/lib/components/Message.svelte
@@ -1,16 +1,15 @@
 <script>
   import { DateTime } from 'luxon';
-  import { deleteMessage } from '$lib/apiServer';
 
   function scroll(message) {
     message.scrollIntoView();
   }
 
-  let { id, at, body, renderedBody, editable = false } = $props();
+  let { id, at, body, renderedBody, editable = false, deleteMessage = async (id) => {} } = $props();
   let deleteArmed = $state(false);
   let atFormatted = $derived(at.toLocaleString(DateTime.DATETIME_SHORT));
 
-  function onDelete(event) {
+  function ondelete(event) {
     event.preventDefault();
     if (deleteArmed) {
       deleteArmed = false;
@@ -29,7 +28,7 @@
   <div class="handle">
     {atFormatted}
     {#if editable}
-      <button onclick={onDelete}>&#x1F5D1;&#xFE0F;</button>
+      <button onclick={ondelete}>&#x1F5D1;&#xFE0F;</button>
     {/if}
   </div>
   <section use:scroll class="message-body">
-- 
cgit v1.2.3

