fix(ui): darkMode lost on cache reset

This commit is contained in:
Guillaume Chau
2018-06-20 14:15:24 +02:00
parent fd92852542
commit b4f6b3c89f
3 changed files with 14 additions and 6 deletions
@@ -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: {
@@ -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
}
}
+8
View File
@@ -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)
@@ -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 */