Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#338] Refactor: main page 탠스택 쿼리 적용 #339

Merged
merged 14 commits into from
Jun 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions src/pages/Main/components/ContentHeader/index.tsx
ienrum marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,39 +1,21 @@
import { useNavigate, useParams } from 'react-router-dom';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { Button, Text } from '@/components';
import { useSelectedChannel } from '@/hooks/useSelectedChannel';
import { useSelectedStatus } from '@/hooks/useSelectedStatus';
import { ContentHeaderWrapper } from '@/pages/Main/components/ContentHeader/style';

const ContentHeader = () => {
const { channelId } = useParams();
const navigate = useNavigate();
const channelName = useLocation().state as string;
ienrum marked this conversation as resolved.
Show resolved Hide resolved

const handleWriteClick: React.MouseEventHandler<HTMLButtonElement> = (e) => {
e.preventDefault();
navigate(`/write/${channelId ? channelId : 'unselected'}`);
};

const channel = useSelectedChannel();
const fullPostStatus = useSelectedStatus('get', '/posts');
const postByChannelStatue = useSelectedStatus(
'get',
'/posts/channel/',
channelId,
);

const channelTitle = (() => {
if (postByChannelStatue.isLoading) return '로딩중';
if (!channelId && !fullPostStatus.isLoading) return '전체 글';
if (postByChannelStatue.error && !postByChannelStatue.isLoading)
return '채널을 찾을 수 없습니다.';
if (channel) return channel.name;
return '로딩중';
})();

return (
<ContentHeaderWrapper>
<Text tagType='span' fontType='h2'>
{channelTitle}
{channelName ? channelName : '전체 글'}
</Text>
<Button styleType='ghost' size='small' onClick={handleWriteClick}>
글 쓰기
Expand Down