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 webpack = require('webpack'); | |
require('dotenv').config(); | |
module.exports = { | |
webpack: config => { | |
const env = Object.keys(process.env).reduce((acc, curr) => { | |
acc[`process.env.${curr}`] = JSON.stringify(process.env[curr]); | |
return acc; | |
}, {}); |
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 cors = require('cors'); | |
const next = require('next'); | |
const Pusher = require('pusher'); | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const dotenv = require('dotenv').config(); | |
const sentiment = require('sentiment'); | |
const dev = process.env.NODE_ENV !== 'production'; | |
const port = process.env.PORT || 3000; |
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
"scripts": { | |
"dev": "node server.js", | |
"build": "next build", | |
"start": "NODE_ENV=production node server.js" | |
} |
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 React, { Fragment } from 'react'; | |
import Head from 'next/head'; | |
const Layout = props => ( | |
<Fragment> | |
<Head> | |
<meta charSet="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossOrigin="anonymous" /> | |
<title>{props.pageTitle || 'Realtime Chat'}</title> |
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 React, { Component } from 'react'; | |
import Layout from '../components/Layout'; | |
class IndexPage extends Component { | |
state = { user: null } | |
handleKeyUp = evt => { | |
if (evt.keyCode === 13) { | |
const user = evt.target.value; |
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 React, { Component, Fragment } from 'react'; | |
import axios from 'axios'; | |
import Pusher from 'pusher-js'; | |
class Chat extends Component { | |
state = { chats: [] } | |
componentDidMount() { | |
this.pusher = new Pusher(process.env.PUSHER_APP_KEY, { |
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 Layout from '../components/Layout'; | |
+ import Chat from '../components/Chat'; | |
+ import Layout from '../components/Layout'; | |
- <section className="col-md-4 position-relative d-flex flex-wrap h-100 align-items-start align-content-between bg-white px-0"></section> | |
+ <section className="col-md-4 position-relative d-flex flex-wrap h-100 align-items-start align-content-between bg-white px-0"> | |
+ { user && <Chat activeUser={user} /> } | |
+ </section> |
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
// server.get('*') is here ... | |
const chatHistory = { messages: [] }; | |
server.post('/message', (req, res, next) => { | |
const { user = null, message = '', timestamp = +new Date } = req.body; | |
const sentimentScore = sentiment(message).score; | |
const chat = { user, message, timestamp, sentiment: sentimentScore }; |
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 React, { Component } from 'react'; | |
class ChatMessage extends Component { | |
render() { | |
const { position = 'left', message } = this.props; | |
const isRight = position.toLowerCase() === 'right'; | |
const align = isRight ? 'text-right' : 'text-left'; | |
const justify = isRight ? 'justify-content-end' : 'justify-content-start'; |
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
// Module imports here ... | |
import ChatMessage from './ChatMessage'; | |
const SAD_EMOJI = [55357, 56864]; | |
const HAPPY_EMOJI = [55357, 56832]; | |
const NEUTRAL_EMOJI = [55357, 56848]; | |
// Chat component class here ... |