Skip to content

Commit

Permalink
fix(settings): Save account management settings in local storage
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Mar 11, 2024
1 parent cbdadba commit 78bcab1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
38 changes: 9 additions & 29 deletions apps/settings/src/components/Users/UserSettingsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
</template>

<script>
import { getBuilder } from '@nextcloud/browser-storage'
import { formatFileSize, parseFileSize } from '@nextcloud/files'
import { generateUrl } from '@nextcloud/router'
Expand Down Expand Up @@ -103,15 +102,6 @@ export default {
},
},
setup() {
const localStorage = getBuilder('settings')
.persist(true)
.clearOnLogout(true)
.build()
return { localStorage }
},
data() {
return {
selectedQuota: false,
Expand Down Expand Up @@ -139,37 +129,37 @@ export default {
showLanguages: {
get() {
return this.getLocalstorage('showLanguages')
return this.showConfig.showLanguages
},
set(status) {
this.setLocalStorage('showLanguages', status)
this.setShowConfig('showLanguages', status)
},
},
showLastLogin: {
get() {
return this.getLocalstorage('showLastLogin')
return this.showConfig.showLastLogin
},
set(status) {
this.setLocalStorage('showLastLogin', status)
this.setShowConfig('showLastLogin', status)
},
},
showUserBackend: {
get() {
return this.getLocalstorage('showUserBackend')
return this.showConfig.showUserBackend
},
set(status) {
this.setLocalStorage('showUserBackend', status)
this.setShowConfig('showUserBackend', status)
},
},
showStoragePath: {
get() {
return this.getLocalstorage('showStoragePath')
return this.showConfig.showStoragePath
},
set(status) {
this.setLocalStorage('showStoragePath', status)
this.setShowConfig('showStoragePath', status)
},
},
Expand Down Expand Up @@ -221,18 +211,8 @@ export default {
},
methods: {
getLocalstorage(key) {
// force initialization
const localConfig = JSON.parse(this.localStorage.getItem(key) ?? 'null')
// if localstorage is null, fallback to original values
this.$store.commit('setShowConfig', { key, value: localConfig !== null ? localConfig === 'true' : this.showConfig[key] })
return this.showConfig[key]
},
setLocalStorage(key, status) {
setShowConfig(key, status) {
this.$store.commit('setShowConfig', { key, value: status })
this.localStorage.setItem(key, JSON.stringify(status))
return status
},
/**
Expand Down
14 changes: 9 additions & 5 deletions apps/settings/src/store/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*
*/

import { getBuilder } from '@nextcloud/browser-storage'
import { getCapabilities } from '@nextcloud/capabilities'
import { parseFileSize } from '@nextcloud/files'
import { generateOcsUrl } from '@nextcloud/router'
Expand All @@ -35,6 +36,8 @@ import axios from '@nextcloud/axios'
import api from './api.js'
import logger from '../logger.ts'

const localStorage = getBuilder('settings').persist(true).build()

const orderGroups = function(groups, orderBy) {
/* const SORT_USERCOUNT = 1;
* const SORT_GROUPNAME = 2;
Expand Down Expand Up @@ -69,11 +72,11 @@ const state = {
disabledUsersLimit: 25,
userCount: 0,
showConfig: {
showStoragePath: false,
showUserBackend: false,
showLastLogin: false,
showNewUserForm: false,
showLanguages: false,
showStoragePath: localStorage.getItem('account_settings__showStoragePath') === 'true',
showUserBackend: localStorage.getItem('account_settings__showUserBackend') === 'true',
showLastLogin: localStorage.getItem('account_settings__showLastLogin') === 'true',
showNewUserForm: localStorage.getItem('account_settings__showNewUserForm') === 'true',
showLanguages: localStorage.getItem('account_settings__showLanguages') === 'true',
},
}

Expand Down Expand Up @@ -248,6 +251,7 @@ const mutations = {
},

setShowConfig(state, { key, value }) {
localStorage.setItem(`account_settings__${key}`, JSON.stringify(value))
state.showConfig[key] = value
},
}
Expand Down

0 comments on commit 78bcab1

Please sign in to comment.