1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

add folder create

This commit is contained in:
Rokt33r
2015-10-24 21:32:53 +09:00
parent 911cfd8642
commit 5ed2dfccd1
5 changed files with 115 additions and 2 deletions

View File

@@ -356,6 +356,41 @@ iptFocusBorderColor = #369DCD
float right float right
width 145px width 145px
text-align center text-align center
&.newFolder
.folderName input
height 33px
border 1px solid transparent
border-radius 5px
padding 0 10px
font-size 14px
outline none
width 150px
&:hover
border-color borderColor
&:focus
border-color iptFocusBorderColor
.folderPublic select
height 33px
border 1px solid transparent
background-color white
outline none
display block
margin 0 auto
font-size 14px
&:hover
border-color borderColor
&:focus
border-color iptFocusBorderColor
.folderControl
button
border none
height 30px
margin-top 1.5px
font-size 14px
background-color transparent
color brandColor
&:hover
color lighten(brandColor, 10%)
&.FolderRow &.FolderRow
.folderName input .folderName input
height 33px height 33px
@@ -374,6 +409,7 @@ iptFocusBorderColor = #369DCD
outline none outline none
display block display block
margin 0 auto margin 0 auto
font-size 14px
&:focus &:focus
border-color iptFocusBorderColor border-color iptFocusBorderColor
.folderControl .folderControl

View File

