Skip to content

Commit

Permalink
[fix] #68, #43 댓글 데이터 수정, 마이페이지 수정, 탈퇴 구현 중
Browse files Browse the repository at this point in the history
[fix] #68, #43 댓글 데이터 수정, 마이페이지 수정, 탈퇴 구현 중
  • Loading branch information
kr-nius authored Dec 4, 2023
2 parents 4de06ef + 2af6419 commit 75f1e4b
Show file tree
Hide file tree
Showing 29 changed files with 1,663 additions and 636 deletions.
397 changes: 206 additions & 191 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/images/back.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 28 additions & 3 deletions src/app/detail/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import Cookies from "js-cookie";
import axios from "axios";
import { useRecoilState } from "recoil";
import { editBoardIdState } from "@/recoilAtom/EditDetail";
import { WeatherIcons } from "@/recoilAtom/WeatherIcon";
import { TemNowControl } from "@/recoilAtom/TemNow";
import { categories } from "@/component/category";
import Image from "next/image";

Expand Down Expand Up @@ -49,14 +51,17 @@ async function urlToFile(url: any, filename: any) {
let mimeType = "";
switch (extension) {
case "jpg":
mimeType = "image/jpg";
break;
case "jpeg":
mimeType = "image/jpeg";
break;
case "png":
mimeType = "image/png";
break;
default:
mimeType = "application/octet-stream"; // Fallback option
// mimeType = "application/octet-stream"; // Fallback option
mimeType = "image/*"; // Fallback option
}

return new File([blob], filename, { type: mimeType });
Expand All @@ -67,9 +72,14 @@ async function urlToFile(url: any, filename: any) {
}

export default function EditDetail(): JSX.Element {
//openweathermap에서 제공하는 icon과 현재 온도
const [icon, setIcon] = useRecoilState(WeatherIcons);
const [usetemp, setTemp] = useRecoilState(TemNowControl);

const [editBoardId, setEditBoardId] = useRecoilState(editBoardIdState);
const [selectedImages, setSelectedImages] = useState<File[]>([]);
const [initialImages, setInitialImages] = useState<Image[]>([]);
const [deleteImageUrls, setDeleteImageUrls] = useState<string[]>([]);
const [content, setContent] = useState<string>("");
const [hashtags, setHashtags] = useState<string[]>([]);
const [selectedCategories, setSelectedCategories] = useState<
Expand All @@ -95,7 +105,7 @@ export default function EditDetail(): JSX.Element {

const initialImages = data.images.map((image: any) => ({
imageId: image.imageId,
imageUrl: image.image_url,
imageUrl: image.imageUrl,
}));
setInitialImages(initialImages);

Expand All @@ -108,6 +118,10 @@ export default function EditDetail(): JSX.Element {
setSelectedImages(files ? Array.from(files) : []);
}, []);

const handleDeleteImage = (imageUrl: string) => {
setDeleteImageUrls((prevUrls) => [...prevUrls, imageUrl]);
};

const handleContent = (text: string) => {
setContent(text);
};
Expand All @@ -133,6 +147,8 @@ export default function EditDetail(): JSX.Element {
)
).filter(Boolean);

console.log(existingImagesAsFiles);

const allImages = [...existingImagesAsFiles, ...selectedImages];

const allSelectedSubCategories = Object.values(selectedCategories).reduce(
Expand All @@ -145,13 +161,21 @@ export default function EditDetail(): JSX.Element {
hashTag: hashtags,
category: allSelectedSubCategories,
content: content,
temperature: usetemp,
weatherIcon: `https://openweathermap.org/img/wn/${icon}.png`,
};

formData.append("board", JSON.stringify(boardData));
allImages.forEach((image) => {
formData.append("images", image);
});

// deleteImageUrls.forEach((imageUrl) => {
// formData.append("deletedImages", imageUrl);
// });

formData.append("deletedImages", JSON.stringify(deleteImageUrls));

const response = await axios({
method: "PATCH",
url: `https://www.jerneithe.site/board/edit/${editBoardId}`,
Expand All @@ -164,7 +188,7 @@ export default function EditDetail(): JSX.Element {

console.log(response.data); // 서버 응답 확인
alert("게시물 수정 완료!");
window.location.href = "/feed";
window.location.href = "/detail";
} catch (error) {
if (axios.isAxiosError(error) && error.response) {
console.error(error.response.data);
Expand Down Expand Up @@ -204,6 +228,7 @@ export default function EditDetail(): JSX.Element {
<ImageUpload
onImagesSelected={handleImagesSelected}
initialImages={initialImages}
onDeleteImage={handleDeleteImage}
/>
<br />
<TextArea
Expand Down
Loading

0 comments on commit 75f1e4b

Please sign in to comment.