mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
refactor file structure
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import superagent from 'superagent'
|
||||
import superagentPromise from 'superagent-promise'
|
||||
// import auth from 'boost/auth'
|
||||
|
||||
export const SERVER_URL = 'https://b00st.io/'
|
||||
// export const SERVER_URL = 'http://localhost:3333/'
|
||||
@@ -1,93 +0,0 @@
|
||||
import React, { PropTypes } from 'react'
|
||||
import { Link } from 'react-router'
|
||||
import linkState from 'boost/linkState'
|
||||
import { login } from 'boost/api'
|
||||
import auth from 'boost/auth'
|
||||
|
||||
export default class LoginPage extends React.Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
user: {},
|
||||
isSending: false,
|
||||
error: null
|
||||
}
|
||||
this.linkState = linkState
|
||||
}
|
||||
|
||||
handleSubmit (e) {
|
||||
e.preventDefault()
|
||||
this.setState({
|
||||
isSending: true,
|
||||
error: null
|
||||
}, function () {
|
||||
login(this.state.user)
|
||||
.then(res => {
|
||||
let { user, token } = res.body
|
||||
auth.user(user, token)
|
||||
|
||||
this.props.history.pushState('home')
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
if (err.code === 'ECONNREFUSED') {
|
||||
return this.setState({
|
||||
error: {
|
||||
name: 'CunnectionRefused',
|
||||
message: 'Can\'t cznnect to API server.'
|
||||
},
|
||||
isSending: false
|
||||
})
|
||||
} else if (err.status != null) {
|
||||
return this.setState({
|
||||
error: {
|
||||
name: err.response.body.name,
|
||||
message: err.response.body.message
|
||||
},
|
||||
isSending: false
|
||||
})
|
||||
}
|
||||
else throw err
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<div className='LoginContainer'>
|
||||
<img className='logo' src='../../resources/favicon-230x230.png'/>
|
||||
|
||||
<nav className='authNavigator text-center'>
|
||||
<Link to='/login' activeClassName='active'>Log In</Link> / <Link to='/signup' activeClassName='active'>Sign Up</Link>
|
||||
</nav>
|
||||
|
||||
<form onSubmit={e => this.handleSubmit(e)}>
|
||||
<div className='formField'>
|
||||
<input valueLink={this.linkState('user.email')} type='text' placeholder='E-mail'/>
|
||||
</div>
|
||||
<div className='formField'>
|
||||
<input valueLink={this.linkState('user.password')} onChange={this.handleChange} type='password' placeholder='Password'/>
|
||||
</div>
|
||||
|
||||
{this.state.isSending
|
||||
? (
|
||||
<p className='alertInfo'>Logging in...</p>
|
||||
) : null}
|
||||
|
||||
{this.state.error != null ? <p className='alertError'>{this.state.error.message}</p> : null}
|
||||
|
||||
<div className='formField'>
|
||||
<button className='logInButton' type='submit'>Log In</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
LoginPage.propTypes = {
|
||||
history: PropTypes.shape({
|
||||
pushState: PropTypes.func
|
||||
})
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
import React, { PropTypes } from 'react'
|
||||
import { Link } from 'react-router'
|
||||
import linkState from 'boost/linkState'
|
||||
import openExternal from 'boost/openExternal'
|
||||
import { signup } from 'boost/api'
|
||||
import auth from 'boost/auth'
|
||||
|
||||
export default class SignupContainer extends React.Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
user: {},
|
||||
connectionFailed: false,
|
||||
emailConflicted: false,
|
||||
nameConflicted: false,
|
||||
validationFailed: false,
|
||||
isSending: false,
|
||||
error: null
|
||||
}
|
||||
this.linkState = linkState
|
||||
this.openExternal = openExternal
|
||||
}
|
||||
|
||||
handleSubmit (e) {
|
||||
this.setState({
|
||||
isSending: true,
|
||||
error: null
|
||||
}, function () {
|
||||
signup(this.state.user)
|
||||
.then(res => {
|
||||
let { user, token } = res.body
|
||||
auth.user(user, token)
|
||||
|
||||
this.props.history.pushState('home')
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
if (err.code === 'ECONNREFUSED') {
|
||||
return this.setState({
|
||||
error: {
|
||||
name: 'CunnectionRefused',
|
||||
message: 'Can\'t connect to API server.'
|
||||
},
|
||||
isSending: false
|
||||
})
|
||||
} else if (err.status != null) {
|
||||
return this.setState({
|
||||
error: {
|
||||
name: err.response.body.name,
|
||||
message: err.response.body.message
|
||||
},
|
||||
isSending: false
|
||||
})
|
||||
}
|
||||
else throw err
|
||||
})
|
||||
})
|
||||
|
||||
e.preventDefault()
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<div className='SignupContainer'>
|
||||
<img className='logo' src='../../resources/favicon-230x230.png'/>
|
||||
|
||||
<nav className='authNavigator text-center'><Link to='/login' activeClassName='active'>Log In</Link> / <Link to='/signup' activeClassName='active'>Sign Up</Link></nav>
|
||||
|
||||
<form onSubmit={e => this.handleSubmit(e)}>
|
||||
<div className='formField'>
|
||||
<input valueLink={this.linkState('user.email')} type='text' placeholder='E-mail'/>
|
||||
</div>
|
||||
<div className='formField'>
|
||||
<input valueLink={this.linkState('user.password')} type='password' placeholder='Password'/>
|
||||
</div>
|
||||
<div className='formField'>
|
||||
<input valueLink={this.linkState('user.name')} type='text' placeholder='name'/>
|
||||
</div>
|
||||
<div className='formField'>
|
||||
<input valueLink={this.linkState('user.profileName')} type='text' placeholder='Profile name'/>
|
||||
</div>
|
||||
|
||||
{this.state.isSending ? (
|
||||
<p className='alertInfo'>Signing up...</p>
|
||||
) : null}
|
||||
|
||||
{this.state.error != null ? <p className='alertError'>{this.state.error.message}</p> : null}
|
||||
|
||||
<div className='formField'>
|
||||
<button className='logInButton' type='submit'>Sign Up</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<p className='alert'>会員登録することで、<a onClick={this.openExternal} href='http://boostio.github.io/regulations.html'>当サイトの利用規約</a>及び<a onClick={this.openExternal} href='http://boostio.github.io/privacypolicies.html'>Cookieの使用を含むデータに関するポリシー</a>に同意するものとします。</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
SignupContainer.propTypes = {
|
||||
history: PropTypes.shape({
|
||||
pushState: PropTypes.func
|
||||
})
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB |
@@ -1,89 +0,0 @@
|
||||
.LoginContainer, .SignupContainer
|
||||
margin 0 auto
|
||||
padding 105px 15px
|
||||
box-sizing border-box
|
||||
color inactiveTextColor
|
||||
.logo
|
||||
width 150px
|
||||
height 150px
|
||||
display block
|
||||
margin 0 auto
|
||||
.authNavigator
|
||||
margin 15px 0 25px
|
||||
a
|
||||
font-size 1.5em
|
||||
text-decoration none
|
||||
color inactiveTextColor
|
||||
&:hover, &.hover, &:active, &.active
|
||||
color brandColor
|
||||
.socialControl
|
||||
text-align center
|
||||
margin 25px 0
|
||||
p
|
||||
margin-bottom 25px
|
||||
.facebookBtn, .githubBtn
|
||||
margin 0 45px
|
||||
width 50px
|
||||
height 50px
|
||||
line-height 50px
|
||||
font-size 25px
|
||||
text-align center
|
||||
background-image none
|
||||
color white
|
||||
border none
|
||||
border-radius 25px
|
||||
cursor pointer
|
||||
.facebookBtn
|
||||
background-color facebookColor
|
||||
&:hover, &.hover
|
||||
background-color lighten(facebookColor, 25%)
|
||||
.githubBtn
|
||||
background-color githubBtn
|
||||
font-size 30px
|
||||
line-height 30px
|
||||
&:hover, &.hover
|
||||
background-color lighten(githubBtn, 25%)
|
||||
.divider
|
||||
.dividerLabel
|
||||
text-align center
|
||||
position relative
|
||||
top -27px
|
||||
font-size 1.3em
|
||||
background-color backgroundColor
|
||||
margin 0 auto
|
||||
width 50px
|
||||
form
|
||||
width 400px
|
||||
margin 0 auto 45px
|
||||
.alertInfo, .alertError
|
||||
margin-top 15px
|
||||
margin-bottom 15px
|
||||
padding 10px
|
||||
border-radius 5px
|
||||
line-height 1.6
|
||||
text-align center
|
||||
.alertInfo
|
||||
alertInfo()
|
||||
.alertError
|
||||
alertError()
|
||||
div.formField
|
||||
input
|
||||
stripInput()
|
||||
height 33px
|
||||
width 100%
|
||||
margin-bottom 10px
|
||||
text-align center
|
||||
font-size 1.1em
|
||||
&:last-child
|
||||
margin-top 15px
|
||||
button.logInButton
|
||||
btnPrimary()
|
||||
height 44px
|
||||
border-radius 22px
|
||||
display block
|
||||
width 200px
|
||||
font-size 1em
|
||||
margin 0 auto
|
||||
p.alert
|
||||
text-align center
|
||||
font-size 0.8em
|
||||
@@ -1,3 +0,0 @@
|
||||
// export const API_URL = 'http://localhost:8000/'
|
||||
export const API_URL = 'http://boost-api4.elasticbeanstalk.com/'
|
||||
// export API_URL 'https://api2.b00st.io/'
|
||||
34
lib/auth.js
34
lib/auth.js
@@ -1,34 +0,0 @@
|
||||
// initial value
|
||||
var currentUser = JSON.parse(localStorage.getItem('currentUser'))
|
||||
var currentToken = localStorage.getItem('token')
|
||||
|
||||
function user (user, newToken) {
|
||||
if (user != null) {
|
||||
localStorage.setItem('currentUser', JSON.stringify(user))
|
||||
currentUser = user
|
||||
}
|
||||
|
||||
if (newToken != null) {
|
||||
localStorage.setItem('token', newToken)
|
||||
currentToken = newToken
|
||||
}
|
||||
|
||||
return currentUser
|
||||
}
|
||||
|
||||
function token () {
|
||||
return currentToken
|
||||
}
|
||||
|
||||
function clear () {
|
||||
localStorage.removeItem('currentUser')
|
||||
localStorage.removeItem('token')
|
||||
currentUser = null
|
||||
currentToken = null
|
||||
}
|
||||
|
||||
export default {
|
||||
user,
|
||||
token,
|
||||
clear
|
||||
}
|
||||
@@ -96,16 +96,16 @@ var view = {
|
||||
BrowserWindow.getFocusedWindow().reload()
|
||||
}
|
||||
},
|
||||
// {
|
||||
// label: 'Toggle Developer Tools',
|
||||
// accelerator: (function () {
|
||||
// if (process.platform === 'darwin') return 'Alt+Command+I'
|
||||
// else return 'Ctrl+Shift+I'
|
||||
// })(),
|
||||
// click: function (item, focusedWindow) {
|
||||
// if (focusedWindow) BrowserWindow.getFocusedWindow().toggleDevTools()
|
||||
// }
|
||||
// }
|
||||
{
|
||||
label: 'Toggle Developer Tools',
|
||||
accelerator: (function () {
|
||||
if (process.platform === 'darwin') return 'Alt+Command+I'
|
||||
else return 'Ctrl+Shift+I'
|
||||
})(),
|
||||
click: function (item, focusedWindow) {
|
||||
if (focusedWindow) BrowserWindow.getFocusedWindow().toggleDevTools()
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
import { API_URL } from '../config'
|
||||
import socketio from 'socket.io-client'
|
||||
import auth from './auth'
|
||||
import store from './store'
|
||||
import { updateUser, updateArticle, destroyArticle, destroyFolder } from './actions'
|
||||
|
||||
export const CONN = 'CONN'
|
||||
export const ALERT = 'ALERT'
|
||||
export const USER_UPDATE = 'USER_UPDATE'
|
||||
export const ARTICLE_UPDATE = 'ARTICLE_UPDATE'
|
||||
export const ARTICLE_DESTROY = 'ARTICLE_DESTROY'
|
||||
export const FOLDER_DESTROY = 'FOLDER_DESTROY'
|
||||
|
||||
let io = socketio(API_URL)
|
||||
|
||||
io.on(CONN, function (data) {
|
||||
console.log('connected', data)
|
||||
|
||||
let token = auth.token()
|
||||
if (token != null) {
|
||||
io.emit('JOIN', {token})
|
||||
}
|
||||
})
|
||||
|
||||
io.on(ALERT, function (data) {
|
||||
console.log(ALERT, data)
|
||||
})
|
||||
|
||||
io.on(USER_UPDATE, function (data) {
|
||||
console.log(USER_UPDATE, data)
|
||||
let { user } = data
|
||||
store.dispatch(updateUser(user))
|
||||
})
|
||||
|
||||
io.on(FOLDER_DESTROY, function (data) {
|
||||
console.log(FOLDER_DESTROY, data)
|
||||
store.dispatch(destroyFolder(data.TeamId, data.FolderId))
|
||||
})
|
||||
|
||||
io.on(ARTICLE_UPDATE, function (data) {
|
||||
console.log(ARTICLE_UPDATE, data)
|
||||
let { userId, article } = data
|
||||
store.dispatch(updateArticle(userId, article))
|
||||
})
|
||||
|
||||
io.on(ARTICLE_DESTROY, function (data) {
|
||||
console.log(ARTICLE_DESTROY, data)
|
||||
let { userId, articleKey } = data
|
||||
store.dispatch(destroyArticle(userId, articleKey))
|
||||
})
|
||||
|
||||
export default io
|
||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Reference in New Issue
Block a user