Skip to content

Commit

Permalink
Merge pull request #109 from kdt-8-4/56-detail
Browse files Browse the repository at this point in the history
[Fix] #56 페이지 이동 및 editBoardId 수정
  • Loading branch information
hyeiis authored Dec 2, 2023
2 parents 9912974 + 732ea91 commit 8f21362
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/app/detail/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,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
19 changes: 7 additions & 12 deletions src/app/detail/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import CategoryDetail from "@/component/CategoryDetail";
import { useRouter } from "next/navigation";
import { editBoardIdState } from "@/recoilAtom/EditDetail";



export default function Detail(): JSX.Element {
const [boardDetail, setBoardDetail] = useState<any>(null);
const [dropdownVisible, setDropdownVisible] = useState<boolean>(false);
Expand All @@ -38,42 +36,39 @@ export default function Detail(): JSX.Element {
console.log("디코딩", decodedToken);

useEffect(() => {

//여기서 localStorae의 값을 가져와 정수로 바꾸기
const boardId_in = localStorage.getItem("getBoardId_local");
const boardIdNumber = boardId_in ? parseInt(boardId_in) : null;
setLocalBoardId(boardIdNumber);

console.log("정수 변환", boardIdNumber);
console.log("로컬에서 불러온 아이읻", localBoardId);



}, []);

useEffect(()=>{
useEffect(() => {
const fetchData = async () => {
try {
const response = await axios.get(
`https://www.jerneithe.site/board/detail/${localBoardId}`,
// `https://www.jerneithe.site/board/detail/3`,
);
setBoardDetail(response.data);
console.log(response);

} catch (error) {
console.error("Error fetching data:", error);
}
};
};

fetchData();
},[localBoardId, setLocalBoardId])
}, [localBoardId, setLocalBoardId]);

const toggleDropdown = () => {
setDropdownVisible(!dropdownVisible);
};

const handleEdit = () => {
setEditBoardId(boardDetail.boardId);
// setEditBoardId(boardDetail.boardId);
setEditBoardId(localBoardId);
router.push(`/detail/edit`);
};

Expand Down
9 changes: 8 additions & 1 deletion src/component/ImageUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ const ImageUpload: React.FC<ImageUploadProps> = ({
setExistingImages(initialImages);
}, [initialImages]);

useEffect(() => {
console.log("selectedImages", selectedImages);
}, [selectedImages]);

useEffect(() => {
console.log("existingImages", existingImages);
}, [existingImages]);

const handleImageChange = (event: ChangeEvent<HTMLInputElement>) => {
const files: FileList | null = event.target.files;
if (files) {
Expand Down Expand Up @@ -52,7 +60,6 @@ const ImageUpload: React.FC<ImageUploadProps> = ({
const removeExistingImage = (index: number) => {
if (existingImages) {
const newImages = [...existingImages];
const imageId = existingImages[index].imageId;
newImages.splice(index, 1);
setExistingImages(newImages);
}
Expand Down

0 comments on commit 8f21362

Please sign in to comment.