aboutsummaryrefslogtreecommitdiff
path: root/src/lib/persisted_state.js
diff options
context:
space:
mode:
authorRoger Braun <roger@rogerbraun.net>2018-11-13 20:21:04 +0100
committerRoger Braun <roger@rogerbraun.net>2018-11-13 20:21:04 +0100
commit7f13cbc493862cfe3f93f7e33e14cf73de92de66 (patch)
tree8cceac003cb8ff5e6de43000e25dfb07debcf58a /src/lib/persisted_state.js
parentffb9d4faf5c6cebb89947a0a9a085fa07e295d42 (diff)
parent11f8a4f312675a82d5fed9c5e75fed63a8456ffc (diff)
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma-fe into dm-tab
Diffstat (limited to 'src/lib/persisted_state.js')
-rw-r--r--src/lib/persisted_state.js53
1 files changed, 27 insertions, 26 deletions
diff --git a/src/lib/persisted_state.js b/src/lib/persisted_state.js
index 006107e2..32fc93c6 100644
--- a/src/lib/persisted_state.js
+++ b/src/lib/persisted_state.js
@@ -17,7 +17,9 @@ const saveImmedeatelyActions = [
'clearCurrentUser',
'setCurrentUser',
'setHighlight',
- 'setOption'
+ 'setOption',
+ 'setClientData',
+ 'setToken'
]
const defaultStorage = (() => {
@@ -43,8 +45,8 @@ export default function createPersistedState ({
storage = defaultStorage,
subscriber = store => handler => store.subscribe(handler)
} = {}) {
- return store => {
- getState(key, storage).then((savedState) => {
+ return getState(key, storage).then((savedState) => {
+ return store => {
try {
if (typeof savedState === 'object') {
// build user cache
@@ -67,36 +69,35 @@ export default function createPersistedState ({
value: store.state.config.customTheme
})
}
- if (store.state.users.lastLoginName) {
- store.dispatch('loginUser', {username: store.state.users.lastLoginName, password: 'xxx'})
+ if (store.state.oauth.token) {
+ store.dispatch('loginUser', store.state.oauth.token)
}
loaded = true
} catch (e) {
console.log("Couldn't load state")
loaded = true
}
- })
-
- subscriber(store)((mutation, state) => {
- try {
- if (saveImmedeatelyActions.includes(mutation.type)) {
- setState(key, reducer(state, paths), storage)
- .then(success => {
- if (typeof success !== 'undefined') {
+ subscriber(store)((mutation, state) => {
+ try {
+ if (saveImmedeatelyActions.includes(mutation.type)) {
+ setState(key, reducer(state, paths), storage)
+ .then(success => {
+ if (typeof success !== 'undefined') {
+ if (mutation.type === 'setOption') {
+ store.dispatch('settingsSaved', { success })
+ }
+ }
+ }, error => {
if (mutation.type === 'setOption') {
- store.dispatch('settingsSaved', { success })
+ store.dispatch('settingsSaved', { error })
}
- }
- }, error => {
- if (mutation.type === 'setOption') {
- store.dispatch('settingsSaved', { error })
- }
- })
+ })
+ }
+ } catch (e) {
+ console.log("Couldn't persist state:")
+ console.log(e)
}
- } catch (e) {
- console.log("Couldn't persist state:")
- console.log(e)
- }
- })
- }
+ })
+ }
+ })
}