Skip to content

Commit

Permalink
[frontend] use context in UserList
Browse files Browse the repository at this point in the history
  • Loading branch information
kotto5 committed Feb 11, 2024
1 parent 8299309 commit 15990b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions frontend/app/lib/hooks/useOnlineStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use client";

import { useState } from "react";

export function useOnlineStatus() {
const [onlineStatus, setOnlineStatus] = useState<{ [key: number]: number }>(
{}
);
return { onlineStatus, setOnlineStatus };
}
6 changes: 4 additions & 2 deletions frontend/app/ui/user/user-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import type { PublicUserEntity } from "@/app/lib/dtos";
import { TooltipProvider } from "@/components/ui/tooltip";
import { Avatar, AvatarSize } from "./avatar";
import { useEffect, useState } from "react";
import { OnlineContext } from "@/app/lib/client-socket-provider";
import { useContext } from "react";

export default function UserList({
users,
Expand All @@ -12,6 +13,7 @@ export default function UserList({
users: PublicUserEntity[];
avatarSize: AvatarSize;
}) {
const onlineStatus = useContext(OnlineContext);
return (
<TooltipProvider delayDuration={0}>
<div className="flex flex-wrap gap-2">
Expand All @@ -22,7 +24,7 @@ export default function UserList({
size={avatarSize}
href={`/user/${u.id}`}
alt={u.name}
online={true}
online={onlineStatus[u.id] === 1}
key={u.id}
/>
))}
Expand Down

0 comments on commit 15990b6

Please sign in to comment.