Skip to content

Commit

Permalink
feat(search): click on user gets you to his chat (doesn't create if n…
Browse files Browse the repository at this point in the history
…one) (#162)
  • Loading branch information
amir-kedis authored Dec 21, 2024
1 parent 455dd2e commit 73e6a8b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/src/features/search/components/result-items/ChannelResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import styled from "styled-components";

import Avatar from "@components/Avatar";
import { useNavigate } from "react-router-dom";
import { useAppSelector } from "@hooks/useGlobalState";

const ItemWrapper = styled.div`
display: flex;
Expand Down Expand Up @@ -57,8 +58,20 @@ const ChannelResult: React.FC<ChannelResultProps> = ({
chatId
}) => {
const navigate = useNavigate();
const { chats, members } = useAppSelector((state) => state.chats);

const handleItemClick = () => {
if (chatId) navigate(`/${chatId}`);

const user = members.find((member) => member.username === username);
const userChat = chats.find(
(chat) =>
chat?.type === "private" &&
chat.members
.flatMap((member) => member._id)
.includes(user?._id as string)
);
if (userChat) navigate(`/${userChat._id}`);
};

return (
Expand Down

0 comments on commit 73e6a8b

Please sign in to comment.