From 33e4bc87d940ecb107c2e21525e8fb4436d6e173 Mon Sep 17 00:00:00 2001 From: Nabil Ould Hamou Date: Wed, 11 Dec 2024 16:53:42 +0100 Subject: [PATCH] feat: cache removing channels and messages that haven't been used in long --- src/lib/components/Message.svelte | 97 +++++++++++-------- src/routes/api/channels/+server.ts | 2 +- .../api/channels/[id]/messages/+server.ts | 27 +++--- src/routes/chats/[id]/+page.server.ts | 1 + src/routes/chats/[id]/+page.svelte | 11 ++- src/routes/user/edit/+page.svelte | 14 ++- 6 files changed, 93 insertions(+), 59 deletions(-) diff --git a/src/lib/components/Message.svelte b/src/lib/components/Message.svelte index e4466c2..3e65192 100644 --- a/src/lib/components/Message.svelte +++ b/src/lib/components/Message.svelte @@ -8,8 +8,6 @@ export let message = null; // Contenu du message - let defaultProfilePicture = "/images/default-profile.png"; - export let setActiveProfile; export let activeProfileId = null; @@ -21,11 +19,28 @@ timeElapsed = formatDistanceToNow(message.createdAt); }; + let user = null; + + async function fetchUser() { + const res = await fetch(`/api/users/${message.user.id}`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }); + + const data = await res.json(); + console.log(data) + user = data; + } + // Initialisation de l'intervalle - onMount(() => { + onMount(async () => { updateElapsed(); // Calcul initial const interval = setInterval(updateElapsed, 1000); // Mise à jour toutes les secondes + await fetchUser(); + return () => { clearInterval(interval); // Nettoyage lors du démontage }; @@ -41,50 +56,56 @@ } } + + - - - - +{#if user !== null} + + + + + {timeElapsed} - -
-
- - Profile Picture - - - -
- -
- +
+
- {myMessage ? "(Moi)" : ""} {message.user.username} - + + Profile Picture + + + +
+ +
+ + {myMessage ? "(Moi)" : ""} {user.username} + +
-
- + - - -

{message.text}

-
- + + +

{message.text}

+
+ + +{/if}