File size: 1,304 Bytes
d6da254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<script lang="ts">
	import type { CommentType } from "$lib/type";
  import { get } from "svelte/store";
  import { userStore } from "$lib/stores/use-user";

  export let comment: CommentType;

  const formatDate = (date: string) => {
    const d = new Date(date);
    return `${d.toLocaleDateString()} ${d.toLocaleTimeString()}`;
  }

  const user = get(userStore);
  const isMe = comment?.user?.sub === user?.sub;
</script>

<div
  class="flex items-start justify-start gap-3 w-full"
  class:flex-row-reverse={isMe}
>
  <img src={comment?.user?.picture} class="w-10 h-10 rounded-full object-cover" alt={comment?.user?.name} />
  <div class="w-full lg:max-w-max">
    <div class="flex items-center justify-between mb-2 gap-6" class:flex-row-reverse={isMe}>
      <p class="text-neutral-200 font-semibold text-base truncate flex items-center justify-start gap-2" class:flex-row-reverse={isMe}>
        {comment?.user?.name}
        <span class="italic text-neutral-500 text-xs font-light">({comment?.user?.preferred_username})</span>
      </p>
      <p class="text-xs text-neutral-600">{formatDate(comment?.createdAt)}</p>
    </div>
    <p
      class="bg-neutral-800 bg-opacity-60 rounded-xl text-white/70 text-sm p-4"
      class:!bg-blue-500={isMe}
    >
      {comment.text}
    </p>
  </div>
</div>