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
| defmodule Sling.PaginationHelpers do | |
| def pagination(page) do | |
| %{ | |
| page_number: page.page_number, | |
| page_size: page.page_size, | |
| total_pages: page.total_pages, | |
| total_entries: page.total_entries | |
| } | |
| end | |
| end |
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
| defmodule Sling.RoomChannel do | |
| use Sling.Web, :channel | |
| def join("rooms:" <> room_id, _params, socket) do | |
| room = Repo.get!(Sling.Room, room_id) | |
| page = | |
| Sling.Message | |
| |> where([m], m.room_id == ^room.id) | |
| |> order_by([desc: :inserted_at, desc: :id]) |
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
| defmodule Sling.Repo do | |
| use Ecto.Repo, otp_app: :sling | |
| use Scrivener, page_size: 25 | |
| end |
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
| // @flow | |
| import React, { Component } from 'react'; | |
| import { connect } from 'react-redux'; | |
| import { connectToChannel, leaveChannel } from '../../actions/room'; | |
| type RoomType = { | |
| id: number, | |
| name: string, | |
| } |
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 room from './room'; // new line | |
| const appReducer = combineReducers({ | |
| form, | |
| session, | |
| rooms, | |
| room, // new line | |
| }); |
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
| const initialState = { | |
| channel: null, | |
| currentRoom: {}, | |
| }; | |
| export default function (state = initialState, action) { | |
| switch (action.type) { | |
| case 'ROOM_CONNECTED_TO_CHANNEL': | |
| return { | |
| ...state, |
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
| export function connectToChannel(socket, roomId) { | |
| return (dispatch) => { | |
| if (!socket) { return false; } | |
| const channel = socket.channel(`rooms:${roomId}`); | |
| channel.join().receive('ok', (response) => { | |
| dispatch({ type: 'ROOM_CONNECTED_TO_CHANNEL', response, channel }); | |
| }); | |
| return false; |
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
| const initialState = { | |
| willAuthenticate: true, | |
| isAuthenticated: false, | |
| currentUser: {}, | |
| socket: null, // new line | |
| }; | |
| // ... | |
| case 'LOGOUT': |
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 { reset } from 'redux-form'; | |
| import { Socket } from 'phoenix'; // new line | |
| import api from '../api'; | |
| import { fetchUserRooms } from './rooms'; | |
| const API_URL = process.env.REACT_APP_API_URL; // new line | |
| const WEBSOCKET_URL = API_URL.replace(/(https|http)/, 'ws').replace('/api', ''); // new line | |
| // new function | |
| function connectToSocket(dispatch) { |
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
| defmodule Sling.RoomChannel do | |
| use Sling.Web, :channel | |
| def join("rooms:" <> room_id, _params, socket) do | |
| room = Repo.get!(Sling.Room, room_id) | |
| response = %{ | |
| room: Phoenix.View.render_one(room, Sling.RoomView, "room.json"), | |
| } |