mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Add: Log in / Sign upの時にエラーが出たらAlertを表示する
Debug: Tray Icon, PopUpWindow, Menuがいつの間にか消える
This commit is contained in:
@@ -12,7 +12,7 @@ module.exports = React.createClass({
|
|||||||
var index = this.props.articles.indexOf(this.props.currentArticle)
|
var index = this.props.articles.indexOf(this.props.currentArticle)
|
||||||
var el = React.findDOMNode(this)
|
var el = React.findDOMNode(this)
|
||||||
var li = el.querySelectorAll('li')[index]
|
var li = el.querySelectorAll('li')[index]
|
||||||
|
|
||||||
if (li == null) {
|
if (li == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ var Link = ReactRouter.Link
|
|||||||
|
|
||||||
var AuthActions = require('../Actions/AuthActions')
|
var AuthActions = require('../Actions/AuthActions')
|
||||||
|
|
||||||
|
var AuthStore = require('../Stores/AuthStore')
|
||||||
|
|
||||||
var OnlyGuest = require('../Mixins/OnlyGuest')
|
var OnlyGuest = require('../Mixins/OnlyGuest')
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
@@ -11,14 +13,50 @@ module.exports = React.createClass({
|
|||||||
getInitialState: function () {
|
getInitialState: function () {
|
||||||
return {
|
return {
|
||||||
email: '',
|
email: '',
|
||||||
password: ''
|
password: '',
|
||||||
|
authenticationFailed: false,
|
||||||
|
connectionFailed: false,
|
||||||
|
isSending: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
componentDidMount: function () {
|
||||||
|
this.unsubscribe = AuthStore.listen(this.onListen)
|
||||||
|
},
|
||||||
|
componentWillUnmount: function () {
|
||||||
|
this.unsubscribe()
|
||||||
|
},
|
||||||
|
onListen: function (res) {
|
||||||
|
if (res.status === 'failedToLogIn') {
|
||||||
|
if (res.data.status === 401) {
|
||||||
|
// Wrong E-mail or Password
|
||||||
|
this.setState({
|
||||||
|
authenticationFailed: true,
|
||||||
|
connectionFailed: false,
|
||||||
|
isSending: false
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Connection Failed or Whatever
|
||||||
|
this.setState({
|
||||||
|
authenticationFailed: false,
|
||||||
|
connectionFailed: true,
|
||||||
|
isSending: false
|
||||||
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleSubmit: function (e) {
|
handleSubmit: function (e) {
|
||||||
AuthActions.login({
|
this.setState({
|
||||||
email: this.state.email,
|
authenticationFailed: false,
|
||||||
password: this.state.password
|
connectionFailed: false,
|
||||||
|
isSending: true
|
||||||
|
}, function () {
|
||||||
|
AuthActions.login({
|
||||||
|
email: this.state.email,
|
||||||
|
password: this.state.password
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
@@ -46,6 +84,19 @@ module.exports = React.createClass({
|
|||||||
<div className='form-group'>
|
<div className='form-group'>
|
||||||
<input className='stripInput' valueLink={this.linkState('password')} onChange={this.handleChange} type='password' placeholder='Password'/>
|
<input className='stripInput' valueLink={this.linkState('password')} onChange={this.handleChange} type='password' placeholder='Password'/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{this.state.isSending ? (
|
||||||
|
<p className='alertInfo'>Logging in...</p>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{this.state.connectionFailed ? (
|
||||||
|
<p className='alertError'>Please try again.</p>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{this.state.authenticationFailed ? (
|
||||||
|
<p className='alertError'>Wrong E-mail or Password.</p>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<div className='form-group'>
|
<div className='form-group'>
|
||||||
<button className='logInButton' type='submit'>Log In</button>
|
<button className='logInButton' type='submit'>Log In</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ var Link = ReactRouter.Link
|
|||||||
|
|
||||||
var AuthActions = require('../Actions/AuthActions')
|
var AuthActions = require('../Actions/AuthActions')
|
||||||
|
|
||||||
|
var AuthStore = require('../Stores/AuthStore')
|
||||||
|
|
||||||
var OnlyGuest = require('../Mixins/OnlyGuest')
|
var OnlyGuest = require('../Mixins/OnlyGuest')
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
@@ -13,15 +15,74 @@ module.exports = React.createClass({
|
|||||||
email: '',
|
email: '',
|
||||||
password: '',
|
password: '',
|
||||||
name: '',
|
name: '',
|
||||||
profileName: ''
|
profileName: '',
|
||||||
|
connectionFailed: false,
|
||||||
|
emailConflicted: false,
|
||||||
|
nameConflicted: false,
|
||||||
|
validationFailed: false,
|
||||||
|
isSending: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
componentDidMount: function () {
|
||||||
|
this.unsubscribe = AuthStore.listen(this.onListen)
|
||||||
|
},
|
||||||
|
componentWillUnmount: function () {
|
||||||
|
this.unsubscribe()
|
||||||
|
},
|
||||||
|
onListen: function (res) {
|
||||||
|
if (res.status === 'failedToRegister') {
|
||||||
|
if (res.data.status === 409) {
|
||||||
|
// Confliction
|
||||||
|
var emailConflicted = res.data.body.errors[0].path === 'email'
|
||||||
|
var nameConflicted = res.data.body.errors[0].path === 'name'
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
connectionFailed: false,
|
||||||
|
emailConflicted: emailConflicted,
|
||||||
|
nameConflicted: nameConflicted,
|
||||||
|
validationFailed: false,
|
||||||
|
isSending: false
|
||||||
|
})
|
||||||
|
return
|
||||||
|
} else if (res.data.status === 422) {
|
||||||
|
this.setState({
|
||||||
|
connectionFailed: false,
|
||||||
|
emailConflicted: false,
|
||||||
|
nameConflicted: false,
|
||||||
|
validationFailed: {
|
||||||
|
errors: res.data.body.errors.map(function (error) {
|
||||||
|
return error.path
|
||||||
|
})
|
||||||
|
},
|
||||||
|
isSending: false
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Connection Failed or Whatever
|
||||||
|
this.setState({
|
||||||
|
connectionFailed: true,
|
||||||
|
emailConflicted: false,
|
||||||
|
nameConflicted: false,
|
||||||
|
validationFailed: false,
|
||||||
|
isSending: false
|
||||||
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleSubmit: function (e) {
|
handleSubmit: function (e) {
|
||||||
AuthActions.register({
|
this.setState({
|
||||||
email: this.state.email,
|
connectionFailed: false,
|
||||||
password: this.state.password,
|
emailConflicted: false,
|
||||||
name: this.state.name,
|
nameConflicted: false,
|
||||||
profileName: this.state.profileName
|
validationFailed: false,
|
||||||
|
isSending: true
|
||||||
|
}, function () {
|
||||||
|
AuthActions.register({
|
||||||
|
email: this.state.email,
|
||||||
|
password: this.state.password,
|
||||||
|
name: this.state.name,
|
||||||
|
profileName: this.state.profileName
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -57,6 +118,27 @@ module.exports = React.createClass({
|
|||||||
<div className='form-group'>
|
<div className='form-group'>
|
||||||
<input className='stripInput' valueLink={this.linkState('profileName')} type='text' placeholder='Profile name'/>
|
<input className='stripInput' valueLink={this.linkState('profileName')} type='text' placeholder='Profile name'/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{this.state.isSending ? (
|
||||||
|
<p className='alertInfo'>Signing up...</p>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{this.state.connectionFailed ? (
|
||||||
|
<p className='alertError'>Please try again.</p>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{this.state.emailConflicted ? (
|
||||||
|
<p className='alertError'>E-mail already exists.</p>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{this.state.nameConflicted ? (
|
||||||
|
<p className='alertError'>Username already exists.</p>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{this.state.validationFailed ? (
|
||||||
|
<p className='alertError'>Please fill every field correctly: {this.state.validationFailed.errors.join(', ')}</p>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<div className='form-group'>
|
<div className='form-group'>
|
||||||
<button className='logInButton' type='submit'>Sign Up</button>
|
<button className='logInButton' type='submit'>Sign Up</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -23,7 +23,10 @@ var AuthStore = Reflux.createStore({
|
|||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
this.trigger(null)
|
this.trigger({
|
||||||
|
status: 'failedToLogIn',
|
||||||
|
data: res
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,8 +47,11 @@ var AuthStore = Reflux.createStore({
|
|||||||
.set('Accept', 'application/json')
|
.set('Accept', 'application/json')
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err)
|
console.error(res)
|
||||||
this.trigger(null)
|
this.trigger({
|
||||||
|
status: 'failedToRegister',
|
||||||
|
data: res
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,8 +54,18 @@
|
|||||||
form
|
form
|
||||||
width 400px
|
width 400px
|
||||||
margin 0 auto 45px
|
margin 0 auto 45px
|
||||||
|
.alertInfo, .alertError
|
||||||
|
margin-top 15px
|
||||||
|
margin-bottom 15px
|
||||||
|
height 44px
|
||||||
|
text-align center
|
||||||
|
border-radius 22px
|
||||||
|
.alertInfo
|
||||||
|
alertInfo()
|
||||||
|
.alertError
|
||||||
|
alertError()
|
||||||
div.form-group:last-child
|
div.form-group:last-child
|
||||||
margin-top 45px
|
margin-top 15px
|
||||||
button.logInButton
|
button.logInButton
|
||||||
btnPrimary()
|
btnPrimary()
|
||||||
height 44px
|
height 44px
|
||||||
|
|||||||
18
browser/styles/mixins/alert.styl
Normal file
18
browser/styles/mixins/alert.styl
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
alert()
|
||||||
|
line-height 44px
|
||||||
|
border-radius 5px
|
||||||
|
|
||||||
|
alertSuccess()
|
||||||
|
alert()
|
||||||
|
background-color successBackgroundColor
|
||||||
|
color successTextColor
|
||||||
|
|
||||||
|
alertError()
|
||||||
|
alert()
|
||||||
|
background-color errorBackgroundColor
|
||||||
|
color errorTextColor
|
||||||
|
|
||||||
|
alertInfo()
|
||||||
|
alert()
|
||||||
|
background-color infoBackgroundColor
|
||||||
|
color infoTextColor
|
||||||
@@ -175,8 +175,6 @@
|
|||||||
width 250px
|
width 250px
|
||||||
.alertSuccess, .alertError, .alertInfo
|
.alertSuccess, .alertError, .alertInfo
|
||||||
float right
|
float right
|
||||||
line-height 44px
|
|
||||||
border-radius 5px
|
|
||||||
transition 0.1s
|
transition 0.1s
|
||||||
overflow hidden
|
overflow hidden
|
||||||
white-space nowrap
|
white-space nowrap
|
||||||
@@ -185,14 +183,11 @@
|
|||||||
&.hide
|
&.hide
|
||||||
width 0
|
width 0
|
||||||
.alertSuccess
|
.alertSuccess
|
||||||
background-color successBackgroundColor
|
alertSuccess()
|
||||||
color successTextColor
|
|
||||||
.alertError
|
.alertError
|
||||||
background-color errorBackgroundColor
|
alertError()
|
||||||
color errorTextColor
|
|
||||||
.alertInfo
|
.alertInfo
|
||||||
background-color infoBackgroundColor
|
alertInfo()
|
||||||
color infoTextColor
|
|
||||||
.saveButton
|
.saveButton
|
||||||
float right
|
float right
|
||||||
.contact
|
.contact
|
||||||
@@ -213,8 +208,6 @@
|
|||||||
float right
|
float right
|
||||||
.alertSuccess, .alertError, .alertInfo
|
.alertSuccess, .alertError, .alertInfo
|
||||||
float right
|
float right
|
||||||
line-height 44px
|
|
||||||
border-radius 5px
|
|
||||||
transition 0.1s
|
transition 0.1s
|
||||||
overflow hidden
|
overflow hidden
|
||||||
white-space nowrap
|
white-space nowrap
|
||||||
@@ -223,14 +216,11 @@
|
|||||||
&.hide
|
&.hide
|
||||||
width 0
|
width 0
|
||||||
.alertSuccess
|
.alertSuccess
|
||||||
background-color successBackgroundColor
|
alertSuccess()
|
||||||
color successTextColor
|
|
||||||
.alertError
|
.alertError
|
||||||
background-color errorBackgroundColor
|
alertError()
|
||||||
color errorTextColor
|
|
||||||
.alertInfo
|
.alertInfo
|
||||||
background-color infoBackgroundColor
|
alertInfo()
|
||||||
color infoTextColor
|
|
||||||
.info
|
.info
|
||||||
text-align left
|
text-align left
|
||||||
.infoLabel
|
.infoLabel
|
||||||
|
|||||||
9
main.js
9
main.js
@@ -6,6 +6,9 @@ var Tray = require('tray')
|
|||||||
require('crash-reporter').start()
|
require('crash-reporter').start()
|
||||||
|
|
||||||
var mainWindow = null
|
var mainWindow = null
|
||||||
|
var appIcon = null
|
||||||
|
var menu = null
|
||||||
|
var popUpWindow = null
|
||||||
|
|
||||||
// app.on('window-all-closed', function () {
|
// app.on('window-all-closed', function () {
|
||||||
// if (process.platform !== 'darwin') app.quit()
|
// if (process.platform !== 'darwin') app.quit()
|
||||||
@@ -15,11 +18,11 @@ app.on('ready', function () {
|
|||||||
// menu start
|
// menu start
|
||||||
var template = require('./modules/menu-template')
|
var template = require('./modules/menu-template')
|
||||||
|
|
||||||
var menu = Menu.buildFromTemplate(template)
|
menu = Menu.buildFromTemplate(template)
|
||||||
|
|
||||||
Menu.setApplicationMenu(menu)
|
Menu.setApplicationMenu(menu)
|
||||||
// menu end
|
// menu end
|
||||||
var appIcon = new Tray(__dirname + '/tray-icon.png')
|
appIcon = new Tray(__dirname + '/tray-icon.png')
|
||||||
appIcon.setToolTip('This is my application.')
|
appIcon.setToolTip('This is my application.')
|
||||||
appIcon.on('clicked', function () {
|
appIcon.on('clicked', function () {
|
||||||
if (mainWindow == null) {
|
if (mainWindow == null) {
|
||||||
@@ -38,7 +41,7 @@ app.on('ready', function () {
|
|||||||
mainWindow.show()
|
mainWindow.show()
|
||||||
})
|
})
|
||||||
|
|
||||||
var popUpWindow = new BrowserWindow({
|
popUpWindow = new BrowserWindow({
|
||||||
width: 600,
|
width: 600,
|
||||||
height: 400,
|
height: 400,
|
||||||
show: false,
|
show: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user