@@ -3,6 +3,7 @@ export const USER_UPDATE = 'USER_UPDATE'
export const ARTICLE_REFRESH = 'ARTICLE_REFRESH' export const ARTICLE_REFRESH = 'ARTICLE_REFRESH'
export const ARTICLE_UPDATE = 'ARTICLE_UPDATE' export const ARTICLE_UPDATE = 'ARTICLE_UPDATE'
export const ARTICLE_DESTROY = 'ARTICLE_DESTROY' export const ARTICLE_DESTROY = 'ARTICLE_DESTROY'
export const FOLDER_DESTROY = 'FOLDER_DESTROY'
export const SWITCH_USER = 'SWITCH_USER' export const SWITCH_USER = 'SWITCH_USER'
export const SWITCH_FOLDER = 'SWITCH_FOLDER' export const SWITCH_FOLDER = 'SWITCH_FOLDER'
@@ -50,6 +51,13 @@ export function destroyArticle (userId, articleKey) {
} }
} }
export function destroyFolder (userId, folderId) {
return {
type: FOLDER_DESTROY,
data: { userId, folderId }
}
}
// Nav // Nav
export function switchUser (userId) { export function switchUser (userId) {
return { return {

View File

@@ -1,8 +1,18 @@
import React, { PropTypes } from 'react' import React, { PropTypes } from 'react'
import _ from 'lodash' import _ from 'lodash'
import FolderRow from './FolderRow' import FolderRow from './FolderRow'
import linkState from 'boost/linkState'
import api from 'boost/api'
export default class FolderSettingTab extends React.Component { export default class FolderSettingTab extends React.Component {
constructor (props) {
super(props)
this.state = {
name: '',
public: 0
}
}
getCurrentTeam (props) { getCurrentTeam (props) {
if (props == null) props = this.props if (props == null) props = this.props
@@ -13,6 +23,32 @@ export default class FolderSettingTab extends React.Component {
this.props.switchTeam(e.target.value) this.props.switchTeam(e.target.value)
} }
handleFolderPublicChange (e) {
this.setState({public: e.target.value})
}
handleSaveButtonClick (e) {
let team = this.getCurrentTeam()
let input = {
UserId: team.id,
name: this.state.name,
public: !!parseInt(this.state.public, 10)
}
api.createFolder(input)
.then(res => {
console.log(res.body)
this.setState({
name: '',
public: 0
})
})
.catch(err => {
if (err.status != null) throw err
else console.error(err)
})
}
renderTeamOptions () { renderTeamOptions () {
return this.props.teams.map(team => { return this.props.teams.map(team => {
return ( return (
@@ -49,6 +85,20 @@ export default class FolderSettingTab extends React.Component {
<div className='folderControl'>Edit/Delete</div> <div className='folderControl'>Edit/Delete</div>
</div> </div>
{folderElements} {folderElements}
<div className='newFolder'>
<div className='folderName'>
<input valueLink={this.linkState('name')} type='text' placeholder='New Folder'/>
</div>
<div className='folderPublic'>
<select value={this.state.public} onChange={e => this.handleFolderPublicChange(e)}>
<option value='0'>Private</option>
<option value='1'>Public</option>
</select>
</div>
<div className='folderControl'>
<button onClick={e => this.handleSaveButtonClick(e)} className='primary'>Add</button>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
@@ -61,3 +111,5 @@ FolderSettingTab.propTypes = {
teams: PropTypes.array, teams: PropTypes.array,
switchTeam: PropTypes.func switchTeam: PropTypes.func
} }
FolderSettingTab.prototype.linkState = linkState

View File

@@ -1,6 +1,6 @@
import { combineReducers } from 'redux' import { combineReducers } from 'redux'
import { findIndex } from 'lodash' import { findIndex } from 'lodash'
import { SWITCH_USER, SWITCH_FOLDER, SWITCH_MODE, SWITCH_ARTICLE, SET_SEARCH_FILTER, SET_TAG_FILTER, USER_UPDATE, ARTICLE_REFRESH, ARTICLE_UPDATE, ARTICLE_DESTROY, IDLE_MODE, CREATE_MODE } from './actions' import { SWITCH_USER, SWITCH_FOLDER, SWITCH_MODE, SWITCH_ARTICLE, SET_SEARCH_FILTER, SET_TAG_FILTER, USER_UPDATE, ARTICLE_REFRESH, ARTICLE_UPDATE, ARTICLE_DESTROY, FOLDER_DESTROY, IDLE_MODE, CREATE_MODE } from './actions'
import auth from 'boost/auth' import auth from 'boost/auth'
const initialStatus = { const initialStatus = {
@@ -116,6 +116,17 @@ function articles (state, action) {
state[teamKey] = articles state[teamKey] = articles
} }
return state return state
case FOLDER_DESTROY:
{
let { userId, folderId } = action.data
let teamKey = genKey(userId)
let articles = JSON.parse(localStorage.getItem(teamKey))
articles = articles.filter(article => article.FolderId !== folderId)
localStorage.setItem(teamKey, JSON.stringify(articles))
state[teamKey] = articles
}
return state
default: default:
if (state == null) return getInitialArticles() if (state == null) return getInitialArticles()
return state return state

View File

@@ -2,13 +2,14 @@ import { API_URL } from '../config'
import socketio from 'socket.io-client' import socketio from 'socket.io-client'
import auth from './auth' import auth from './auth'
import store from './store' import store from './store'
import { updateUser, updateArticle, destroyArticle } from './actions' import { updateUser, updateArticle, destroyArticle, destroyFolder } from './actions'
export const CONN = 'CONN' export const CONN = 'CONN'
export const ALERT = 'ALERT' export const ALERT = 'ALERT'
export const USER_UPDATE = 'USER_UPDATE' export const USER_UPDATE = 'USER_UPDATE'
export const ARTICLE_UPDATE = 'ARTICLE_UPDATE' export const ARTICLE_UPDATE = 'ARTICLE_UPDATE'
export const ARTICLE_DESTROY = 'ARTICLE_DESTROY' export const ARTICLE_DESTROY = 'ARTICLE_DESTROY'
export const FOLDER_DESTROY = 'FOLDER_DESTROY'
let io = socketio(API_URL) let io = socketio(API_URL)
@@ -31,6 +32,11 @@ io.on(USER_UPDATE, function (data) {
store.dispatch(updateUser(user)) 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) { io.on(ARTICLE_UPDATE, function (data) {
console.log(ARTICLE_UPDATE, data) console.log(ARTICLE_UPDATE, data)
let { userId, article } = data let { userId, article } = data