From 445687cc54a847d1cc6a056fdc406fc66c6e5195 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Fri, 22 Nov 2019 18:21:52 -0500 Subject: [PATCH] Automatically display new Direct Messages --- twistter-frontend/src/pages/directMessages.js | 3 ++- twistter-frontend/src/redux/actions/dataActions.js | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/twistter-frontend/src/pages/directMessages.js b/twistter-frontend/src/pages/directMessages.js index 63fb8b0..3f43882 100644 --- a/twistter-frontend/src/pages/directMessages.js +++ b/twistter-frontend/src/pages/directMessages.js @@ -207,7 +207,7 @@ export class directMessages extends Component { componentDidMount() { this.props.getDirectMessages(); - // this.updatePage(); + this.updatePage(); } // Updates the state whenever redux is updated @@ -230,6 +230,7 @@ export class directMessages extends Component { updatePage = async() => { while (true) { await this.sleep(15000); + // console.log("getting new DMs"); this.props.getNewDirectMessages(); } } diff --git a/twistter-frontend/src/redux/actions/dataActions.js b/twistter-frontend/src/redux/actions/dataActions.js index d387b6a..595d2d4 100644 --- a/twistter-frontend/src/redux/actions/dataActions.js +++ b/twistter-frontend/src/redux/actions/dataActions.js @@ -12,6 +12,8 @@ import { } from '../types'; import axios from "axios"; +// TODO: Tidy up these functions. They shouldn't have all these promises in them. + export const getDirectMessages = () => (dispatch) => { dispatch({type: SET_LOADING_UI_2}); axios.get('/dms') @@ -37,6 +39,10 @@ export const getNewDirectMessages = () => (dispatch) => { dispatch({type: CLEAR_ERRORS}); resolve(); }) + .catch((err) => { + console.log(err) + reject(err); + }) }) } @@ -52,6 +58,10 @@ export const reloadDirectMessageChannels = () => (dispatch) => { dispatch({type: CLEAR_ERRORS}); resolve(); }) + .catch((err) => { + console.log(err) + reject(err); + }) }) } @@ -66,7 +76,7 @@ export const createNewDirectMessage = (username) => (dispatch) => { axios.post('/dms/new', data) .then((res) => { - console.log(res.data); + // console.log(res.data); if (res.data.err) { dispatch({ type: SET_ERRORS, @@ -90,7 +100,7 @@ export const createNewDirectMessage = (username) => (dispatch) => { }); dispatch({type: SET_NOT_LOADING_UI_3}); console.log(err.response.data); - reject(); + reject(err); }) }); }