Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/#46
Browse files Browse the repository at this point in the history
  • Loading branch information
lkhoony committed Sep 14, 2024
2 parents d8143e0 + 2d57767 commit cdaf647
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 31 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
"@tanstack/react-query": "^5.51.23",
"axios": "1.7.3",
"core-js": "^3.28.0",
"dayjs": "^1.11.13",
"echarts": "^5.5.1",
"echarts-for-react": "^3.0.2",
"lucide-react": "^0.435.0",
"p5": "^1.9.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.8.1",
"react-tailwindcss-datepicker": "^1.7.2",
"socket.io-client": "^4.7.5",
"zustand": "^4.5.5"
},
Expand Down
5 changes: 3 additions & 2 deletions src/api/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export const getTodayPoseAnalysis = async (): Promise<TodayAnalysisData> => {
}
}

export const getTotalPoseAnalysis = async (): Promise<TodayAnalysisData[]> => {
export const getTotalPoseAnalysis = async (params: { fromDate?: string; toDate?: string }) => {
const queryString = new URLSearchParams(params).toString()
try {
const res = await axiosInstance.get("/pose-counts?sort=date,asc")
const res = await axiosInstance.get(`/pose-counts?${queryString ? `${queryString}` : ""}&sort=date,asc`)
return res.data.data
} catch (e) {
throw e
Expand Down
20 changes: 17 additions & 3 deletions src/hooks/useDashBoard.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import { getTodayPoseAnalysis, getTotalPoseAnalysis } from "@/api/analysis"
import { useQueries } from "@tanstack/react-query"
import dayjs from "dayjs"
import { DateValueType } from "react-tailwindcss-datepicker"

export const usePoseAnalysis = () => {
export const usePoseAnalysis = (dateRange: DateValueType) => {
const results = useQueries({
queries: [
{
queryKey: ["todayAnalysis"],
queryFn: getTodayPoseAnalysis,
},
{
queryKey: ["totalAnalysis"],
queryFn: getTotalPoseAnalysis,
queryKey: ["totalAnalysis", dateRange],
queryFn: () => {
const params: { fromDate?: string; toDate?: string } = {}

if (dateRange?.startDate) {
params.fromDate = dayjs(dateRange.startDate).format("YYYY-MM-DD")
}

if (dateRange?.endDate) {
params.toDate = dayjs(dateRange.endDate).format("YYYY-MM-DD")
}

return getTotalPoseAnalysis(params)
},
},
],
})
Expand Down
52 changes: 27 additions & 25 deletions src/pages/AnalysisDashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import { poseType } from "@/api/pose"
import { Calendar, ChevronLeft, ChevronRight } from "lucide-react"
import { useEffect, useRef, useState } from "react"
import { usePoseAnalysis } from "@/hooks/useDashBoard"
import { ChevronLeft, ChevronRight } from "lucide-react"
import { useEffect, useRef, useState } from "react"

import TotalCountChartIcon from "@/assets/icons/dash-board-total-count.svg?react"
import ChinUpImage from "@/assets/images/chin-up.png"
import ShoulderTwistImage from "@/assets/images/shoulder-twist.png"
import TailBoneSitImage from "@/assets/images/tail-bone-sit.png"
import TurtleNeckImage from "@/assets/images/tutle-neck.png"
import PoseAnalysisChart from "@/components/Dashboard/Chart"
import Datepicker, { DateValueType } from "react-tailwindcss-datepicker"

const AnalysisDashboard = () => {
const [currentIndex, setCurrentIndex] = useState(0)
const carouselRef = useRef(null)
const [currentIndex, setCurrentIndex] = useState(0)
const [dateRange, setDateRange] = useState<DateValueType>({
startDate: null,
endDate: null,
})

const { todayAnalysis, totalAnalysis, isLoading, isError } = usePoseAnalysis()
const { todayAnalysis, totalAnalysis, isLoading, isError } = usePoseAnalysis(dateRange)

console.log("totalAnalysis: ", totalAnalysis)
console.log("totalAnalysis: ", dateRange)

const getPoseCount = (type: poseType) => {
return todayAnalysis?.count.find((item: any) => item.type === type)?.count || 0
Expand Down Expand Up @@ -125,28 +130,25 @@ const AnalysisDashboard = () => {
)}
</div>
</div>
<div className="mb-12 mt-8">
<hr />
</div>
{/* 차트 섹션 */}
<div className="rounded-lg shadow">
<div className="mb-4 flex items-center justify-between">
<div className="flex items-center space-x-2">
<ChevronLeft size={20} />
<span className="rounded-full bg-zinc-800 px-4 py-2 text-white">7월 첫째주 추이</span>
<ChevronRight size={20} />
</div>
<div className="flex items-center text-sm text-gray-600">
<Calendar size={16} className="mr-2" />
{"2024-09-09"}
</div>
</div>
<div className="h-[340px] rounded-[10px] border-[1px] border-solid border-gray-200 bg-white">
{totalAnalysis && <PoseAnalysisChart data={totalAnalysis} />}
</div>
</div>
</div>
)}
<div className="mb-12 mt-8">
<hr />
</div>
{/* 차트 섹션 */}
<div className="mb-4 flex items-end justify-end">
<div className="text-sm text-gray-600">
<Datepicker
inputClassName="w-[270px] py-2 rounded-full bg-zinc-800 text-white px-[24px]"
maxDate={new Date()}
value={dateRange}
onChange={(value) => setDateRange(value)}
/>
</div>
</div>
<div className="h-[340px] rounded-[10px] border-[1px] border-solid border-gray-200 bg-white">
{totalAnalysis && <PoseAnalysisChart data={totalAnalysis} />}
</div>
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{ts,tsx,js,jsx}"],
content: ["./src/**/*.{ts,tsx,js,jsx}", "./node_modules/react-tailwindcss-datepicker/dist/index.esm.js"],
theme: {
extend: {
fontFamily: { sans: ["Pretendard"] },
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,11 @@ data-view-byte-offset@^1.0.0:
es-errors "^1.3.0"
is-data-view "^1.0.1"

dayjs@^1.11.13:
version "1.11.13"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.13.tgz#92430b0139055c3ebb60150aa13e860a4b5a366c"
integrity sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==

debug@^3.2.7:
version "3.2.7"
resolved "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz"
Expand Down Expand Up @@ -2834,6 +2839,11 @@ [email protected]:
dependencies:
"@remix-run/router" "1.19.0"

react-tailwindcss-datepicker@^1.7.2:
version "1.7.2"
resolved "https://registry.yarnpkg.com/react-tailwindcss-datepicker/-/react-tailwindcss-datepicker-1.7.2.tgz#ee2525b2a82211fc5756285265feaa459e102301"
integrity sha512-/NIRLB1evT69pt3Syol3cZpsAnLZlGvFWav98/Rr77Gey382C1fjKW2Emgu+SC4NtiRt6CBFwx/0Wbkn4iI+nA==

react@^18.2.0:
version "18.3.1"
resolved "https://registry.npmjs.org/react/-/react-18.3.1.tgz"
Expand Down

0 comments on commit cdaf647

Please sign in to comment.