Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitignore
Empty file.
4 changes: 4 additions & 0 deletions frontend/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["es2015", "react"],
"plugins": ["transform-object-rest-spread"]
}
21 changes: 21 additions & 0 deletions frontend/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"rules": {
"no-console": "off",
"indent": [ "error", 2 ],
"quotes": [ "error", "single" ],
"semi": ["error", "always"],
"linebreak-style": [ "error", "unix" ]
},
"env": {
"es6": true,
"node": true,
"mocha": true,
"jasmine": true
},
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true,
"impliedStrict": true
},
"extends": "eslint:recommended"
}
70 changes: 70 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Created by https://www.gitignore.io/api/osx,linux,node,vim
node_modules
.env
.test.env
db/
build/

.DS_Store
.AppleDouble
.LSOverride

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*


### Node ###
# Logs
logs
*.log
npm-debug.log*
.tern-project

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

### Vim ###
# swap
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# session
Session.vim
# temporary
.netrwhist
*~

# auto-generated tag files
tags
39 changes: 39 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "frontend",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"build": "webpack",
"watch": "webpack-dev-server --inline --hot"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"clean-webpack-plugin": "^0.1.16",
"css-loader": "^0.28.7",
"dotenv": "^4.0.0",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2",
"html-webpack-plugin": "^2.30.1",
"node-sass": "^4.5.3",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-redux": "^5.0.6",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"redux": "^3.7.2",
"sass-loader": "^6.0.6",
"superagent": "^3.6.0",
"uglifyjs-webpack-plugin": "^0.4.6",
"url-loader": "^0.5.9",
"webpack": "^3.5.6",
"webpack-dev-server": "^2.7.1"
}
}
35 changes: 35 additions & 0 deletions frontend/src/action/auth-actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import superagent from 'superagent';

export const tokenSet = (token) => ({
type: 'TOKEN_SET',
payload: token
})

export const tokenDelete = () => ({
type: 'TOKEN_DELETE'
})

export const signupRequest = (user) => (dispatch) => {
return superagent.post(`${__API_URL__}/signup`)
.withCredentials()
.send(user)
.then( res => {
dispatch(tokenSet(res.text));
try {
localStorage.token = res.text;
} catch (err) {
console.log(err);
}
return res;
})
}

export const loginRequest = (user) => (dispatch) => {
return superagent.get(`${__API_URL__}/login`)
.withCredentials()
.auth(user.username, user.password)
.then(res => {
dispatch(tokenSet(res.text))
return res;
})
}
34 changes: 34 additions & 0 deletions frontend/src/component/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import {Provider} from 'react-redux';
import {BrowserRouter, Route, Link} from 'react-router-dom';
import appStoreCreate from '../../lib/app-create-store.js';
import LandingContainer from '../landing-container';

let store = appStoreCreate();

class App extends React.Component {
render() {
return (
<div className='cfgram'>
<Provider store={store}>
<BrowserRouter>
<section>
<header>
<h1>cfgram</h1>
<nav>
<ul>
<li><Link to='/welcome/signup'>signup</Link></li>
<li><Link to='/welcome/login'>login</Link></li>
</ul>
</nav>
</header>
<Route path='/welcome/:auth' component={LandingContainer} />
</section>
</BrowserRouter>
</Provider>
</div>
)
}
}

export default App;
91 changes: 91 additions & 0 deletions frontend/src/component/auth-form/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React from 'react';
import * as util from '../../lib/util.js';

class AuthForm extends React.Component {
constructor(props) {
super(props);
this.state = {
username: '',
email: '',
password: '',
usernameError: null,
passwordError: null,
emailError: null,
error: null
}

this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}

handleChange(e) {
let {name, value} = e.target;

this.setState({
[name]: value,
usernameError: name === 'username' && !value ? 'username required' : null,
emailError: name === 'email' && !value ? 'email required' : null,
passwordError: name === 'password' && !value ? 'password required' : null
})
}

handleSubmit(e) {
e.preventDefault();
this.props.onComplete(this.state)
.then(() => {
this.setState({ username: '', email: '', password: ''})
})
.catch(error => {
console.error(error);
this.setState({error});
})
}

render() {
return (
<form
onSubmit={this.handleSubmit}
className='user-form'>

{util.renderIf(this.props.auth === 'signup',
<input
type='text'
name='email'
placeholder='email'
value={this.state.email}
onChange={this.handleChange} />
)}

{util.renderIf(this.state.usernameError,
<span className='tooltip'>
{this.state.usernameError}
</span>
)}

<input
type='text'
name='username'
placeholder='username'
value={this.state.username}
onChange={this.handleChange} />

{util.renderIf(this.state.passwordError,
<span className='tooltip'>
{this.state.passwordError}
</span>
)}

<input
type='password'
name='password'
placeholder='enter pw'
value={this.state.password}
onChange={this.handleChange} />

<button type='submit'>{this.props.auth}</button>
</form>
)
}
}

export default AuthForm;
30 changes: 30 additions & 0 deletions frontend/src/component/landing-container/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import {connect} from 'react-redux';
import AuthForm from '../auth-form';
import {signupRequest, loginRequest} from '../../action/auth-actions.js';
import * as util from '../../lib/util.js';

class LandingContainer extends React.Component {
render() {
let {params} = this.props.match;

let handleComplete = params === 'auth' ? this.props.login :this.props.signup

return (
<div>
<AuthForm
auth={params.auth}
onComplete={handleComplete} />
</div>
)
}
}

let mapDispatchToProps = (dispatch) => {
return {
signup: (user) => dispatch(signupRequest(user)),
login: (user) => dispatch(loginRequest(user))
}
}

export default connect(undefined, mapDispatchToProps)(LandingContainer);
10 changes: 10 additions & 0 deletions frontend/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>cfgram</title>
</head>
<body>
<div id='root'></div>
</body>
</html>
9 changes: 9 additions & 0 deletions frontend/src/lib/app-create-store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import reducer from '../reducer';
import thunk from './redux-thunk.js';
import reporter from './redux-reporter.js';
import {createStore, applyMiddleware} from 'redux';

let appStoreCreate = () =>
createStore(reducer, applyMiddleware(thunk, reporter))

export default appStoreCreate;
15 changes: 15 additions & 0 deletions frontend/src/lib/redux-reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let reporter = store => next => action => {
console.log('__ACTION__', action);

try {
let result = next(action);
console.log('__STATE__', store.getState());
return result;
} catch (error) {
error.action = action;
console.error('__ERROR__', error);
return error;
}
}

export default reporter;
5 changes: 5 additions & 0 deletions frontend/src/lib/redux-thunk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//gives us the ability to create an action creater that deals with async ajax requests
export default store => next => action =>
typeof action === 'function' //functions are async actions
? action(store.dispatch, store.getState)
: next(action)
22 changes: 22 additions & 0 deletions frontend/src/lib/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const log = (...arg) =>
__DEBUG__ ? console.log(...args) : undefined;

export const logError = (...args) =>
__DEBUG__ ? console.error(...args) : undefined;

export const renderIf = (test, component) => test ? component : undefined;

export const classToggler = (options) =>
Object.keys(options).filter(key => !!options[key]).join(' ');

export const map = (list, ...args) =>
Array.prototype.map.apply(list, args);

export const filter = (list, ...args) =>
Array.prototype.filter.apply(list, args);

export const reduce = (list, ...args) =>
Array.prototype.reduce.apply(list, args);


//these are just helpful methods, shortcuts kinda
Loading