작성
·
297
0
안녕하세요.
import React from 'react';
import { Container, Header } from './styles';
import useSWR from 'swr';
import fetcher from '@utils/fetcher';
import { useParams } from 'react-router';
import gravatar from 'gravatar';
const DirectMessage = () => {
const { workspace, id } = useParams<{ workspace: string; id: string }>();
const { data: userData } = useSWR(`api/workspaces/${workspace}/members/${id}`, fetcher);
const { data: myData } = useSWR('api/users', fetcher);
if (!userData || !myData) {
return null;
}
return (
<Container>
<Header>
<img src={gravatar.url(userData.email, { s: '24px', d: 'retor' })} alt={userData.nickname} />
<span>{userData.nickname}</span>
</Header>
{/* <ChatList />
<ChatBox /> */}
</Container>
);
};
export default DirectMessage;
이건 DirectMessage입니다.
// import EachDM from '@components/EachDM';
// import useSocket from '@hooks/useSocket';
import { CollapseButton } from '@components/DMList/styles';
import { IDM, IUser, IUserWithOnline } from '@typings/db';
import fetcher from '@utils/fetcher';
import React, { FC, useCallback, useEffect, useState } from 'react';
import { useParams } from 'react-router';
import { NavLink } from 'react-router-dom';
import useSWR from 'swr';
const DMList: FC = () => {
const { workspace } = useParams<{ workspace?: string }>();
const { data: userData } = useSWR<IUser>('/api/users', fetcher, {
dedupingInterval: 2000, // 2초
});
const { data: memberData } = useSWR<IUserWithOnline[]>(
userData ? `/api/workspaces/${workspace}/members` : null,
fetcher,
);
// const [socket] = useSocket(workspace);
const [channelCollapse, setChannelCollapse] = useState(false);
const [countList, setCountList] = useState<{ [key: string]: number }>({});
const [onlineList, setOnlineList] = useState<number[]>([]);
const toggleChannelCollapse = useCallback(() => {
setChannelCollapse((prev) => !prev);
}, []);
const resetCount = useCallback(
(id) => () => {
setCountList((list) => {
return {
...list,
[id]: 0,
};
});
},
[],
);
const onMessage = (data: IDM) => {
console.log('dm왔다', data);
setCountList((list) => {
return {
...list,
[data.SenderId]: list[data.SenderId] ? list[data.SenderId] + 1 : 1,
};
});
};
useEffect(() => {
console.log('DMList: workspace 바꼈다', workspace);
setOnlineList([]);
setCountList({});
}, [workspace]);
// useEffect(() => {
// socket?.on('onlineList', (data: number[]) => {
// setOnlineList(data);
// });
// console.log('socket on dm', socket?.hasListeners('dm'), socket);
// return () => {
// console.log('socket off dm', socket?.hasListeners('dm'));
// socket?.off('onlineList');
// };
// }, [socket]);
return (
<>
<h2>
<CollapseButton collapse={channelCollapse} onClick={toggleChannelCollapse}>
<i
className="c-icon p-channel_sidebar__section_heading_expand p-channel_sidebar__section_heading_expand--show_more_feature c-icon--caret-right c-icon--inherit c-icon--inline"
data-qa="channel-section-collapse"
aria-hidden="true"
/>
</CollapseButton>
<span>Direct Messages</span>
</h2>
<div>
{!channelCollapse &&
memberData?.map((member) => {
const isOnline = onlineList.includes(member.id);
const count = countList[member.id] || 0;
<NavLink
key={member.id}
activeClassName="selected"
to={`/workapce/${workspace}/dm/${member.id}`}
onClick={resetCount(member.id)}
>
;
<i
className={`c-icon p-channel_sidebar__presence_icon p-channel_sidebar__presence_icon--dim_enabled c-presence ${
isOnline ? 'c-presence--active c-icon--presence-online' : 'c-icon--presence-offline'
}`}
aria-hidden="true"
data-qa="presence_indicator"
data-qa-presence-self="false"
data-qa-presence-active="false"
data-qa-presence-dnd="false"
/>
;<span className={count > 0 ? 'bold' : undefined}>{member.nickname}</span>
{member.id === userData?.id && <span> (나)</span>}
{count > 0 && <span className="count">{count}</span>}
</NavLink>;
// return <EachDM key={member.id} member={member} isOnline={isOnline} />;
})}
</div>
</>
);
};
export default DMList;
이건 DMList입니다.
현재 DM페이지 만들기 강의를 듣고 있는데, DM리스트에 사용자가 하나도 표시가 되지 않는데 원래 지금 강의까지는 표시가 되지 않는게 맞나요?
워크스페이스 초대, 채널 멤버 초대해도 에러는 발생하지 않는데 DM리스트에 추가는 다음 강의에서 진행하나요? 아니면 지금도 되야하는게 정상인가요..?
아.. 제 눈에는 찾아봐도 왜 안보였을까요.. 감사합니다!!
항상 빠른 답변 감사드려요!!