Skip to content

Commit

Permalink
Display the chat's name at the top of the <Chat /> component
Browse files Browse the repository at this point in the history
  • Loading branch information
mybearworld committed Jul 6, 2024
1 parent b0ee30d commit 8140882
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ export const Chat = (props: ChatProps) => {
const [replies, setReplies] = useState<Reply[]>([]);
const [loadingMore, setLoadingMore] = useState(false);
const [loadMoreError, setLoadMoreError] = useState<string>();
const [posts, loadChatPosts, loadMore] = useAPI(
const [credentials, chat, loadChat, posts, loadChatPosts, loadMore] = useAPI(
useShallow((state) => [
state.credentials,
state.chats[props.chat],
state.loadChat,
state.chatPosts[props.chat],
state.loadChatPosts,
state.loadMore,
]),
);
loadChat(props.chat);
loadChatPosts(props.chat);

const setReplyFromPost = useCallback(
Expand Down Expand Up @@ -70,6 +74,21 @@ export const Chat = (props: ChatProps) => {

return (
<div className="flex flex-col gap-2">
{props.chat === "home" ? undefined : (
<p className="font-bold">
{chat
? chat.error
? `Failed getting chat. Message: ${chat.message}`
: chat.deleted
? ""
: chat.nickname ??
"@" +
chat.members.find(
(member) => member !== credentials?.username,
)
: "Loading chat name..."}
</p>
)}
<EnterPost chat={props.chat} replies={replies} setReplies={setReplies} />
<TypingIndicator chat={props.chat} />
{posts.posts.map((post) => (
Expand Down

0 comments on commit 8140882

Please sign in to comment.