mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 18:28:47 +00:00
Automatically display new Direct Messages
This commit is contained in:
parent
331509da7f
commit
445687cc54
@ -207,7 +207,7 @@ export class directMessages extends Component {
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.getDirectMessages();
|
this.props.getDirectMessages();
|
||||||
// this.updatePage();
|
this.updatePage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates the state whenever redux is updated
|
// Updates the state whenever redux is updated
|
||||||
@ -230,6 +230,7 @@ export class directMessages extends Component {
|
|||||||
updatePage = async() => {
|
updatePage = async() => {
|
||||||
while (true) {
|
while (true) {
|
||||||
await this.sleep(15000);
|
await this.sleep(15000);
|
||||||
|
// console.log("getting new DMs");
|
||||||
this.props.getNewDirectMessages();
|
this.props.getNewDirectMessages();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,8 @@ import {
|
|||||||
} from '../types';
|
} from '../types';
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
|
// TODO: Tidy up these functions. They shouldn't have all these promises in them.
|
||||||
|
|
||||||
export const getDirectMessages = () => (dispatch) => {
|
export const getDirectMessages = () => (dispatch) => {
|
||||||
dispatch({type: SET_LOADING_UI_2});
|
dispatch({type: SET_LOADING_UI_2});
|
||||||
axios.get('/dms')
|
axios.get('/dms')
|
||||||
@ -37,6 +39,10 @@ export const getNewDirectMessages = () => (dispatch) => {
|
|||||||
dispatch({type: CLEAR_ERRORS});
|
dispatch({type: CLEAR_ERRORS});
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
reject(err);
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +58,10 @@ export const reloadDirectMessageChannels = () => (dispatch) => {
|
|||||||
dispatch({type: CLEAR_ERRORS});
|
dispatch({type: CLEAR_ERRORS});
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
reject(err);
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -66,7 +76,7 @@ export const createNewDirectMessage = (username) => (dispatch) => {
|
|||||||
|
|
||||||
axios.post('/dms/new', data)
|
axios.post('/dms/new', data)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res.data);
|
// console.log(res.data);
|
||||||
if (res.data.err) {
|
if (res.data.err) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: SET_ERRORS,
|
type: SET_ERRORS,
|
||||||
@ -90,7 +100,7 @@ export const createNewDirectMessage = (username) => (dispatch) => {
|
|||||||
});
|
});
|
||||||
dispatch({type: SET_NOT_LOADING_UI_3});
|
dispatch({type: SET_NOT_LOADING_UI_3});
|
||||||
console.log(err.response.data);
|
console.log(err.response.data);
|
||||||
reject();
|
reject(err);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user