Skip to content

Commit 6b1f10a

Browse files
committed
update UI and add version control
1 parent c1c9ca6 commit 6b1f10a

File tree

6 files changed

+226
-110
lines changed

6 files changed

+226
-110
lines changed

dist/build/static/js/bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/*! For license information please see main.6a518c98.js.LICENSE.txt */
1+
/*! For license information please see main.f36c5541.js.LICENSE.txt */

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
"xlsx-populate": "^1.21.0",
3939
"xlsx-style": "^0.8.13"
4040
},
41+
"browser":{
42+
"child_process": false
43+
},
4144
"scripts": {
4245
"start": "electron-forge start",
4346
"dev2": "react-scripts start",

src/App.js

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ function App() {
5656
const [anchorEl, setAnchorEl] = useState(null); // State to manage the settings menu
5757
const [openAboutModal, setOpenAboutModal] = useState(false); // About modal state
5858
const [openHelpModal, setOpenHelpModal] = useState(false); // Help modal state
59-
59+
const [openUpdateDialog, setOpenUpdateDialog] = useState(false);
60+
const [isShown, setIsShown] = useState(false);
6061
const classes = useStyles();
6162
const AnalysisPunchoutsFunc = (d) => d === undefined ? AnalysisPunchouts : setAnalysisPunchouts(d);
6263
const AnalysisSlabThicknessFunc = (d) => d === undefined ? AnalysisSlabThickness : setAnalysisSlabThickness(d);
@@ -66,6 +67,38 @@ function App() {
6667

6768
const handleCloseAboutModal = () => setOpenAboutModal(false);
6869
const handleCloseHelpModal = () => setOpenHelpModal(false);
70+
const handleCloseUpdateDialog = () => {setOpenUpdateDialog(false);
71+
setIsShown(true);}
72+
async function checkForUpdates() {
73+
const repo = "iDataVisualizationLab/TxDOT";
74+
const branch = "main";
75+
76+
try {
77+
// Use the GitHub API to get the latest commit
78+
const response = await fetch(`https://api.github.com/repos/${repo}/commits/${branch}`);
79+
80+
if (!response.ok) {
81+
throw new Error(`GitHub API error: ${response.statusText}`);
82+
}
83+
84+
const data = await response.json();
85+
const latestCommitHash = data.sha;
86+
87+
// Compare with the local commit hash
88+
if (process.env.LOCAL_COMMIT_HASH !== latestCommitHash) {
89+
if (!isShown) {
90+
setOpenUpdateDialog(true);
91+
} else {
92+
setOpenUpdateDialog(false);
93+
}
94+
} else {
95+
console.log("You are using the latest version.");
96+
}
97+
} catch (error) {
98+
console.error("Error checking for updates:", error);
99+
}
100+
}
101+
checkForUpdates();
69102
return (
70103
<ThemeProvider theme={theme}>
71104
<div>
@@ -95,13 +128,31 @@ function App() {
95128
open={Boolean(anchorEl)}
96129
onClose={() => setAnchorEl(null)} // Close menu
97130
>
98-
<MenuItem onClick={() => setPage('TransferFunc')}>Transfer Function</MenuItem>
131+
<MenuItem onClick={() => {setPage('TransferFunc');checkForUpdates();}}>Transfer Function</MenuItem>
99132
<MenuItem onClick={handleHelpClick}>Help</MenuItem>
100133
<MenuItem onClick={handleAboutClick}>About</MenuItem>
101134
</Menu>
102135

103136
</Toolbar>
104137
</AppBar>
138+
{/* Dialog for Update Information */}
139+
<Dialog open={openUpdateDialog} onClose={handleCloseUpdateDialog}>
140+
<DialogTitle>Update Available</DialogTitle>
141+
<DialogContent>
142+
<p>A newer version of this application is available.</p>
143+
<p>
144+
Please download the latest version from{' '}
145+
<a href="https://github.com/iDataVisualizationLab/TxDOT/releases" target="_blank" rel="noopener noreferrer">
146+
GitHub Releases
147+
</a>.
148+
</p>
149+
</DialogContent>
150+
<DialogActions>
151+
<Button onClick={handleCloseUpdateDialog} color="primary">
152+
Close
153+
</Button>
154+
</DialogActions>
155+
</Dialog>
105156
{/* About Modal */}
106157
<Dialog open={openAboutModal} onClose={handleCloseAboutModal}>
107158
<DialogTitle>About</DialogTitle>
@@ -151,7 +202,7 @@ function App() {
151202
</Grid>
152203
<Grid container item alignItems="stretch" justify="center" direction={"column"} spacing={3} style={{ width: 'fit-content' }}>
153204
<Grid item>
154-
<Button variant="contained" color="primary" style={{ width: '100%' }} onClick={() => setPage('CRCP')}>CRCP Design</Button>
205+
<Button variant="contained" color="primary" style={{ width: '100%' }} onClick={() => {setPage('CRCP');checkForUpdates();}}>CRCP Design</Button>
155206
</Grid>
156207
<Grid item>
157208
<Button variant="contained" style={{ width: '100%' }}>Slab Support</Button>
@@ -166,7 +217,7 @@ function App() {
166217
{/* CRCP Page */}
167218
<Slide direction="up" in={page === 'CRCP'} mountOnEnter unmountOnExit>
168219
<CRCP
169-
toMenu={() => setPage('home')}
220+
toMenu={() => {setPage('home');checkForUpdates();}}
170221
AnalysisPunchouts={AnalysisPunchoutsFunc}
171222
AnalysisSlabThickness={AnalysisSlabThicknessFunc}
172223
/>
@@ -176,7 +227,7 @@ function App() {
176227
<Slide direction="up" in={page === 'TransferFunc'} mountOnEnter unmountOnExit>
177228
<div>
178229
<TransferFunc
179-
toMenu={() => setPage('home')}
230+
toMenu={() => {setPage('home');checkForUpdates();}}
180231
handleHelpClick = {handleHelpClick} />
181232
</div>
182233
</Slide>

0 commit comments

Comments
 (0)