mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
add info toast for new dev version available
This commit is contained in:
+1
-1
@@ -50,7 +50,7 @@
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=false react-scripts build",
|
||||
"build-netlify": "cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=true REACT_APP_COMMIT_REF=$COMMIT_REF react-scripts build",
|
||||
"build-netlify": "echo $COMMIT_REF > ./public/latest_commit.txt && cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=true REACT_APP_COMMIT_REF=$COMMIT_REF react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"analyze-bundle": "cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=true react-scripts build && source-map-explorer 'build/static/js/*.js'",
|
||||
"electron": "yarn electron:before && electron .",
|
||||
|
||||
+15
-4
@@ -25,6 +25,7 @@ import useError from "./hooks/useError";
|
||||
import useInfo from "./hooks/useInfo";
|
||||
import useSuccess from "./hooks/useSuccess";
|
||||
import packageJson from '../package.json';
|
||||
const commitRef = process?.env?.REACT_APP_COMMIT_REF || '';
|
||||
|
||||
export default function App() {
|
||||
const {
|
||||
@@ -70,20 +71,30 @@ export default function App() {
|
||||
try {
|
||||
const packageRes = await fetch('https://raw.githubusercontent.com/plebbit/plebchan/master/package.json', { cache: 'no-cache' });
|
||||
const packageData = await packageRes.json();
|
||||
|
||||
|
||||
if (packageJson.version !== packageData.version) {
|
||||
const newVersionInfo = `New version available, plebchan v${packageData.version}. Refresh the page to update.`;
|
||||
localStorage.setItem('infoToast', newVersionInfo);;
|
||||
localStorage.setItem('infoToast', newVersionInfo);
|
||||
}
|
||||
|
||||
// Check for commit hash if commitRef is defined
|
||||
if (commitRef.length > 0) {
|
||||
const commitRes = await fetch('https://raw.githubusercontent.com/plebbit/plebchan/development/public/latest_commit.txt', { cache: 'no-cache' });
|
||||
const latestCommit = await commitRes.text();
|
||||
|
||||
if (latestCommit.trim() !== commitRef.trim()) {
|
||||
const newVersionInfo = `New dev version available, commit ${latestCommit}. Refresh the page to update.`;
|
||||
localStorage.setItem('infoToast', newVersionInfo);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch latest version info:', error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
fetchVersionInfo();
|
||||
}, [setNewInfoMessage]);
|
||||
|
||||
|
||||
|
||||
// preload banners
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user