From 2d57bcf1b7ea3a9df42ae7e1eb9388f978a96312 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 1 Sep 2016 15:13:02 +0200 Subject: [PATCH] Preparing for follow form --- .../javascripts/components/actions/follow.jsx | 48 +++++++++++++++++++ .../components/components/status.jsx | 4 +- .../components/reducers/follow.jsx | 24 ++++++++++ .../javascripts/components/reducers/index.jsx | 4 +- 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/components/actions/follow.jsx create mode 100644 app/assets/javascripts/components/reducers/follow.jsx diff --git a/app/assets/javascripts/components/actions/follow.jsx b/app/assets/javascripts/components/actions/follow.jsx new file mode 100644 index 000000000..1c4e2c66a --- /dev/null +++ b/app/assets/javascripts/components/actions/follow.jsx @@ -0,0 +1,48 @@ +import api from '../api' + +export const FOLLOW_CHANGE = 'FOLLOW_CHANGE'; +export const FOLLOW_SUBMIT = 'FOLLOW_SUBMIT'; +export const FOLLOW_SUBMIT_REQUEST = 'FOLLOW_SUBMIT_REQUEST'; +export const FOLLOW_SUBMIT_SUCCESS = 'FOLLOW_SUBMIT_SUCCESS'; +export const FOLLOW_SUBMIT_FAIL = 'FOLLOW_SUBMIT_FAIL'; + +export function followChange(text) { + return { + type: FOLLOW_CHANGE, + text: text + }; +} + +export function followSubmit() { + return function (dispatch, getState) { + dispatch(followSubmitRequest()); + + api(getState).post('/api/follows', { + uri: getState().getIn(['follow', 'text']) + }).then(function (response) { + dispatch(followSubmitSuccess(response.data)); + }).catch(function (error) { + dispatch(followSubmitFail(error)); + }); + }; +} + +export function followSubmitRequest() { + return { + type: FOLLOW_SUBMIT_REQUEST + }; +} + +export function followSubmitSuccess(account) { + return { + type: FOLLOW_SUBMIT_SUCCESS, + account: account + }; +} + +export function followSubmitFail(error) { + return { + type: FOLLOW_SUBMIT_FAIL, + error: error + }; +} diff --git a/app/assets/javascripts/components/components/status.jsx b/app/assets/javascripts/components/components/status.jsx index fabe85bab..9f46e0e76 100644 --- a/app/assets/javascripts/components/components/status.jsx +++ b/app/assets/javascripts/components/components/status.jsx @@ -34,10 +34,10 @@ const Status = React.createClass({ if (status.get('reblog') !== null) { return ( -
+
- {status.getIn(['account', 'display_name'])} reblogged + {status.getIn(['account', 'display_name'])} reblogged
diff --git a/app/assets/javascripts/components/reducers/follow.jsx b/app/assets/javascripts/components/reducers/follow.jsx new file mode 100644 index 000000000..348510eaf --- /dev/null +++ b/app/assets/javascripts/components/reducers/follow.jsx @@ -0,0 +1,24 @@ +import * as constants from '../actions/follow'; +import Immutable from 'immutable'; + +const initialState = Immutable.Map({ + text: '', + is_submitting: false +}); + +export default function compose(state = initialState, action) { + switch(action.type) { + case constants.FOLLOW_CHANGE: + return state.set('text', action.text); + case constants.FOLLOW_SUBMIT_REQUEST: + return state.set('is_submitting', true); + case constants.FOLLOW_SUBMIT_SUCCESS: + return state.withMutations(map => { + map.set('text', '').set('is_submitting', false); + }); + case constants.FOLLOW_SUBMIT_FAIL: + return state.set('is_submitting', false); + default: + return state; + } +} diff --git a/app/assets/javascripts/components/reducers/index.jsx b/app/assets/javascripts/components/reducers/index.jsx index 9acbfcf46..3f3e1e928 100644 --- a/app/assets/javascripts/components/reducers/index.jsx +++ b/app/assets/javascripts/components/reducers/index.jsx @@ -2,9 +2,11 @@ import { combineReducers } from 'redux-immutable'; import timelines from './timelines'; import meta from './meta'; import compose from './compose'; +import follow from './follow'; export default combineReducers({ timelines, meta, - compose + compose, + follow });