From 0bdb8142c6ca913b67e5a20306e0909cfd73c5c8 Mon Sep 17 00:00:00 2001 From: Rokt33r Date: Sun, 18 Oct 2015 20:18:16 +0900 Subject: [PATCH] USER auto refresh --- browser/main/HomePage/ArticleNavigator.js | 14 ++++++++------ lib/actions.js | 2 +- lib/reducer.js | 2 +- lib/socket.js | 4 +++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/browser/main/HomePage/ArticleNavigator.js b/browser/main/HomePage/ArticleNavigator.js index 3150449b..ee8ffc14 100644 --- a/browser/main/HomePage/ArticleNavigator.js +++ b/browser/main/HomePage/ArticleNavigator.js @@ -33,12 +33,14 @@ export default class ArticleNavigator extends React.Component { let activeFolder = findWhere(activeUser.Folders, {id: status.folderId}) - let folders = activeUser.Folders.map((folder, index) => { - return ( - - ) - }) + let folders = activeUser.Folders != null + ? activeUser.Folders.map((folder, index) => { + return ( + + ) + }) + : [] let members = Array.isArray(activeUser.Members) ? activeUser.Members.sort((a, b) => { return new Date(a._pivot_createdAt) - new Date(b._pivot_createdAt) diff --git a/lib/actions.js b/lib/actions.js index 76851c15..b34e0b5c 100644 --- a/lib/actions.js +++ b/lib/actions.js @@ -23,7 +23,7 @@ export const UNSYNCED = 'UNSYNCED' export function updateUser (user) { return { type: USER_UPDATE, - data: user + data: { user } } } diff --git a/lib/reducer.js b/lib/reducer.js index 25f3f0bf..5cee48a6 100644 --- a/lib/reducer.js +++ b/lib/reducer.js @@ -25,7 +25,7 @@ function getInitialArticles () { function currentUser (state, action) { switch (action.type) { case USER_UPDATE: - let user = action.data + let user = action.data.user return auth.user(user) default: diff --git a/lib/socket.js b/lib/socket.js index 9d9e36f6..e62f0fb3 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -2,7 +2,7 @@ import { API_URL } from '../config' import socketio from 'socket.io-client' import auth from './auth' import store from './store' -import { updateArticle, destroyArticle } from './actions' +import { updateUser, updateArticle, destroyArticle } from './actions' export const CONN = 'CONN' export const ALERT = 'ALERT' @@ -27,6 +27,8 @@ io.on(ALERT, function (data) { io.on(USER_UPDATE, function (data) { console.log(USER_UPDATE, data) + let { user } = data + store.dispatch(updateUser(user)) }) io.on(ARTICLE_UPDATE, function (data) {