mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-15 18:56:22 +00:00
on Refactor... #4
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
/* global localStorage */
|
||||
|
||||
var Reflux = require('reflux')
|
||||
|
||||
var actions = Reflux.createActions([
|
||||
@@ -8,6 +10,36 @@ var actions = Reflux.createActions([
|
||||
module.exports = Reflux.createStore({
|
||||
listenables: [actions],
|
||||
onUpdate: function (user) {
|
||||
var currentUser = JSON.parse(localStorage.getItem('currentUser'))
|
||||
|
||||
if (currentUser.id === user.id) {
|
||||
localStorage.setItem('currentUser', JSON.stringify(user))
|
||||
}
|
||||
|
||||
if (user.userType === 'team') {
|
||||
var isMyTeam = user.Members.some(function (member) {
|
||||
if (currentUser.id === member.id) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
if (isMyTeam) {
|
||||
var isNew = !currentUser.Teams.some(function (team, index) {
|
||||
if (user.id === team.id) {
|
||||
currentUser.Teams.splice(index, 1, user)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
if (isNew) {
|
||||
currentUser.Teams.push(user)
|
||||
}
|
||||
localStorage.setItem('currentUser', JSON.stringify(currentUser))
|
||||
}
|
||||
}
|
||||
|
||||
this.trigger({
|
||||
status: 'userUpdated',
|
||||
data: user
|
||||
|
||||
Reference in New Issue
Block a user