Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab nick #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
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"
}
136 changes: 136 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Created by https://www.gitignore.io/api/osx,vim,node,macos,windows

### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

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

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

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

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


### OSX ###

# Icon must end with two \r

# Thumbnails

# Files that might appear in the root of a volume

# Directories potentially created on remote AFP share

### Vim ###
# swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
# session
Session.vim
# temporary
.netrwhist
*~
# auto-generated tag files
tags

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/osx,vim,node,macos,windows
46 changes: 46 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "33-photo_uploads",
"version": "1.0.0",
"description": "![cf](https://i.imgur.com/7v5ASc8.png) 33: Photo Uploads ======",
"main": "index.js",
"scripts": {
"build": "webpack",
"watch": "webpack-dev-server --inline --hot"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nickjaz/33-photo_uploads.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/nickjaz/33-photo_uploads/issues"
},
"homepage": "https://github.com/nickjaz/33-photo_uploads#readme",
"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-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.5",
"webpack-dev-server": "^2.7.1"
}
}
30 changes: 30 additions & 0 deletions frontend/src/__test__/auth-reducer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import authReducer from '../reducer/auth.js';

describe('Auth Reducer', () => {
let state = {auth: '1234567890987654321'}

test('initial state should be null', () => {
let result = authReducer(undefined, {type: null});
expect(result).toEqual(null)
})

test('no action provided should return default state', () => {
let result = authReducer(state, {type: null});
expect(result).toEqual(state);
})

test('TOKEN_SET should return a token', () => {
let action = {
type: 'TOKEN_SET',
payload: 'sample token'
}

let result = authReducer({}, action);
expect(result).toBe(action.payload);
})

test('TOKEN_DELETE should return null', () => {
let result = authReducer(state, {type: 'TOKEN_DELETE'});
expect(result).toBe(null);
})
})
36 changes: 36 additions & 0 deletions frontend/src/action/auth-actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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.token;
} 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;
})
}
22 changes: 22 additions & 0 deletions frontend/src/action/profile-actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import superagent from 'superagent';

export const profileCreate = (profile) => ({
type: 'PROFILE_CREATE',
payload: profile
})

export const profileUpdate = (profile) => ({
type: 'PROFILE_UPDATE',
payload: profile
})

export const profileCreateRequest = (profile) => (dispatch, getState) => {
let {auth} = getState();
return superagent.post(`${__API_URL__}/profile`)
.set('Authorization', `Bearer ${auth}`)
.field('bio', profile.bio)
.attach( res => {
dispatch(dispatchCreate(res.body));
return res;
})
}
49 changes: 49 additions & 0 deletions frontend/src/component/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import {connect} from 'react-redux';
import {BrowserRouter, Route, Link} from 'react-router-dom';
import LandingContainer from '../landing-container';
import SettingsContainer from '../settings-container';
import * as util from '../../lib/util.js';
import {tokenSet} from '../../action/auth-actions.js';

class App extends React.Component {
componentDidMount() {
let token = util.readCookie('X-Sluggram-Token');
if(token) {
this.props.tokenSet(token);
}
}

render() {
return (
<div className='sluggram'>
<BrowserRouter>
<section>
<header>
<h1>Sluggram</h1>
<nav>
<ul>
<li><Link to='/welcome/signup'>signup</Link></li>
<li><Link to='/welcome/login'>login</Link></li>
<li><Link to='/settings'>settings</Link></li>
</ul>
</nav>
</header>
<Route exact path='/welcome/:auth' component={LandingContainer} />
<Route exact path='/settings' component={SettingsContainer} />
</section>
</BrowserRouter>
</div>
)
}
}

let mapStateToProps = (state) => ({
profile: state.profile
})

let mapDispatchToProps =(dispatch) => ({
tokenSet: (token) => dispatch(tokenSet(token))
})

export default connect(mapStateToProps, mapDispatchToProps)(App);
Loading