Skip to content

Commit a032b92

Browse files
authored
Merge pull request #2 from WoongyuChoi/dev
Dev
2 parents 8286683 + 346a2e6 commit a032b92

File tree

9 files changed

+88
-43
lines changed

9 files changed

+88
-43
lines changed

package-lock.json

Lines changed: 34 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"react-chartjs-2": "^5.2.0",
1919
"react-dom": "^18.3.1",
2020
"react-lottie-player": "^2.1.0",
21-
"react-router-dom": "^6.27.0"
21+
"react-router-dom": "^6.27.0",
22+
"zustand": "^5.0.1"
2223
},
2324
"devDependencies": {
2425
"@eslint/js": "^9.11.1",

src/App.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ function App() {
1111
const [queryClient] = useState(() => new QueryClient());
1212
return (
1313
<QueryClientProvider client={queryClient}>
14-
<UsePlayingProvider>
15-
<ChartProvider>
16-
<BrowserRouter>
17-
<SpeedInsights />
18-
<Routes>
19-
<Route path="/" element={<Home />} />
20-
</Routes>
21-
</BrowserRouter>
22-
</ChartProvider>
23-
</UsePlayingProvider>
14+
{/* <UsePlayingProvider> */}
15+
<ChartProvider>
16+
<BrowserRouter>
17+
<SpeedInsights />
18+
<Routes>
19+
<Route path="/" element={<Home />} />
20+
</Routes>
21+
</BrowserRouter>
22+
</ChartProvider>
23+
{/* </UsePlayingProvider> */}
2424
</QueryClientProvider>
2525
);
2626
}

src/common/Loading.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { useEffect, useState } from "react";
22
import Lottie from "react-lottie-player";
33
import LoadingLottie from "../assets/lottie/loading.json";
44
import { usePlaying } from "../hook/usePlayingContext";
5+
import usePlayingStore from "../store/playing";
56

67
export default function Loading() {
78
const [mounted, setMounted] = useState(false);
8-
const { isPlaying, toggleIsPlaying } = usePlaying();
9+
// const { isPlaying, toggleIsPlaying } = usePlaying();
10+
const { isPlaying, toggleIsPlaying } = usePlayingStore();
911

1012
useEffect(() => setMounted(true), []);
1113

src/data/SelectedConstant.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export enum SelectedTitle {
2-
BAR_CHART_1 = 1,
3-
BAR_CHART_2 = 2,
4-
WATERFALL_CHART = 3,
5-
MIXED_CHART = 4,
6-
AREA_CHART = 5,
2+
BAR_CHART_1 = "BAR_CHART_1",
3+
BAR_CHART_2 = "BAR_CHART_2",
4+
WATERFALL_CHART = "WATERFALL_CHART",
5+
MIXED_CHART = "MIXED_CHART",
6+
AREA_CHART = "AREA_CHART",
77
}

src/hook/useDynamicData.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useQuery } from "@tanstack/react-query";
22
import { useEffect, useRef, useState } from "react";
33
import { usePlaying } from "./usePlayingContext";
4+
import usePlayingStore from "../store/playing";
45

56
const useDynamicData = (
67
initialData: any,
@@ -10,7 +11,8 @@ const useDynamicData = (
1011
const containerRef = useRef<HTMLDivElement>(null);
1112
const [isVisible, setIsVisible] = useState(false);
1213
const [firstLoad, setFirstLoad] = useState(true);
13-
const { isPlaying } = usePlaying();
14+
// const { isPlaying } = usePlaying();
15+
const { isPlaying } = usePlayingStore();
1416

1517
const { data: data, refetch } = useQuery({
1618
queryKey: [queryKey],

src/layout/ButtonLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import "../Button.css";
33
import { SelectedTitle } from "../data/SelectedConstant";
44

55
interface ButtonLayoutProps {
6-
setSelectedChart: (chart: number) => void;
6+
setSelectedChart: (chart: SelectedTitle) => void;
77
}
88

99
const ButtonLayout = ({ setSelectedChart }: ButtonLayoutProps) => {

src/layout/ChartLayout.tsx

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { Chart } from "chart.js";
2-
import { useEffect, useRef } from "react";
3-
import AreaChart from "../chart/AreaChart";
4-
import BarChartComparison from "../chart/BarChartComparison";
5-
import BarChartNegative from "../chart/BarChartNegative";
6-
import MixedChart from "../chart/MixedChart";
7-
import WaterfallChart from "../chart/WaterfallChart";
2+
import React, { Suspense, useEffect, useRef } from "react";
83
import { SelectedTitle } from "../data/SelectedConstant";
94

105
const ChartLayout = ({
@@ -24,20 +19,20 @@ const ChartLayout = ({
2419
};
2520
}, []);
2621

22+
const chartMap = {
23+
BAR_CHART_1: React.lazy(() => import("../chart/BarChartComparison")),
24+
BAR_CHART_2: React.lazy(() => import("../chart/BarChartNegative")),
25+
WATERFALL_CHART: React.lazy(() => import("../chart/WaterfallChart")),
26+
MIXED_CHART: React.lazy(() => import("../chart/MixedChart")),
27+
AREA_CHART: React.lazy(() => import("../chart/AreaChart")),
28+
};
29+
2730
const renderChart = () => {
28-
switch (selectedChart) {
29-
case SelectedTitle.BAR_CHART_1:
30-
return <BarChartComparison chartRef={chartRef} />;
31-
case SelectedTitle.BAR_CHART_2:
32-
return <BarChartNegative chartRef={chartRef} />;
33-
case SelectedTitle.WATERFALL_CHART:
34-
return <WaterfallChart chartRef={chartRef} />;
35-
case SelectedTitle.MIXED_CHART:
36-
return <MixedChart chartRef={chartRef} />;
37-
case SelectedTitle.AREA_CHART:
38-
return <AreaChart chartRef={chartRef} />;
39-
default:
40-
return <div>Please select a chart.</div>;
31+
if (selectedChart) {
32+
const Chart = chartMap[selectedChart];
33+
return <Chart chartRef={chartRef} />;
34+
} else {
35+
return <div>Please select a chart.</div>;
4136
}
4237
};
4338

@@ -51,7 +46,9 @@ const ChartLayout = ({
5146
boxShadow: "0px 4px 12px rgba(0, 0, 0, 0.15)",
5247
}}
5348
>
54-
<>{renderChart()}</>
49+
<Suspense fallback={<div>Loading...</div>}>
50+
<>{renderChart()}</>
51+
</Suspense>
5552
</div>
5653
);
5754
};

src/store/playing.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { create } from "zustand";
2+
3+
interface PlayingState {
4+
isPlaying: boolean;
5+
toggleIsPlaying: () => void;
6+
}
7+
8+
const usePlayingStore = create<PlayingState>((set) => ({
9+
isPlaying: true,
10+
toggleIsPlaying: () => set((state) => ({ isPlaying: !state.isPlaying })),
11+
}));
12+
13+
export default usePlayingStore;

0 commit comments

Comments
 (0)