mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2026-03-10 21:25:04 +00:00
Direct Messages can use redux for creating new DM channels
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import {
|
||||
SET_DIRECT_MESSAGES,
|
||||
LOADING_UI,
|
||||
SET_ERRORS,
|
||||
CLEAR_ERRORS,
|
||||
SET_LOADING_UI_2,
|
||||
SET_LOADING_UI_3,
|
||||
SET_LOADING_UI_4,
|
||||
SET_NOT_LOADING_UI_2,
|
||||
SET_NOT_LOADING_UI_3,
|
||||
SET_NOT_LOADING_UI_4
|
||||
} from '../types';
|
||||
import axios from "axios";
|
||||
|
||||
export const getDirectMessages = () => (dispatch) => {
|
||||
dispatch({type: LOADING_UI});
|
||||
axios.get('/dms')
|
||||
.then((res) => {
|
||||
dispatch({
|
||||
type: SET_DIRECT_MESSAGES,
|
||||
payload: res.data.data
|
||||
});
|
||||
dispatch({type: CLEAR_ERRORS});
|
||||
})
|
||||
}
|
||||
|
||||
export const createNewDirectMessage = (username) => (dispatch) => {
|
||||
dispatch({type: SET_LOADING_UI_3});
|
||||
const data = {
|
||||
user: username
|
||||
}
|
||||
// console.log(username);
|
||||
|
||||
axios.post('/dms/new', data)
|
||||
.then((res) => {
|
||||
console.log(res.data);
|
||||
if (res.data.err) {
|
||||
dispatch({
|
||||
type: SET_ERRORS,
|
||||
payload: {
|
||||
createDirectMessage: res.data.err
|
||||
}
|
||||
});
|
||||
}
|
||||
dispatch({type: SET_NOT_LOADING_UI_3});
|
||||
})
|
||||
.catch((err) => {
|
||||
dispatch({
|
||||
type: SET_ERRORS,
|
||||
payload: {
|
||||
createDirectMessage: err.response.data.err
|
||||
}
|
||||
});
|
||||
dispatch({type: SET_NOT_LOADING_UI_3});
|
||||
console.log(err.response.data);
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import {SET_DIRECT_MESSAGES, SET_USERNAME_VALID, SET_USERNAME_INVALID} from '../types';
|
||||
|
||||
const initialState = {
|
||||
directMessages: null,
|
||||
};
|
||||
|
||||
export default function(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case SET_DIRECT_MESSAGES:
|
||||
return {
|
||||
...state,
|
||||
directMessages: action.payload
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,20 @@
|
||||
import { SET_ERRORS, CLEAR_ERRORS, LOADING_UI } from '../types';
|
||||
import {
|
||||
SET_ERRORS,
|
||||
CLEAR_ERRORS,
|
||||
LOADING_UI,
|
||||
SET_LOADING_UI_2,
|
||||
SET_LOADING_UI_3,
|
||||
SET_LOADING_UI_4,
|
||||
SET_NOT_LOADING_UI_2,
|
||||
SET_NOT_LOADING_UI_3,
|
||||
SET_NOT_LOADING_UI_4
|
||||
} from '../types';
|
||||
|
||||
const initialState = {
|
||||
loading: false,
|
||||
loading2: false,
|
||||
loading3: false,
|
||||
loading4: false,
|
||||
errors: null
|
||||
};
|
||||
|
||||
@@ -23,7 +36,37 @@ export default function(state = initialState, action) {
|
||||
return {
|
||||
...state,
|
||||
loading: true
|
||||
}
|
||||
};
|
||||
case SET_LOADING_UI_2:
|
||||
return {
|
||||
...state,
|
||||
loading2: true
|
||||
};
|
||||
case SET_LOADING_UI_3:
|
||||
return {
|
||||
...state,
|
||||
loading3: true
|
||||
};
|
||||
case SET_LOADING_UI_4:
|
||||
return {
|
||||
...state,
|
||||
loading4: true
|
||||
};
|
||||
case SET_NOT_LOADING_UI_2:
|
||||
return {
|
||||
...state,
|
||||
loading2: false
|
||||
};
|
||||
case SET_NOT_LOADING_UI_3:
|
||||
return {
|
||||
...state,
|
||||
loading3: false
|
||||
};
|
||||
case SET_NOT_LOADING_UI_4:
|
||||
return {
|
||||
...state,
|
||||
loading4: false
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,15 @@ export const LOADING_USER = 'LOADING_USER';
|
||||
// UI reducer types
|
||||
export const SET_ERRORS = 'SET_ERRORS';
|
||||
export const LOADING_UI = 'LOADING_UI';
|
||||
export const SET_LOADING_UI_2 = 'SET_LOADING_UI_2';
|
||||
export const SET_LOADING_UI_3 = 'SET_LOADING_UI_3';
|
||||
export const SET_LOADING_UI_4 = 'SET_LOADING_UI_4';
|
||||
export const SET_NOT_LOADING_UI_2 = 'SET_NOT_LOADING_UI_2';
|
||||
export const SET_NOT_LOADING_UI_3 = 'SET_NOT_LOADING_UI_3';
|
||||
export const SET_NOT_LOADING_UI_4 = 'SET_NOT_LOADING_UI_4';
|
||||
export const CLEAR_ERRORS = 'CLEAR_ERRORS';
|
||||
|
||||
// Data reducer types
|
||||
// Data reducer types
|
||||
export const SET_DIRECT_MESSAGES = 'SET_DIRECT_MESSAGES';
|
||||
export const SET_USERNAME_VALID = 'SET_USERNAME_VALID';
|
||||
export const SET_USERNAME_INVALID = 'SET_USERNAME_INVALID';
|
||||
Reference in New Issue
Block a user