Skip to content

Commit

Permalink
fix(ui): darkMode lost on cache reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Jun 20, 2018
1 parent fd92852 commit b4f6b3c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 0 additions & 6 deletions packages/@vue/cli-ui/src/components/StatusBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,6 @@ export default {
async applyDarkMode (enabled) {
localStorage.setItem('vue-ui-dark-mode', enabled.toString())
const el = document.getElementsByTagName('html')[0]
if (enabled) {
el.classList.add('vue-ui-dark-mode')
} else {
el.classList.remove('vue-ui-dark-mode')
}
await this.$apollo.mutate({
mutation: DARK_MODE_SET,
variables: {
Expand Down
6 changes: 6 additions & 0 deletions packages/@vue/cli-ui/src/state/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export default {
darkMode: enabled
}
cache.writeData({ data })
const el = document.getElementsByTagName('html')[0]
if (enabled) {
el.classList.add('vue-ui-dark-mode')
} else {
el.classList.remove('vue-ui-dark-mode')
}
return null
}
}
Expand Down
8 changes: 8 additions & 0 deletions packages/@vue/cli-ui/src/vue-apollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import clientStateResolvers from './state/resolvers'
// import CONNECTED from './graphql/connected.gql'
import CONNECTED_SET from './graphql/connectedSet.gql'
import LOADING_CHANGE from './graphql/loadingChange.gql'
import DARK_MODE_SET from './graphql/darkModeSet.gql'

// Install the vue plugin
Vue.use(VueApollo)
Expand Down Expand Up @@ -67,6 +68,13 @@ export async function resetApollo () {
} catch (e) {
// Potential errors
}
const raw = localStorage.getItem('vue-ui-dark-mode')
apolloClient.mutate({
mutation: DARK_MODE_SET,
variables: {
enabled: raw === 'true'
}
})
}

/* Connected state */
Expand Down

0 comments on commit b4f6b3c

Please sign in to comment.