Skip to content

Commit

Permalink
Merge pull request #167 from sebanimm/main
Browse files Browse the repository at this point in the history
fix: if문을 객체 방식으로 수정
  • Loading branch information
Ubinquitous authored Jan 18, 2024
2 parents d96e0ca + 6f348f7 commit 7495c72
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 54 deletions.
70 changes: 43 additions & 27 deletions src/templates/post/layouts/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { CATEGORY } from "../../constants";
import { usePostWritable } from "../../hooks";
import { PostDetailParamsProps } from "../../types/@props";

type PostCategoryType = {
[key in keyof typeof CATEGORY]?: JSX.Element;
};

const PostEditPage = ({ id }: PostDetailParamsProps) => {
const { post } = usePostQuery(id);
const {
Expand All @@ -24,6 +28,44 @@ const PostEditPage = ({ id }: PostDetailParamsProps) => {
handlePostEditButtonClick,
handleInputPostDataChange,
} = usePostWritable(post);

const PostCategory: PostCategoryType = {
PROJECT: (
<ProjectInputBox
handleChange={handleInputPostDataChange}
postData={postData}
/>
),
CODE_REVIEW: (
<CodeReviewInputBox
handleChange={handleInputPostDataChange}
postData={postData}
/>
),
LOST: (
<LostFoundInputBox
handleChange={handleInputPostDataChange}
handleFileSelect={handleImageFileSelect}
postData={postData}
lostImageUrl={lostImageUrl}
/>
),
FOUND: (
<>
<LostFoundInputBox
handleChange={handleInputPostDataChange}
handleFileSelect={handleImageFileSelect}
postData={postData}
lostImageUrl={lostImageUrl}
/>
<FoundInputBox
handleChange={handleInputPostDataChange}
postData={postData}
/>
</>
),
};

return (
<>
<Layout>
Expand All @@ -34,33 +76,7 @@ const PostEditPage = ({ id }: PostDetailParamsProps) => {
handleChange={handleInputPostDataChange}
postData={postData}
/>
{postData.category === CATEGORY.PROJECT && (
<ProjectInputBox
handleChange={handleInputPostDataChange}
postData={postData}
/>
)}
{postData.category === CATEGORY.CODE_REVIEW && (
<CodeReviewInputBox
handleChange={handleInputPostDataChange}
postData={postData}
/>
)}
{(postData.category === CATEGORY.LOST ||
postData.category === CATEGORY.FOUND) && (
<LostFoundInputBox
handleChange={handleInputPostDataChange}
handleFileSelect={handleImageFileSelect}
postData={postData}
lostImageUrl={lostImageUrl}
/>
)}
{postData.category === CATEGORY.FOUND && (
<FoundInputBox
handleChange={handleInputPostDataChange}
postData={postData}
/>
)}
{PostCategory[postData.category]}
<ContentInputBox
handleChange={handleInputPostDataChange}
postData={postData}
Expand Down
70 changes: 43 additions & 27 deletions src/templates/post/layouts/write/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { CATEGORY } from "../../constants";
import { usePostWritable } from "../../hooks";
import PostCategoryBox from "./CategoryBox";

type PostCategoryType = {
[key in keyof typeof CATEGORY]?: JSX.Element;
};

const PostWritePage = () => {
const {
postData,
Expand All @@ -23,6 +27,44 @@ const PostWritePage = () => {
handlePostWriteButtonClick,
handleInputPostDataChange,
} = usePostWritable();

const PostCategory: PostCategoryType = {
PROJECT: (
<ProjectInputBox
handleChange={handleInputPostDataChange}
postData={postData}
/>
),
CODE_REVIEW: (
<CodeReviewInputBox
handleChange={handleInputPostDataChange}
postData={postData}
/>
),
LOST: (
<LostFoundInputBox
handleChange={handleInputPostDataChange}
handleFileSelect={handleImageFileSelect}
postData={postData}
lostImageUrl={lostImageUrl}
/>
),
FOUND: (
<>
<LostFoundInputBox
handleChange={handleInputPostDataChange}
handleFileSelect={handleImageFileSelect}
postData={postData}
lostImageUrl={lostImageUrl}
/>
<FoundInputBox
handleChange={handleInputPostDataChange}
postData={postData}
/>
</>
),
};

return (
<>
<Layout>
Expand All @@ -37,33 +79,7 @@ const PostWritePage = () => {
handleChange={handleInputPostDataChange}
postData={postData}
/>
{postData.category === CATEGORY.PROJECT && (
<ProjectInputBox
handleChange={handleInputPostDataChange}
postData={postData}
/>
)}
{postData.category === CATEGORY.CODE_REVIEW && (
<CodeReviewInputBox
handleChange={handleInputPostDataChange}
postData={postData}
/>
)}
{(postData.category === CATEGORY.LOST ||
postData.category === CATEGORY.FOUND) && (
<LostFoundInputBox
handleChange={handleInputPostDataChange}
handleFileSelect={handleImageFileSelect}
postData={postData}
lostImageUrl={lostImageUrl}
/>
)}
{postData.category === CATEGORY.FOUND && (
<FoundInputBox
handleChange={handleInputPostDataChange}
postData={postData}
/>
)}
{PostCategory[postData.category]}
<ContentInputBox
handleChange={handleInputPostDataChange}
postData={postData}
Expand Down

0 comments on commit 7495c72

Please sign in to comment.