mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
* Added sort to all workspaces homepage and remember preference * Fixed feedback * Fixed migration conflict * Fixed feedback
29 lines
975 B
JavaScript
29 lines
975 B
JavaScript
import { computed } from 'vue'
|
|
import { useStore } from 'vuex'
|
|
|
|
import { notifyIf } from '@baserow/modules/core/utils/error'
|
|
|
|
/**
|
|
* A writable ref backed by a registered user preference, so a setting survives
|
|
* reloads and follows the user across devices. Reading straight from the store
|
|
* keeps the value in sync when an optimistic update is rolled back after a
|
|
* failed request.
|
|
*
|
|
* @param {string} key The type of a backend registered user preference.
|
|
* @param {*} fallback Used when the session predates the preference.
|
|
* @returns {import('vue').WritableComputedRef} The preference value.
|
|
*/
|
|
export function useUserPreference(key, fallback = undefined) {
|
|
const store = useStore()
|
|
return computed({
|
|
get: () => store.getters['auth/getUserPreference'](key) ?? fallback,
|
|
set: (value) => {
|
|
store
|
|
.dispatch('auth/updateUserPreferences', { [key]: value })
|
|
.catch((error) => {
|
|
notifyIf(error, 'user')
|
|
})
|
|
},
|
|
})
|
|
}
|