Skip to content

fix: Store dismissedBanner key in localStorage #5388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Store dismissedBanner key in localStorage
  • Loading branch information
Kira-Pilot committed Dec 12, 2022
commit 983e18f616a18c3578a7217c43dc4f2d9b04b102
1 change: 0 additions & 1 deletion site/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ rules:
message:
"Use path imports to avoid pulling in unused modules. See:
https://material-ui.com/guides/minimizing-bundle-size/"
no-storage/no-browser-storage: error
no-unused-vars: "off"
"object-curly-spacing": "off"
react-hooks/exhaustive-deps: warn
Expand Down
1 change: 0 additions & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jest": "27.0.1",
"eslint-plugin-jsx-a11y": "6.6.1",
"eslint-plugin-no-storage": "1.0.2",
"eslint-plugin-react": "7.31.1",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-unicorn": "44.0.0",
Expand Down
7 changes: 7 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,14 @@ export const getBuildInfo = async (): Promise<TypesGen.BuildInfoResponse> => {
export const getUpdateCheck =
async (): Promise<TypesGen.UpdateCheckResponse> => {
const response = await axios.get("/api/v2/updatecheck")
// return {
// current: true,
// url: "https://github.com/coder/coder/releases/tag/v0.13.1",
// version: "v0.13.1"
// }
console.log('response.data', response.data)
return response.data
return { current: false, version: 'v0.13.1', url: 'https://github.com/coder/coder/releases/tag/v0.13.1' }
}

export const putWorkspaceAutostart = async (
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/AuthAndFrame/AuthAndFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const AuthAndFrame: FC<AuthAndFrameProps> = ({ children }) => {

useEffect(() => {
if (authState.matches("signedIn")) {
updateCheckSend("CHECK")
updateCheckSend("CHECK") // this calls getUpdateCheck which returns the latest version
} else {
updateCheckSend("CLEAR")
}
Expand Down
14 changes: 10 additions & 4 deletions site/src/xServices/updateCheck/updateCheckXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const updateCheckMachine = createMachine(
dismissOrClear: {
on: {
DISMISS: {
actions: ["assignHide"],
actions: ["assignHide", "setDismissedVersion"],
target: "dismissed",
},
CLEAR: {
Expand All @@ -141,9 +141,9 @@ export const updateCheckMachine = createMachine(
assignPermissions: assign({
permissions: (_, event) => event.data as Permissions,
}),
assignShow: assign({
show: true,
}),
assignShow: assign((context) => ({
show: localStorage.getItem("dismissedVersion") !== context.updateCheck?.version,
})),
assignHide: assign({
show: false,
}),
Expand All @@ -161,6 +161,12 @@ export const updateCheckMachine = createMachine(
...context,
error: undefined,
})),
setDismissedVersion: (context) => {
if (context.updateCheck?.version) {
// We use localStorage to ensure users who have dimissed the UpdateCheckBanner are not plagued by it on page reload
localStorage.setItem("dismissedVersion", context.updateCheck.version)
}
},
},
guards: {
canViewUpdateCheck: (context) =>
Expand Down
5 changes: 0 additions & 5 deletions site/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6550,11 +6550,6 @@ eslint-plugin-jsx-a11y@6.6.1:
minimatch "^3.1.2"
semver "^6.3.0"

eslint-plugin-no-storage@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-no-storage/-/eslint-plugin-no-storage-1.0.2.tgz#b32b2f00c4084f8e70c6c4ea79704ffe28b6caad"
integrity sha512-INY2pA4ynTsPIb7wP6+j1QEzDx+zVZ1rZsQkC3up+TQLXsVGg3AnYSqDv/LlwR1QPfh4fDEgQ2Hg5Zxk2XxxEw==

eslint-plugin-react-hooks@4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.0.tgz#4c3e697ad95b77e93f8646aaa1630c1ba607edd3"
Expand Down