From b2310ba9d14c081ad8b480c4113718dd4bf87a0a Mon Sep 17 00:00:00 2001 From: dandamdandam Date: Sun, 18 Aug 2024 00:12:46 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= =?UTF-8?q?=EC=9D=84=20=EC=99=9C...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/log/Score.tsx | 32 ++++++++++++++++++++++++++++ src/app/log/page.tsx | 40 +++++++++-------------------------- src/app/mypage/page.tsx | 2 +- src/lib/hooks/useLogStatus.ts | 15 +++++++++++++ 4 files changed, 58 insertions(+), 31 deletions(-) create mode 100644 src/app/log/Score.tsx create mode 100644 src/lib/hooks/useLogStatus.ts diff --git a/src/app/log/Score.tsx b/src/app/log/Score.tsx new file mode 100644 index 0000000..e26ea4e --- /dev/null +++ b/src/app/log/Score.tsx @@ -0,0 +1,32 @@ +import { useState } from "react"; +import styles from "./page.module.scss"; +import { usePersonalGoals } from "@/lib/firebase/api/personalGoalAPI"; + +export default function Score() { + const [score, setScore] = useState(100); + const { data, isLoading, isError } = usePersonalGoals(); + + // ///// + // try { + // const response_score = await axios.post( + // 'https://castberry.kr:3650/api/open', { + // "goal": {}, + // "status": {}, + // } + // ); + // setScore(JSON.parse(response_score.data).score); + // } catch (error) { + // console.error(error); + // } + ///// + + return ( +
+
+
오늘의 점수
+
오늘도 열심히 활동했어요!
+
+
{score}점
+
+ ); +} diff --git a/src/app/log/page.tsx b/src/app/log/page.tsx index 0d306f4..5087324 100644 --- a/src/app/log/page.tsx +++ b/src/app/log/page.tsx @@ -1,15 +1,14 @@ -"use client" +"use client"; import DietLog from "./DietLog"; import SleepLog from "./SleepLog"; import WorkoutLog from "./WorkoutLog"; -import styles from './page.module.scss' +import styles from "./page.module.scss"; import Header from "../_common/header"; import NavBar from "../_common/navBar"; -import { useState } from "react"; -import axios from "axios"; +import Score from "./Score"; export function logInput() { console.log("log input select"); @@ -18,37 +17,18 @@ export function logInput() { 완료 - ) + ); } -export default async function LogPage() { - const [ score, setScore ] = useState(100); - - // ///// - // try { - // const response_score = await axios.post( - // 'https://castberry.kr:3650/api/open', { - // "goal": {}, - // "status": {}, - // } - // ); - // setScore(JSON.parse(response_score.data).score); - // } catch (error) { - // console.error(error); - // } - - ///// +export default function LogPage() { return (
-
-
-
-
오늘의 점수
-
오늘도 열심히 활동했어요!
-
-
{score}점
-
+
+ diff --git a/src/app/mypage/page.tsx b/src/app/mypage/page.tsx index 84512e5..2c5ba94 100644 --- a/src/app/mypage/page.tsx +++ b/src/app/mypage/page.tsx @@ -21,7 +21,7 @@ export default function MyPage() { ? "목표를 설정해주세요" : data.diet?.calories}
- 식단 목표 설정하기 + 목표 설정하기
); diff --git a/src/lib/hooks/useLogStatus.ts b/src/lib/hooks/useLogStatus.ts new file mode 100644 index 0000000..c9f2aed --- /dev/null +++ b/src/lib/hooks/useLogStatus.ts @@ -0,0 +1,15 @@ +import { useMemo } from "react"; +import { useDietOfDay } from "../firebase/api/dietAPI" +import { useWorkoutOfDay } from "../firebase/api/workoutAPI"; + +export const useLogStatus = () => { + const { data: diets, isLoading: dietIsLoading, isError: dietIsError } = useDietOfDay(new Date()); + const { data: workouts, isLoading: workoutIsLoading, isError: workoutIsError } = useWorkoutOfDay(new Date()); + const { data: sleeps, isLoading: sleepIsLoading, isError: sleepIsError } = useWorkoutOfDay(new Date()); + + const isRender = useMemo(() => { + if (dietIsLoading || workoutIsLoading || sleepIsLoading) return false; + if (dietIsError || workoutIsError || sleepIsError) return false; + return true; + }, [dietIsLoading, workoutIsLoading, sleepIsLoading, dietIsError, workoutIsError, sleepIsError]); +} \ No newline at end of file