Skip to content

Commit

Permalink
feat(#5):캘린더
Browse files Browse the repository at this point in the history
  • Loading branch information
EunSeok-222 committed Nov 5, 2024
1 parent dc8d420 commit 7929fa5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 66 deletions.
2 changes: 2 additions & 0 deletions src/pages/CommunityPage/CommunityList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ const ListImg = styled.img`
background-image: url(${props => props.src}); /* 이미지 URL 설정 */
background-size: cover; /* 이미지를 채우도록 설정 */
background-position: center; /* 이미지 중앙 정렬 */
cursor: pointer;
`;
const ListTitlesContainer = styled.div`
display: flex;
Expand Down Expand Up @@ -266,6 +267,7 @@ const Icons = styled.div`
`;
const FcLike1 = styled(FcLike)`
font-size: 16px;
cursor: pointer;
`;
const Hr = styled.div`
width: 100%;
Expand Down
10 changes: 3 additions & 7 deletions src/pages/CommunityPage/CommunityWrite.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const CommunityWrite = () => {

// FormData 객체 생성
const formData = new FormData();
// const createdAt = new Date().toISOString();
// formData.append('createdAt', createdAt); // 현재 시간 추가
const user = localStorage.getItem('userId');
formData.append('title', title);
formData.append('contents', contents);
formData.append('user', user);
Expand Down Expand Up @@ -79,11 +78,6 @@ const CommunityWrite = () => {
<ItemTitle>
<Form onSubmit={handleSubmit}>
<div>
<label htmlFor="user">
유저 : <br />
<input id="user" value={user} type="number" onChange={e => setUser(e.target.value)} required />
</label>
<br />
<LableImg htmlFor="imageUrl">
<input type="file" style={{ display: 'none' }} onChange={handleFileChange} accept="image/*" id="imageUrl" />
{uploadedImage ? (
Expand Down Expand Up @@ -204,6 +198,7 @@ const CategoryBtn = styled.div`
align-items: center;
opacity: ${({ $active }) => ($active ? '1' : '0.5')};
transition: opacity 0.3s;
cursor: pointer;
&:hover {
opacity: 1;
}
Expand Down Expand Up @@ -282,6 +277,7 @@ const LableImg = styled.label`
position: relative;
display: flex;
width: 65px;
cursor: pointer;
`;
const Form = styled.form`
height: 100vh;
Expand Down
22 changes: 10 additions & 12 deletions src/pages/HealthCare/HealthCare.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@ const HealthCare = () => {
});
const [memo, setMemo] = useState("");

// useEffect(()=>{

// axios.get(`/healths`)
// .then((response) => {
// setAppointments(response.data.map(item => ({ ...item, date: new Date(item.date) })));
// console.log('댓글 목록 :', response.data);
// })
// .catch((error) => {
// console.error("Error fetching data:", error);
// });
// },[]);

const handleDateChange = (date) => {
setSelectedDate(date);
};
Expand Down Expand Up @@ -113,6 +101,16 @@ const HealthCare = () => {
}
};

// useEffect(()=>{
// axios.get(`/healths`)
// .then((response) => {
// setAppointments(response.data.map(item => ({ ...item, date: new Date(item.date) })));
// console.log('댓글 목록 :', response.data);
// })
// .catch((error) => {
// console.error("Error fetching data:", error);
// });
// },[]);
return (
<Container>
<Legend>
Expand Down
44 changes: 15 additions & 29 deletions src/pages/NanumPage/NanumDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,7 @@ const PetItemDetailPage = () => {
const [itemDetail, setItemDetail] = useState([]);
const [comments, setComments] = useState([]);

// useEffect(() => {
// const fetchUserData = async () => {
// const userId = localStorage.getItem('userId');
// if (!userId) {
// console.error('User ID not found in local storage');
// return;
// }
// );

useEffect(() => {
// 상세정보 불러오기

axios
.get(`/petItems/${no}`)
.then(response => {
Expand All @@ -35,22 +24,22 @@ const PetItemDetailPage = () => {
}, [no]);

useEffect(() => {
axios
.get(`/petItemComments`)
.then(response => {
const fetchComments = async () => {
try {
const response = await axios.get(`/petItemComments`);
setComments(response.data);
console.log('댓글 목록 :', response.data);
})
.catch(error => {
console.error('Error fetching data:', error);
});
} catch (error) {
console.error('Error :', error);
}
};

fetchComments();
}, []);

// 좋아요 수 증가 함수
const good = () => {
const updatedGood = itemDetail.good + 1;

// 서버의 좋아요 수 업데이트 요청
axios
.put(`/petItems/${no}`, { ...itemDetail, good: updatedGood })
.then(response => {
Expand All @@ -63,13 +52,12 @@ const PetItemDetailPage = () => {
};
//댓글 등록
const handleSubmit = e => {
e.preventDefault(); // 새로고침 방지
e.preventDefault();
const formData = new FormData(e.target);
const data = Object.fromEntries(formData.entries()); //객체로 변환
// const now = new Date().toISOString();
// data.createdAt = now; // 현재 시간 추가
const user = localStorage.getItem('userId');
const data = Object.fromEntries(formData.entries());
data.petItem = no;
//글 등록
data.user = user;
axios
.post('/petItemComments', data)
.then(response => {
Expand All @@ -79,7 +67,7 @@ const PetItemDetailPage = () => {
})
.catch(error => console.error('오류 발생:', error));

e.target.reset(); // 입력값 초기화
e.target.reset();
};

return (
Expand Down Expand Up @@ -118,7 +106,7 @@ const PetItemDetailPage = () => {
<div key={item.petItemCommentId}>
<User2>
<VscAccount1 />
작성자: {item.length > 0 && item[0].user}
작성자: {item.user}
<ListDate key={item.petItemCommentId}>
{new Date(item.createdAt).toLocaleDateString('ko-KR', {
timeZone: 'Asia/Seoul',
Expand All @@ -130,9 +118,7 @@ const PetItemDetailPage = () => {
))}
</CommentST>
</ItemTitle>

<CommentFrom onSubmit={handleSubmit}>
<input type="number" name="user" placeholder="유저번호" required />
<CommentCC type="text" name="comment" placeholder="댓글을 달아주세요." required />
<CommentSubmit type="submit">등록</CommentSubmit>
</CommentFrom>
Expand Down
21 changes: 3 additions & 18 deletions src/pages/NanumPage/NanumWrite.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,12 @@ const PetItemPage = () => {
const [sharing, setSharing] = useState(''); // 나눔 . 판매 여부
const [loading, setLoading] = useState(false);



useEffect(() => {
const fetchUserData = async () => {
const userId = localStorage.getItem('userId');

if (!userId) {

console.error('User ID not found in local storage');
return;
}
}
});
const handleSubmit = async e => {
const user = localStorage.getItem('userId');
e.preventDefault(); // 새로고침 방지
setLoading(true);

// FormData 객체 생성
const formData = new FormData();
// const createdAt = new Date().toISOString();
// formData.append('createdAt', createdAt); // 현재 시간 추가
formData.append('name', name);
formData.append('description', description);
formData.append('price', price);
Expand All @@ -45,7 +30,6 @@ const PetItemPage = () => {
if (imageUrl) {
formData.append('imageUrl', imageUrl);
}

try {
const response = await axios.post('/petItems', formData, {
headers: {
Expand Down Expand Up @@ -74,7 +58,8 @@ const PetItemPage = () => {
} finally {
setLoading(false);
}
};
}
// }, []);
// 파일 선택 핸들러
const handleFileChange = e => {
if (e.target.files && e.target.files[0]) {
Expand Down

0 comments on commit 7929fa5

Please sign in to comment.