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}