mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
remove repo
This commit is contained in:
@@ -152,7 +152,7 @@ function _resolveRepoJSON (targetPath) {
|
||||
function getAllRepoStats () {
|
||||
let data
|
||||
try {
|
||||
data = JSON.parse(localStorage.getItem('repositories'))
|
||||
data = JSON.parse(localStorage.getItem('repoStats'))
|
||||
if (!_.isArray(data)) {
|
||||
throw new Error('Data is corrupted. it must be an array.')
|
||||
}
|
||||
@@ -208,7 +208,7 @@ function addRepo (newRepo) {
|
||||
let resolveBoostrepoJSON = _resolveRepoJSON(path.resolve(targetPath, 'boostrepo.json'))
|
||||
return Promise.all([resolveDataDirectory, resolveBoostrepoJSON])
|
||||
})
|
||||
.then(function setLoalStorage (data) {
|
||||
.then(function saveToLocalStorage (data) {
|
||||
let dataPath = data[0]
|
||||
repoJSON = data[1]
|
||||
|
||||
@@ -260,6 +260,22 @@ function addRepo (newRepo) {
|
||||
})
|
||||
}
|
||||
|
||||
function removeRepo (repository) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
let repoStats = getAllRepoStats()
|
||||
let targetIndex = _.findIndex(repoStats, {key: repository.key})
|
||||
if (targetIndex > -1) {
|
||||
repoStats.splice(targetIndex, 1)
|
||||
}
|
||||
_saveAllRepoStats(repoStats)
|
||||
resolve(true)
|
||||
} catch (err) {
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getRepos () {
|
||||
let repoStats
|
||||
try {
|
||||
@@ -291,5 +307,6 @@ function getRepos () {
|
||||
export default {
|
||||
getAllRepoStats,
|
||||
addRepo,
|
||||
removeRepo,
|
||||
getRepos
|
||||
}
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
import React, { PropTypes } from 'react'
|
||||
import CSSModules from 'browser/lib/CSSModules'
|
||||
import styles from './Repository.styl'
|
||||
import actions from 'browser/main/actions'
|
||||
import RepositoryManager from 'browser/lib/RepositoryManager'
|
||||
|
||||
class Repository extends React.Component {
|
||||
handleUnlinkButtonClick (e) {
|
||||
let { dispatch, repository } = this.props
|
||||
|
||||
RepositoryManager.removeRepo(repository)
|
||||
.then(() => {
|
||||
dispatch(actions.removeRepo(repository))
|
||||
})
|
||||
}
|
||||
|
||||
render () {
|
||||
let { repository } = this.props
|
||||
|
||||
let folderElements = repository.folders.map((folder) => {
|
||||
return (
|
||||
<div
|
||||
@@ -38,6 +50,7 @@ class Repository extends React.Component {
|
||||
|
||||
<div styleName='header-control'>
|
||||
<button styleName='header-control-button'
|
||||
onClick={(e) => this.handleUnlinkButtonClick(e)}
|
||||
>
|
||||
<i className='fa fa-unlink'/>
|
||||
</button>
|
||||
@@ -69,7 +82,8 @@ Repository.propTypes = {
|
||||
folders: PropTypes.arrayOf(PropTypes.shape({
|
||||
name: PropTypes.string
|
||||
}))
|
||||
})
|
||||
}),
|
||||
dispatch: PropTypes.func
|
||||
}
|
||||
|
||||
export default CSSModules(Repository, styles)
|
||||
|
||||
@@ -10,42 +10,10 @@ import NewRepositoryModal from '../../modal/NewRepositoryModal'
|
||||
|
||||
const ipc = require('electron').ipcRenderer
|
||||
|
||||
const BRAND_COLOR = '#18AF90'
|
||||
const OSX = global.process.platform === 'darwin'
|
||||
|
||||
const preferenceTutorialElement = (
|
||||
<svg width='300' height='300' className='tutorial'>
|
||||
<text x='15' y='30' fill={BRAND_COLOR} fontSize='24'>Preference</text>
|
||||
<svg x='-30' y='-270' width='400' height='400'>
|
||||
<path fill='white' d='M165.9,297c5.3,0,10.6,0.1,15.8,0.1c3.3,0,7.7,0.8,10.7-1c2.3-1.4,3.1-4,4.5-6.2c3.5-5.5,9.6-5.2,14.6-1.9
|
||||
c4.6,3.1,8.7,8,8.4,13.8c-0.3,5.2-3.3,10.1-6.1,14.3c-3.1,4.7-6.6,7-12.2,7.9c-5.2,0.8-11.7,1.6-15.4-3
|
||||
c-6.6-8.2,2.1-20.5,7.4-27.1c6.5-8.1,20.1-14,26.4-2.1c5.4,10.3-3.1,21.7-13,24.8c-5.7,1.8-11,0.9-16.2-1.9c-2-1.1-5-2.6-6.6-4.4
|
||||
c-3.9-4.3-0.3-8.2,2.5-11.2c1.3-1.4-0.8-3.6-2.1-2.1c-2.7,2.9-5.8,6.6-5.1,10.9c0.7,4.4,5.6,6.9,9,8.9c8.6,5.1,18.7,4.8,26.8-1.2
|
||||
c7.3-5.4,11.6-15,8-23.7c-3.3-8.1-11.7-11.8-20-9c-12.5,4.1-33.7,33.5-15.9,43.1c6.8,3.7,19.8,1.8,25.3-3.6
|
||||
c6.1-5.8,12.1-17.2,9.5-25.7c-2.6-8.4-13.7-17-22.6-13.3c-1.6,0.7-3,1.7-4.1,3c-1.6,1.9-2.2,5.1-4.1,6.6c-3.1,2.4-10.1,1-13.7,1
|
||||
c-4,0-7.9,0-11.9-0.1C164,294,164,297,165.9,297L165.9,297z'/>
|
||||
</svg>
|
||||
</svg>
|
||||
)
|
||||
|
||||
const newFolderTutorialElement = (
|
||||
<svg width='800' height='500' className='tutorial'>
|
||||
<text x='30' y='110' fill={BRAND_COLOR} fontSize='24'>Create a new folder!!</text>
|
||||
<text x='50' y='135' fill={BRAND_COLOR} fontSize='16'>{'press ' + (OSX ? '`⌘ + Shift + n`' : '`^ + Shift + n`')}</text>
|
||||
<svg x='50' y='10' width='300' height='400'>
|
||||
<path fill='white' d='M94.1,10.9C77.7,15.6,62,22.7,47.8,32.1c-13.6,9-27.7,20.4-37.1,33.9c-1.1,1.6,1.5,3.1,2.6,1.5
|
||||
C22.6,54.1,37,42.7,50.6,33.8c13.7-8.8,28.6-15.5,44.2-20C96.7,13.3,95.9,10.4,94.1,10.9L94.1,10.9z'/>
|
||||
<path fill='white' d='M71.1,8.6c7.9,1.6,15.8,3.2,23.6,4.7c-0.1-0.9-0.2-1.8-0.4-2.7c-4.6,3.4-5.4,7.7-4.4,13.2
|
||||
c0.8,4.4,0.8,10.9,5.6,12.8c1.8,0.7,2.6-2.2,0.8-2.9c-2.3-1-2.6-6.2-3-8.3c-0.9-4.5-1.7-9,2.5-12.1c0.9-0.7,1-2.5-0.4-2.7
|
||||
C87.5,9,79.6,7.4,71.8,5.9C70,5.4,69.2,8.3,71.1,8.6L71.1,8.6z'/>
|
||||
</svg>
|
||||
</svg>
|
||||
)
|
||||
|
||||
class SideNav extends React.Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
this.newFolderHandler = e => {
|
||||
this.newFolderHandler = (e) => {
|
||||
if (isModalOpen()) return true
|
||||
this.handleNewFolderButton(e)
|
||||
}
|
||||
@@ -69,7 +37,7 @@ class SideNav extends React.Component {
|
||||
}
|
||||
|
||||
handleFolderButtonClick (name) {
|
||||
return e => {
|
||||
return (e) => {
|
||||
let { dispatch } = this.props
|
||||
dispatch(actions.switchFolder(name))
|
||||
}
|
||||
@@ -85,11 +53,12 @@ class SideNav extends React.Component {
|
||||
}
|
||||
|
||||
render () {
|
||||
let { repositories } = this.props
|
||||
let { repositories, dispatch } = this.props
|
||||
let repositorieElements = repositories.map((repo) => {
|
||||
return <Repository
|
||||
key={repo.name}
|
||||
repository={repo}
|
||||
dispatch={dispatch}
|
||||
/>
|
||||
})
|
||||
|
||||
|
||||
@@ -164,6 +164,13 @@ export function addRepo (data) {
|
||||
}
|
||||
}
|
||||
|
||||
export function removeRepo (data) {
|
||||
return {
|
||||
type: 'REMOVE_REPOSITORY',
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
updateUser,
|
||||
|
||||
@@ -188,5 +195,6 @@ export default {
|
||||
toggleTutorial,
|
||||
|
||||
// v0.6.*
|
||||
addRepo
|
||||
addRepo,
|
||||
removeRepo
|
||||
}
|
||||
|
||||
@@ -332,12 +332,22 @@ import RepositoryManager from 'browser/lib/RepositoryManager'
|
||||
const initialRepositories = RepositoryManager.getRepos()
|
||||
|
||||
function repositories (state = initialRepositories, action) {
|
||||
console.log(state)
|
||||
switch (action.type) {
|
||||
case 'ADD_REPOSITORY':
|
||||
let repos = state.slice()
|
||||
repos.push(action.data)
|
||||
return repos
|
||||
{
|
||||
let repos = state.slice()
|
||||
repos.push(action.data)
|
||||
return repos
|
||||
}
|
||||
case 'REMOVE_REPOSITORY':
|
||||
{
|
||||
let repos = state.slice()
|
||||
let targetIndex = _.findIndex(repos, {key: action.data.key})
|
||||
if (targetIndex > -1) {
|
||||
repos.splice(targetIndex, 1)
|
||||
}
|
||||
return repos
|
||||
}
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user