Skip to content

Commit

Permalink
feat: fill 다 채워져 있는지 확인하는 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
minjeoong committed Jan 17, 2025
1 parent 84e7767 commit 0c0b1ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/page/community/write/Write.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ interface writeProps {
title: string;
content: string;
image: string[];
tag: string;
selectedChips: {
breedId: number[];
diseaseIds: number[];
Expand All @@ -57,20 +56,17 @@ const Write = () => {
category: "",
title: "",
content: "",
tag: "",
image: [],
selectedChips: {
breedId: [],
diseaseIds: [],
symptomIds: [],
},
});
const [images, setImages] = useState<string[]>([]);
const fileInputRef = useRef<HTMLInputElement>(null);

const { isDropDownOpen, toggleDropDown, closeDropDown } = useDropDown();
const { category, selectedChips, setCategory, isOpen, setOpen, toggleChips } =
useFilterStore();
const { selectedChips, isOpen, setOpen } = useFilterStore();

const TagLabel = [
{
Expand Down Expand Up @@ -121,13 +117,19 @@ const Write = () => {
const handleAddImage = (event: React.ChangeEvent<HTMLInputElement>) => {
if (event.target.files && event.target.files[0]) {
const newImage = URL.createObjectURL(event.target.files[0]);
setImages((prev) => [...prev, newImage]);
setParams((prevParams) => ({
...prevParams,
image: [...prevParams.image, newImage],
}));
}
};

// 이미지 삭제
const handleDeleteImage = (index: number) => {
setImages((prev) => prev.filter((_, i) => i !== index)); // 선택한 이미지 제거
setParams((prevParams) => ({
...prevParams,
image: prevParams.image.filter((_, i) => i !== index), // 선택한 이미지 제거
}));
};

// 이미지 업로드 버튼 클릭
Expand All @@ -151,9 +153,14 @@ const Write = () => {
symptomIds: selectedChips.symptomIds,
},
}));
console.log(params);
}, [selectedChips]);

const isAllParamsFilled =
params.category &&
params.title &&
params.content &&
params.selectedChips.breedId.length > 0;

return (
<>
<div>
Expand Down Expand Up @@ -212,7 +219,7 @@ const Write = () => {
className={plusImage}
onClick={handleFileUploadClick}
/>
{images.map((imageSrc, index) => (
{params.image.map((imageSrc, index) => (
<ImageCover
key={index}
imageSrc={imageSrc}
Expand All @@ -224,23 +231,24 @@ const Write = () => {
{/* 태그 선택 영역 */}
<WriteInputSection title={"태그 선택"}>
{TagLabel.map((tag, index) => (
<React.Fragment key={index}>
<>
<Tag
key={index}
placeholder={tag.label}
value={tag.value.length > 0 ? tag.value.join(", ") : ""}
isActive={tag.value.length > 0}
onClick={() => setOpen(true)}
/>
<Spacing marginBottom={"0.8"} />
</React.Fragment>
</>
))}
</WriteInputSection>
<Spacing marginBottom={"13.5"} />
</div>
{/* 바닥 버튼 영역 */}
<div className={bottomButton}>
<Button
variant={"solidNeutral"}
variant={isAllParamsFilled ? "solidPrimary" : "solidNeutral"}
label={"글 작성 마치기"}
size={"large"}
/>
Expand Down
Empty file.

0 comments on commit 0c0b1ac

Please sign in to comment.