mirror of
https://github.com/fluencelabs/fluid
synced 2025-04-26 15:22:17 +00:00
37 lines
940 B
JavaScript
37 lines
940 B
JavaScript
|
import { saveMessage } from "../utils/api";
|
||
|
|
||
|
//importing loading bar to show when we submit a tweet
|
||
|
import { showLoading, hideLoading } from "react-redux-loading";
|
||
|
|
||
|
export const ADD_MESSAGE = "ADD_MESSAGE";
|
||
|
export const RECEIVE_MESSAGES = "RECEIVE_MESSAGES";
|
||
|
|
||
|
function addMessage(message) {
|
||
|
return {
|
||
|
type: ADD_MESSAGE,
|
||
|
message
|
||
|
};
|
||
|
}
|
||
|
|
||
|
//args: message text and the message that the newTweet is replying to, if any
|
||
|
export function handleAddMessage(text, name) {
|
||
|
//using getState to get the current state of our store
|
||
|
return (dispatch) => {
|
||
|
dispatch(showLoading());
|
||
|
return saveMessage({
|
||
|
text: text,
|
||
|
name: name
|
||
|
})
|
||
|
.then(message => dispatch(addMessage(message)))
|
||
|
.then(() => dispatch(hideLoading()));
|
||
|
};
|
||
|
}
|
||
|
|
||
|
//action creator
|
||
|
export function receiveMessages(messages) {
|
||
|
return {
|
||
|
type: RECEIVE_MESSAGES,
|
||
|
messages
|
||
|
};
|
||
|
}
|