1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

Url share done

This commit is contained in:
Rokt33r
2015-12-13 14:22:45 +09:00
parent a4c72a9a86
commit 24e2544544
11 changed files with 291 additions and 295 deletions

View File

@@ -146,3 +146,23 @@ export function toggleTutorial () {
type: TOGGLE_TUTORIAL
}
}
export default {
updateUser,
clearNewArticle,
updateArticle,
destroyArticle,
createFolder,
updateFolder,
destroyFolder,
replaceFolder,
switchFolder,
switchMode,
switchArticle,
setSearchFilter,
setTagFilter,
clearSearch,
lockStatus,
unlockStatus,
toggleTutorial
}

View File

@@ -1,8 +1,8 @@
import _ from 'lodash'
import moment from 'moment'
import keygen from 'boost/keygen'
import dataStore from 'boost/dataStore'
import { request, WEB_URL } from 'boost/api'
import clientKey from 'boost/clientKey'
const electron = require('electron')
const version = electron.remote.app.getVersion()
@@ -28,16 +28,6 @@ export function init () {
}
}
export function getClientKey () {
let clientKey = localStorage.getItem('clientKey')
if (!_.isString(clientKey) || clientKey.length !== 40) {
clientKey = keygen()
localStorage.setItem('clientKey', clientKey)
}
return clientKey
}
export function getAllRecords () {
return JSON.parse(localStorage.getItem('activityRecords'))
}
@@ -67,7 +57,7 @@ export function postRecords (data) {
console.log('posting...', records)
let input = {
clientKey: getClientKey(),
clientKey: clientKey.get(),
records
}
return request.post(WEB_URL + 'apis/activity')
@@ -142,6 +132,5 @@ export function emit (type, data = {}) {
export default {
init,
emit,
getClientKey,
postRecords
}

View File

@@ -1,191 +1,22 @@
import superagent from 'superagent'
import superagentPromise from 'superagent-promise'
import auth from 'boost/auth'
// import auth from 'boost/auth'
export const API_URL = 'http://boost-api4.elasticbeanstalk.com/'
export const WEB_URL = 'https://b00st.io/'
// export const WEB_URL = 'http://localhost:3333/'
// export const SERVER_URL = 'https://b00st.io/'
export const SERVER_URL = 'http://localhost:3333/'
export const request = superagentPromise(superagent, Promise)
export function login (input) {
export function shareWithPublicURL (input) {
return request
.post(API_URL + 'auth/login')
.send(input)
}
export function signup (input) {
return request
.post(API_URL + 'auth/register')
.send(input)
}
export function updateUserInfo (input) {
return request
.put(API_URL + 'auth/user')
.set({
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function updatePassword (input) {
return request
.post(API_URL + 'auth/password')
.set({
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function fetchCurrentUser () {
return request
.get(API_URL + 'auth/user')
.set({
Authorization: 'Bearer ' + auth.token()
})
}
export function fetchArticles (userId) {
return request
.get(API_URL + 'teams/' + userId + '/articles')
.set({
Authorization: 'Bearer ' + auth.token()
})
}
export function createArticle (input) {
return request
.post(API_URL + 'articles/')
.set({
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function saveArticle (input) {
return request
.put(API_URL + 'articles/' + input.id)
.set({
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function destroyArticle (articleId) {
return request
.del(API_URL + 'articles/' + articleId)
.set({
Authorization: 'Bearer ' + auth.token()
})
}
export function createTeam (input) {
return request
.post(API_URL + 'teams')
.set({
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function updateTeamInfo (teamId, input) {
return request
.put(API_URL + 'teams/' + teamId)
.set({
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function destroyTeam (teamId) {
return request
.del(API_URL + 'teams/' + teamId)
.set({
Authorization: 'Bearer ' + auth.token()
})
}
export function searchUser (key) {
return request
.get(API_URL + 'search/users')
.query({key: key})
}
export function setMember (teamId, input) {
return request
.post(API_URL + 'teams/' + teamId + '/members')
.set({
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function deleteMember (teamId, input) {
return request
.del(API_URL + 'teams/' + teamId + '/members')
.set({
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function createFolder (input) {
return request
.post(API_URL + 'folders/')
.set({
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function updateFolder (id, input) {
return request
.put(API_URL + 'folders/' + id)
.set({
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function destroyFolder (id) {
return request
.del(API_URL + 'folders/' + id)
.set({
Authorization: 'Bearer ' + auth.token()
})
}
export function sendEmail (input) {
return request
.post(API_URL + 'mail')
.set({
Authorization: 'Bearer ' + auth.token()
})
.post(SERVER_URL + 'apis/share')
// .set({
// Authorization: 'Bearer ' + auth.token()
// })
.send(input)
}
export default {
API_URL,
WEB_URL,
request,
login,
signup,
updateUserInfo,
updatePassword,
fetchCurrentUser,
fetchArticles,
createArticle,
saveArticle,
destroyArticle,
createTeam,
updateTeamInfo,
destroyTeam,
searchUser,
setMember,
deleteMember,
createFolder,
updateFolder,
destroyFolder,
sendEmail
SERVER_URL,
shareWithPublicURL
}

23
lib/clientKey.js Normal file
View File

@@ -0,0 +1,23 @@
import _ from 'lodash'
import keygen from 'boost/keygen'
function getClientKey () {
let clientKey = localStorage.getItem('clientKey')
if (!_.isString(clientKey) || clientKey.length !== 40) {
clientKey = keygen()
setClientKey(clientKey)
}
return clientKey
}
function setClientKey (newKey) {
localStorage.setItem('clientKey', newKey)
}
getClientKey()
export default {
get: getClientKey,
set: setClientKey
}

View File

@@ -1,85 +0,0 @@
import React, { PropTypes, findDOMNode } from 'react'
import linkState from 'boost/linkState'
import { sendEmail } from 'boost/api'
export default class ContactModal extends React.Component {
constructor (props) {
super(props)
this.linkState = linkState
this.state = {
isSent: false,
mail: {
title: '',
content: ''
}
}
}
onKeyCast (e) {
switch (e.status) {
case 'closeModal':
this.props.close()
break
case 'submitContactModal':
if (this.state.isSent) {
this.props.close()
return
}
this.sendEmail()
break
}
}
componentDidMount () {
findDOMNode(this.refs.title).focus()
}
sendEmail () {
sendEmail(this.state.mail)
.then(function (res) {
this.setState({isSent: !this.state.isSent})
}.bind(this))
.catch(function (err) {
console.error(err)
})
}
render () {
return (
<div className='ContactModal modal'>
<div className='modal-header'><h1>Contact form</h1></div>
{!this.state.isSent ? (
<div className='contactForm'>
<div className='modal-body'>
<div className='formField'>
<input ref='title' valueLink={this.linkState('mail.title')} placeholder='Title'/>
</div>
<div className='formField'>
<textarea valueLink={this.linkState('mail.content')} placeholder='Content'/>
</div>
</div>
<div className='modal-footer'>
<div className='formControl'>
<button onClick={this.sendEmail} className='sendButton'>Send</button>
<button onClick={this.props.close}>Cancel</button>
</div>
</div>
</div>
) : (
<div className='confirmation'>
<div className='confirmationMessage'>Thanks for sharing your opinion!</div>
<button className='doneButton' onClick={this.props.close}>Done</button>
</div>
)}
</div>
)
}
}
ContactModal.propTypes = {
close: PropTypes.func
}

View File

@@ -180,7 +180,9 @@ function articles (state = initialArticles, action) {
let targetIndex = _.findIndex(state, _article => article.key === _article.key)
if (targetIndex < 0) state.unshift(article)
else state.splice(targetIndex, 1, article)
else {
Object.assign(state[targetIndex], article)
}
if (article.status !== 'NEW') dataStore.setArticles(state)
else isCreatingNew = true