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

[Feature/#47] 태그 생성 기능 추가 #52

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
45 changes: 27 additions & 18 deletions src/components/SelectTag/SelectTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,42 @@ import Text from "@/components/ui/Text/Text";

import { useRoute } from "@/hooks/common/useRoute";

// 임시 데이터
const TAG_LIST = [
"음식이 맛있어요",
"양이 많아요",
"가성비가 좋아요",
"메뉴 구성이 알차요",
"매장이 넓어요",
"단체모임 하기 좋아요",
"뷰가 좋아요",
"아늑해요",
"분위기가 좋아요",
"친절해요",
"매장이 청결해요",
];

const SelectTag = () => {
const { navigateToSelectStyle } = useRoute();

const [selectedTagList, setSelectedTagList] = useState<string[]>([]);
const [isBottomSheetOpen, setIsBottomSheetOpen] = useState(false);
const [tagList, setTagList] = useState<string[]>([
"음식이 맛있어요",
"양이 많아요",
"가성비가 좋아요",
"메뉴 구성이 알차요",
"매장이 넓어요",
"단체모임 하기 좋아요",
"뷰가 좋아요",
"아늑해요",
"분위기가 좋아요",
"친절해요",
"매장이 청결해요",
]);

const handleTagClick = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
const tag = e.currentTarget.textContent || "";

setSelectedTagList((prevSelectedTags) =>
prevSelectedTags.includes(tag)
? prevSelectedTags.filter((selectedTag) => selectedTag !== tag)
: [...prevSelectedTags, tag],
: [...prevSelectedTags, tag]
);
};

const handleTagAdd = (newTag: string) => {
setIsBottomSheetOpen(false);
if (!tagList.includes(newTag)) {
setTagList((prevTagList: string[]) => [...prevTagList, newTag]);
}
};

const handleSheetClose = () => {
setIsBottomSheetOpen(false);
};
Expand All @@ -55,7 +60,7 @@ const SelectTag = () => {
</Text>
</div>
<div className={styles.TagList}>
{TAG_LIST.map((tag) => (
{tagList.map((tag) => (
<Tag
text={tag}
key={tag}
Expand All @@ -71,7 +76,11 @@ const SelectTag = () => {
<Button text="다음" onClick={navigateToSelectStyle} />
</div>

<TagSheet isOpen={isBottomSheetOpen} handleClose={handleSheetClose} />
<TagSheet
isOpen={isBottomSheetOpen}
handleClose={handleSheetClose}
handleTagAdd={handleTagAdd}
/>
</div>
);
};
Expand Down
17 changes: 14 additions & 3 deletions src/components/SelectTag/TagSheet/TagSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useState, useEffect } from "react";

import * as Dialog from "@radix-ui/react-dialog";
import * as VisuallyHidden from "@radix-ui/react-visually-hidden";
Expand All @@ -15,16 +15,23 @@ import { useFocus } from "@/hooks/common/useFocus";
interface TagSheetProps {
isOpen: boolean;
handleClose: () => void;
handleTagAdd: (newTag: string) => void;
}

const TagSheet = ({ isOpen, handleClose }: TagSheetProps) => {
const TagSheet = ({ isOpen, handleClose, handleTagAdd }: TagSheetProps) => {
const { isFocus, onFocus, onBlur } = useFocus({ defaultFocus: true });

const [newTag, setNewTag] = useState("");

const isInputError = newTag.length > 20;
const isInputEmpty = newTag.length === 0;

useEffect(() => {
if (isOpen) {
setNewTag("");
}
}, [isOpen]);

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setNewTag(e.target.value);
};
Expand Down Expand Up @@ -82,7 +89,11 @@ const TagSheet = ({ isOpen, handleClose }: TagSheetProps) => {
)}
</div>

<Button text="추가하기" disabled={isInputError || isInputEmpty} />
<Button
text="추가하기"
disabled={isInputError || isInputEmpty}
onClick={() => handleTagAdd(newTag)}
/>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
Expand Down