aboutsummaryrefslogtreecommitdiff
path: root/src/lib/persisted_state.js
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2018-11-26 04:38:44 +0300
committerHenry Jameson <me@hjkos.com>2018-11-26 04:38:44 +0300
commite06717fd0dfa4b37ebf481d5f4cd7ce8ef0034d0 (patch)
tree7f3f7d27ac932e72ec9b5fbdb41b7c8efb210396 /src/lib/persisted_state.js
parent0ca42bd3d63e209f9c1354a30a3123c1f7317579 (diff)
parentf1a23f2b6edb0858890c82cf42c8b6d835102d56 (diff)
Merge remote-tracking branch 'upstream/develop' into feature/scope_preferences
* upstream/develop: DM timeline: stream new statuses update-japanese-translation Add actual user search. incorporate most translation changes from MR 368 update french translation Always show dm panel. Add direct message tab. api service url On logout switch to public timeline. Put oauth text into description. Display OAuth login on login form button. Add login form back in. Linting. Re-activate registration, use oauth password flow to fetch token. Fix typo. Remove gonsole.logg :DD Fix linting. Move login to oauth.
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)
- }
- })
- }
+ })
+ }
+ })
}