-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: versioning & refresh banner (#7)
* versioning & refresh banner * add version.json to network first strategy * Change update banner style to be flex by default * update app version
- Loading branch information
1 parent
45a874d
commit 256d232
Showing
9 changed files
with
107 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"editor.tabSize": 2 | ||
"editor.tabSize": 2, | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"1.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import { clearCacheAndRefresh } from '../hooks/useVersionInfo'; | ||
|
||
export default function AppUpdateBanner() { | ||
return ( | ||
<div className="updateBanner"> | ||
The app is out of date & please click the "Refresh Now" button to have a better experience. | ||
<button onClick={clearCacheAndRefresh} className="refresh-btn"> | ||
Refresh Now | ||
</button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
export default function useVersionInfo() { | ||
const [isUpToDate, setIsUpToDate] = useState(true); | ||
|
||
useEffect(() => { | ||
if (wasUpToDate()) { | ||
fetch('/version.json') | ||
.then((versionJSON) => versionJSON.json()) | ||
.then((versionString) => { | ||
const localVersion = getLocalVersion(); | ||
if (versionString !== localVersion) { | ||
console.log('## The app is out of date & needs update!'); | ||
setIsUpToDate(false); | ||
localStorage.setItem('wasUpToDate', false); | ||
} else { | ||
localStorage.setItem('wasUpToDate', true); | ||
setIsUpToDate(true); | ||
} | ||
|
||
localStorage.setItem('version', versionString); | ||
}) | ||
.catch((err) => { | ||
console.log('App offline, assuming up to date'); | ||
}); | ||
} else { | ||
clearCacheAndRefresh(); | ||
} | ||
}, []); | ||
|
||
return { isUpToDate }; | ||
} | ||
|
||
function getLocalVersion() { | ||
return localStorage.getItem('version') || ''; | ||
} | ||
|
||
function wasUpToDate() { | ||
return localStorage.getItem('wasUpToDate') === false ? false : true; | ||
} | ||
|
||
export function clearCacheAndRefresh() { | ||
const currentVersion = getLocalVersion(); | ||
localStorage.clear(); | ||
localStorage.setItem('version', currentVersion); | ||
window.location.reload(); | ||
} |
256d232
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: