mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2026-03-10 21:25:04 +00:00
Dynamic front-end adding new DM channels
This commit is contained in:
@@ -13,19 +13,52 @@ import {
|
||||
import axios from "axios";
|
||||
|
||||
export const getDirectMessages = () => (dispatch) => {
|
||||
dispatch({type: LOADING_UI});
|
||||
dispatch({type: SET_LOADING_UI_2});
|
||||
axios.get('/dms')
|
||||
.then((res) => {
|
||||
dispatch({
|
||||
type: SET_DIRECT_MESSAGES,
|
||||
payload: res.data.data
|
||||
});
|
||||
dispatch({type: SET_NOT_LOADING_UI_2});
|
||||
dispatch({type: CLEAR_ERRORS});
|
||||
})
|
||||
}
|
||||
|
||||
export const getNewDirectMessages = () => (dispatch) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get('/dms')
|
||||
.then((res) => {
|
||||
dispatch({
|
||||
type: SET_DIRECT_MESSAGES,
|
||||
payload: res.data.data
|
||||
});
|
||||
dispatch({type: SET_NOT_LOADING_UI_2});
|
||||
dispatch({type: CLEAR_ERRORS});
|
||||
resolve();
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const reloadDirectMessageChannels = () => (dispatch) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get('/dms')
|
||||
.then((res) => {
|
||||
dispatch({
|
||||
type: SET_DIRECT_MESSAGES,
|
||||
payload: res.data.data
|
||||
});
|
||||
dispatch({type: SET_NOT_LOADING_UI_3});
|
||||
dispatch({type: CLEAR_ERRORS});
|
||||
resolve();
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
export const createNewDirectMessage = (username) => (dispatch) => {
|
||||
dispatch({type: SET_LOADING_UI_3});
|
||||
return new Promise((resolve, reject) => {
|
||||
dispatch({type: SET_LOADING_UI_3});
|
||||
const data = {
|
||||
user: username
|
||||
}
|
||||
@@ -41,17 +74,25 @@ export const createNewDirectMessage = (username) => (dispatch) => {
|
||||
createDirectMessage: res.data.err
|
||||
}
|
||||
});
|
||||
dispatch({type: SET_NOT_LOADING_UI_3});
|
||||
} else {
|
||||
// dispatch(getNewDirectMessages());
|
||||
// dispatch({type: SET_NOT_LOADING_UI_3});
|
||||
}
|
||||
dispatch({type: SET_NOT_LOADING_UI_3});
|
||||
resolve();
|
||||
})
|
||||
.catch((err) => {
|
||||
dispatch({
|
||||
type: SET_ERRORS,
|
||||
payload: {
|
||||
createDirectMessage: err.response.data.err
|
||||
createDirectMessage: err.response.data.error
|
||||
}
|
||||
});
|
||||
dispatch({type: SET_NOT_LOADING_UI_3});
|
||||
console.log(err.response.data);
|
||||
reject();
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user