Skip to content

Commit

Permalink
refactor: 코드 리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonjinan096 committed Jul 2, 2024
1 parent 5fd2ae3 commit dc14a64
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/app/(post)/comment/_components/PostComment.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import React, { useState } from 'react';
import React, { ChangeEvent, useState } from 'react';

import { useParams } from 'next/navigation';

Expand All @@ -11,7 +11,7 @@ const PostComment = () => {
const [comment, setComment] = useState('');
const createComment = useCreateComment(postId);

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
setComment(e.target.value);
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/(post)/search/_components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface SearchBarProps {
onSubmit: (input: string) => void;
}

const SearchBar: React.FC<SearchBarProps> = ({ onClear, onSubmit }) => {
const SearchBar = ({ onClear, onSubmit }: SearchBarProps) => {
const [input, setInput] = useState('');

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
Expand Down
44 changes: 23 additions & 21 deletions src/app/(post)/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import React, { useState } from 'react';

import Link from 'next/link';
import { useSearchParams } from 'next/navigation';
import { useRouter, useSearchParams } from 'next/navigation';

import { useGetPostListAPI } from '@/src/apis/postList';
import { CATEGORY_MAP } from '@/src/app/(main)/constants';
Expand All @@ -16,18 +16,21 @@ import EmptyPage from '@/src/components/EmptyPage';
import TopBar from '../../../components/Topbar';
import SearchBar from './_components/SearchBar';

const CreatePostPage = () => {
const SearchPostPage = () => {
const searchParams = useSearchParams();
const router = useRouter();
const channel = (searchParams.get('channel') as ChannelType | null) ?? 'all';
const [keyword, setKeyword] = useState('');
const { content: posts } = useGetPostListAPI(keyword, CATEGORY_MAP[channel]);

const handleRemoveClick = () => {
setKeyword('');
router.push(`/search`);
};

const handleSubmit = (input: string) => {
setKeyword(input);
router.push(`/search`);
};

return (
Expand All @@ -38,27 +41,26 @@ const CreatePostPage = () => {
</TopBar.Container>

{keyword !== '' && (
<ChipContainer currentChannel={channel} defaultPath='/search' />
)}

{keyword !== '' && (
<main className='flex h-full grow flex-col overflow-y-scroll'>
{posts.length ? (
posts.map((post, index) => (
<Link
href={`/result/${post.postId}`}
key={`${index}-${post.voteTitle}`}
>
<PostItem post={post} />
</Link>
))
) : (
<EmptyPage href='/createPost' text='작성 글이 없습니다.' />
)}
</main>
<>
<ChipContainer currentChannel={channel} defaultPath='/search' />
<main className='flex h-full grow flex-col overflow-y-scroll'>
{posts.length ? (
posts.map((post, index) => (
<Link
href={`/result/${post.postId}`}
key={`${index}-${post.voteTitle}`}
>
<PostItem post={post} />
</Link>
))
) : (
<EmptyPage href='/createPost' text='작성 글이 없습니다.' />
)}
</main>
</>
)}
</>
);
};

export default CreatePostPage;
export default SearchPostPage;
2 changes: 1 addition & 1 deletion src/app/_components/ChipContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ const ChipContainer = ({
);
};

export default React.memo(ChipContainer);
export default ChipContainer;
2 changes: 1 addition & 1 deletion src/components/Icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { ComponentProps } from 'react';

import { IconName } from './type';

interface IconProps extends ComponentProps<'svg'> {
interface IconProps extends Omit<ComponentProps<'svg'>, 'width' | 'height'> {
id: IconName;
size?: number;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ const TextInput = forwardRef<HTMLInputElement, TextInputProps>(
);

TextInput.displayName = 'TextInput';
export default React.memo(TextInput);
export default TextInput;

0 comments on commit dc14a64

Please sign in to comment.