Skip to content

Commit 983e18f

Browse files
committed
fix: Store dismissedBanner key in localStorage
1 parent 88bb901 commit 983e18f

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

site/.eslintrc.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ rules:
9898
message:
9999
"Use path imports to avoid pulling in unused modules. See:
100100
https://material-ui.com/guides/minimizing-bundle-size/"
101-
no-storage/no-browser-storage: error
102101
no-unused-vars: "off"
103102
"object-curly-spacing": "off"
104103
react-hooks/exhaustive-deps: warn

site/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
"eslint-plugin-import": "2.26.0",
112112
"eslint-plugin-jest": "27.0.1",
113113
"eslint-plugin-jsx-a11y": "6.6.1",
114-
"eslint-plugin-no-storage": "1.0.2",
115114
"eslint-plugin-react": "7.31.1",
116115
"eslint-plugin-react-hooks": "4.6.0",
117116
"eslint-plugin-unicorn": "44.0.0",

site/src/api/api.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,14 @@ export const getBuildInfo = async (): Promise<TypesGen.BuildInfoResponse> => {
407407
export const getUpdateCheck =
408408
async (): Promise<TypesGen.UpdateCheckResponse> => {
409409
const response = await axios.get("/api/v2/updatecheck")
410+
// return {
411+
// current: true,
412+
// url: "https://github.com/coder/coder/releases/tag/v0.13.1",
413+
// version: "v0.13.1"
414+
// }
415+
console.log('response.data', response.data)
410416
return response.data
417+
return { current: false, version: 'v0.13.1', url: 'https://github.com/coder/coder/releases/tag/v0.13.1' }
411418
}
412419

413420
export const putWorkspaceAutostart = async (

site/src/components/AuthAndFrame/AuthAndFrame.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const AuthAndFrame: FC<AuthAndFrameProps> = ({ children }) => {
2727

2828
useEffect(() => {
2929
if (authState.matches("signedIn")) {
30-
updateCheckSend("CHECK")
30+
updateCheckSend("CHECK") // this calls getUpdateCheck which returns the latest version
3131
} else {
3232
updateCheckSend("CLEAR")
3333
}

site/src/xServices/updateCheck/updateCheckXService.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const updateCheckMachine = createMachine(
117117
dismissOrClear: {
118118
on: {
119119
DISMISS: {
120-
actions: ["assignHide"],
120+
actions: ["assignHide", "setDismissedVersion"],
121121
target: "dismissed",
122122
},
123123
CLEAR: {
@@ -141,9 +141,9 @@ export const updateCheckMachine = createMachine(
141141
assignPermissions: assign({
142142
permissions: (_, event) => event.data as Permissions,
143143
}),
144-
assignShow: assign({
145-
show: true,
146-
}),
144+
assignShow: assign((context) => ({
145+
show: localStorage.getItem("dismissedVersion") !== context.updateCheck?.version,
146+
})),
147147
assignHide: assign({
148148
show: false,
149149
}),
@@ -161,6 +161,12 @@ export const updateCheckMachine = createMachine(
161161
...context,
162162
error: undefined,
163163
})),
164+
setDismissedVersion: (context) => {
165+
if (context.updateCheck?.version) {
166+
// We use localStorage to ensure users who have dimissed the UpdateCheckBanner are not plagued by it on page reload
167+
localStorage.setItem("dismissedVersion", context.updateCheck.version)
168+
}
169+
},
164170
},
165171
guards: {
166172
canViewUpdateCheck: (context) =>

site/yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6550,11 +6550,6 @@ eslint-plugin-jsx-a11y@6.6.1:
65506550
minimatch "^3.1.2"
65516551
semver "^6.3.0"
65526552

6553-
eslint-plugin-no-storage@1.0.2:
6554-
version "1.0.2"
6555-
resolved "https://registry.yarnpkg.com/eslint-plugin-no-storage/-/eslint-plugin-no-storage-1.0.2.tgz#b32b2f00c4084f8e70c6c4ea79704ffe28b6caad"
6556-
integrity sha512-INY2pA4ynTsPIb7wP6+j1QEzDx+zVZ1rZsQkC3up+TQLXsVGg3AnYSqDv/LlwR1QPfh4fDEgQ2Hg5Zxk2XxxEw==
6557-
65586553
eslint-plugin-react-hooks@4.6.0:
65596554
version "4.6.0"
65606555
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.0.tgz#4c3e697ad95b77e93f8646aaa1630c1ba607edd3"

0 commit comments

Comments
 (0)