diff options
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/statuses.js | 2 | ||||
| -rw-r--r-- | src/modules/users.js | 38 |
2 files changed, 39 insertions, 1 deletions
diff --git a/src/modules/statuses.js b/src/modules/statuses.js index b1a77061..8109d906 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -82,7 +82,7 @@ const addStatusesToTimeline = (addedStatuses, showImmediately, { statuses, visib visibleStatuses: newVisibleStatuses, newStatusCount: newNewStatusCount, maxId: newStatuses[0].id, - minVisibleId: last(newVisibleStatuses).id, + minVisibleId: (last(newVisibleStatuses) || { id: undefined }).id, faves: unionBy(faves, addedFaves, 'id') } } diff --git a/src/modules/users.js b/src/modules/users.js new file mode 100644 index 00000000..e7ebf305 --- /dev/null +++ b/src/modules/users.js @@ -0,0 +1,38 @@ +import apiService from '../services/api/api.service.js' + +const users = { + state: { + currentUser: false, + loggingIn: false + }, + mutations: { + setCurrentUser (state, user) { + state.currentUser = user + }, + beginLogin (state) { + state.loggingIn = true + }, + endLogin (state) { + state.loggingIn = false + } + }, + actions: { + loginUser ({commit, state}, userCredentials) { + commit('beginLogin') + apiService.verifyCredentials(userCredentials) + .then((response) => { + if (response.ok) { + response.json() + .then((user) => commit('setCurrentUser', user)) + } + commit('endLogin') + }) + .catch((error) => { + console.log(error) + commit('endLogin') + }) + } + } +} + +export default users |
