forked from githru/githru-vscode-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
111 lines (101 loc) · 3.46 KB
/
Copy pathApp.tsx
File metadata and controls
111 lines (101 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import "reflect-metadata";
import { useEffect, useMemo, useRef } from "react";
import BounceLoader from "react-spinners/BounceLoader";
import { ThemeProvider } from "@mui/material";
import MonoLogo from "assets/monoLogo.svg";
import { BranchSelector, Statistics, TemporalFilter, ThemeSelector, VerticalClusterList } from "components";
import "./App.scss";
import { useAnalayzedData } from "hooks";
import { RefreshButton } from "components/RefreshButton";
import type { IDESentEvents } from "types/IDESentEvents";
import { useBranchStore, useDataStore, useGithubInfo, useLoadingStore, useThemeStore } from "store";
import { THEME_INFO } from "components/ThemeSelector/ThemeSelector.const";
import { initializeIDEConnection, sendFetchAnalyzedDataCommand } from "services";
import { COMMIT_COUNT_PER_PAGE } from "constants/constants";
import { createMuiTheme } from "theme";
const App = () => {
const initRef = useRef<boolean>(false);
const { handleChangeAnalyzedData } = useAnalayzedData();
const { filteredData, nextCommitId, isLastPage } = useDataStore((state) => ({
filteredData: state.filteredData,
nextCommitId: state.nextCommitId,
isLastPage: state.isLastPage,
}));
const { handleChangeBranchList } = useBranchStore();
const { handleGithubInfo } = useGithubInfo();
const { loading, setLoading } = useLoadingStore();
const { theme } = useThemeStore();
const muiTheme = useMemo(() => createMuiTheme(theme), [theme]);
useEffect(() => {
if (initRef.current === false) {
const callbacks: IDESentEvents = {
handleChangeAnalyzedData: (payload) => handleChangeAnalyzedData(payload),
handleChangeBranchList,
handleGithubInfo,
};
setLoading(true);
initializeIDEConnection(callbacks);
initRef.current = true;
}
}, [handleChangeAnalyzedData, handleChangeBranchList, handleGithubInfo, setLoading]);
const handleLoadMore = () => {
if (loading || isLastPage) return;
setLoading(true);
sendFetchAnalyzedDataCommand({
commitCountPerPage: COMMIT_COUNT_PER_PAGE,
lastCommitId: nextCommitId,
});
};
if (loading) {
return (
<BounceLoader
color={THEME_INFO[theme as keyof typeof THEME_INFO].colors.primary}
loading={loading}
cssOverride={{
position: "fixed",
left: "50%",
top: "50%",
transform: "translate(-50%, 0)",
}}
/>
);
}
return (
<ThemeProvider theme={muiTheme}>
<div className="header-container">
<ThemeSelector />
<BranchSelector />
<RefreshButton />
</div>
<div className="top-container">
<TemporalFilter />
</div>
<div>
{filteredData.length !== 0 ? (
<>
<div className="middle-container">
<VerticalClusterList />
<Statistics />
</div>
<div className="load-more-container">
<button
className="load-more-button"
onClick={handleLoadMore}
disabled={isLastPage || loading}
>
{loading ? "Loading..." : isLastPage ? "No More Commits" : "Load More"}
</button>
</div>
</>
) : (
<div className="no-commits-container">
<MonoLogo />
<h1>No Commits Found.</h1>
<p>Make at least one commit to proceed.</p>
</div>
)}
</div>
</ThemeProvider>
);
};
export default App;