Created
October 21, 2016 19:54
-
-
Save bnhansn/54780a12e8d44d9d95ef560696e2a2ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import api from '../api'; | |
| export function fetchRooms() { | |
| return dispatch => api.fetch('/rooms') | |
| .then((response) => { | |
| dispatch({ type: 'FETCH_ROOMS_SUCCESS', response }); | |
| }); | |
| } | |
| export function fetchUserRooms(userId) { | |
| return dispatch => api.fetch(`/users/${userId}/rooms`) | |
| .then((response) => { | |
| dispatch({ type: 'FETCH_USER_ROOMS_SUCCESS', response }); | |
| }); | |
| } | |
| export function createRoom(data, router) { | |
| return dispatch => api.post('/rooms', data) | |
| .then((response) => { | |
| dispatch({ type: 'CREATE_ROOM_SUCCESS', response }); | |
| router.transitionTo(`/r/${response.data.id}`); | |
| }); | |
| } | |
| export function joinRoom(roomId, router) { | |
| return dispatch => api.post(`/rooms/${roomId}/join`) | |
| .then((response) => { | |
| dispatch({ type: 'ROOM_JOINED', response }); | |
| router.transitionTo(`/r/${response.data.id}`); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment