Skip to content

Commit

Permalink
Merge pull request #162 from LikeLion-at-DGU/dev
Browse files Browse the repository at this point in the history
🚀 Deploy
  • Loading branch information
sayyyho authored Aug 2, 2024
2 parents bd72323 + 7bd2c9c commit ea3c377
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 29 deletions.
13 changes: 0 additions & 13 deletions src/apis/Theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,3 @@ export const getThemeContent = async (theme_id) => {
throw err;
}
};

export const postRoutineRegister = async (start_date, end_date) => {
try {
const res = await instance.post(`/api/add_routine/${id}`, {
start_date: start_date,
end_date: end_date,
});
return res;
} catch (err) {
console.log(err);
throw err;
}
};
15 changes: 15 additions & 0 deletions src/apis/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { instance } from "./instance";

export const postRoutineRegister = async (start_date, end_date, id) => {
try {
const res = await instance.post(`/api/add_routine/${id}/`, {
start_date,
end_date,
id,
});
return res;
} catch (err) {
console.log(err);
throw err;
}
};
20 changes: 16 additions & 4 deletions src/components/DateRangeCalendar/DateRangeCalendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import {
routineEnd,
CalendarVisible,
CheckVisible,
registerID,
} from "../../stores/routineRegister";
import { useRecoilState } from "recoil";
import { postRoutineRegister } from "../../apis/Theme";
import { useRecoilState, useRecoilValue } from "recoil";
import { postRoutineRegister } from "../../apis/register";

const DateRangeCalendar = () => {
const [currentDate, setCurrentDate] = useState(new Date());
Expand All @@ -16,7 +17,7 @@ const DateRangeCalendar = () => {
const [selectedEndDate, setSelectedEndDate] = useRecoilState(routineEnd);
const [, setIsCalendarVisible] = useRecoilState(CalendarVisible);
const [, setIsCheckVisible] = useRecoilState(CheckVisible);

const id = useRecoilValue(registerID);
//루틴 목표날짜 startdate,enddate에 넣기
const handleDateClick = (date) => {
if (!selectedStartDate || (selectedStartDate && selectedEndDate)) {
Expand Down Expand Up @@ -100,10 +101,21 @@ const DateRangeCalendar = () => {
try {
const response = await postRoutineRegister(
formattedStartDate,
formattedEndDate
formattedEndDate,
id
// 안되면 전역상태로 id관리 하기
);

console.log(response);
if (response.status == 200 || response.status == 201) {
// 예시: 서버 응답이 성공적인 경우
setSelectedStartDate(formattedStartDate);
setSelectedEndDate(formattedEndDate);
setIsCalendarVisible(false);
setIsCheckVisible(true);
} else {
console.error("Failed to register routine:", response.message);
}
} catch (error) {
console.error(error);
}
Expand Down
18 changes: 10 additions & 8 deletions src/pages/RandomDice/RandomDice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const RandomDice = () => {
});
useEffect(() => {
const handleResize = () => {
console.log(window.innerWidth);
if (window.innerWidth > 768) {
setContainerStyle({
justifyContent: "center",
Expand Down Expand Up @@ -57,11 +56,14 @@ export const RandomDice = () => {
// 3초 후에 이미지 결정
setTimeout(async () => {
clearInterval(interval);
const res = getRandomRoutine();
const randomImage = res.image;
setData(res);
setCurrentImage(randomImage);
// setBackgroundColor("#78A1B5");
try {
const res = await getRandomRoutine();
const randomImage = res.image;
setCurrentImage(randomImage);
setData(res);
} catch (err) {
throw err;
}
setRolling(false);
setShowContent(true);
}, 3000);
Expand Down Expand Up @@ -110,8 +112,8 @@ export const RandomDice = () => {
</div>
) : (
<div className="content">
<div className="title">{res.title}</div>
<div className="description">{res.content}</div>
<div className="title">{data.title}</div>
<div className="description">{data.content}</div>
</div>
)}
{!showContent ? (
Expand Down
10 changes: 6 additions & 4 deletions src/pages/ThemePage/ThemePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import MainRoutineBox from "../../components/mainRoutineBox/MainRoutineBox";
import Modal from "../../components/Modal/Modal";
import DateRangeCalendar from "../../components/DateRangeCalendar/DateRangeCalendar";
import { CheckUp } from "../../components/CheckUp/CheckUp";
import { useRecoilValue } from "recoil";
import { useRecoilState } from "recoil";
import { useRecoilValue, useRecoilState, useSetRecoilState } from "recoil";

import {
routineStart,
routineEnd,
CalendarVisible,
CheckVisible,
registerID,
} from "../../stores/routineRegister";

const ThemePage = () => {
Expand All @@ -23,15 +23,17 @@ const ThemePage = () => {
const [isCalendarVisible, setIsCalendarVisible] =
useRecoilState(CalendarVisible);
const [isCheckVisible, setIsCheckVisible] = useRecoilState(CheckVisible);
const setID = useSetRecoilState(registerID);
const { theme } = useMoveonTheme();

console.log("theme:", theme);
const themeData = theme && theme.data ? theme.data : null;
console.log("themeData:", themeData);
const [term, setTerm] = useState(0);

const handlePlusButtonClick = () => {
const handlePlusButtonClick = (routineId) => {
setIsCalendarVisible(true);
setID(routineId);
};

const handleCloseModal = () => {
Expand Down Expand Up @@ -83,7 +85,7 @@ const ThemePage = () => {
title={item.title}
subtitle={item.sub_title}
content={item.content}
onPlusButtonClick={handlePlusButtonClick}
onPlusButtonClick={() => handlePlusButtonClick(item.id)}
/>
))
) : (
Expand Down
5 changes: 5 additions & 0 deletions src/stores/routineRegister.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ export const CheckVisible = atom({
key: "CheckVisible",
default: false,
});

export const registerID = atom({
key: "registerID",
default: null,
});

0 comments on commit ea3c377

Please sign in to comment.