Skip to content

Commit

Permalink
Save conversations and notes separately #217
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardLitt committed Jul 15, 2015
1 parent b41944f commit 323d44b
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 98 deletions.
123 changes: 44 additions & 79 deletions build/main.min.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"./js/main.js":[function(require,module,exports){
/* globals chrome, localStorage */
/* globals chrome */
'use strict'


Expand Down Expand Up @@ -183,18 +183,8 @@ function buildView (options) {
console.log(options.protocols, !_.isEmpty(options.protocols))
}

var parent = (options.doctype === 'pdf') ? document : document.getElementById(sidebarId).contentDocument

if (localStorage.userId && localStorage.avatar) {
// TODO email and userId should not be synonymous.
options.account = {
'userId': localStorage.userId,
'avatar': localStorage.avatar,
'email': localStorage.userId
}
} else {
options.account = {}
}
var parent = (options.doctype === 'pdf') ? document :
document.getElementById(sidebarId).contentDocument

// Get Data
// // PDFJS will not execute the callback a second time. I've no idea why. There
Expand Down Expand Up @@ -267,6 +257,7 @@ function buildView (options) {
)
}


linkHandler()

if (options.doctype !== 'viewer') {
Expand Down Expand Up @@ -304,6 +295,7 @@ var Publication = require('./components/publication.jsx')
var Sidebar = require('./components/sidebar.jsx')
var PDFUrlLink = require('./components/pdfUrlLink.jsx')
var Slack = require('./components/slack.jsx').SendSlack
var Conversation = require('./components/conversation.jsx')
var Toolbar = require('./components/toolbar.jsx')
var Navbar = require('./components/navbar.jsx')
// var Comment = require('./components/comment.jsx')
Expand All @@ -318,8 +310,7 @@ var Navbar = require('./components/navbar.jsx')
// var Tags = require('./components/tags.jsx')
// var Toc = require('./components/toc.jsx')

var Conversation = require('./components/conversation.jsx')
// var note = require('./data/schema.js').note
// var conversation = require('./data/schema.js').conversation

// var account = require('./data/schema.js').account
// var publication = require('./data/schema.js').mediaPublication
Expand All @@ -331,25 +322,16 @@ module.exports = React.createClass({
pdfLocation: React.PropTypes.object,
fingerprint: React.PropTypes.object,
docType: React.PropTypes.string,
modules: React.PropTypes.object,
account: React.PropTypes.object
modules: React.PropTypes.object
},

// TODO Add in loading state so dummy data isn't needed here.
getInitialState: function () {
return {
'publication': null,
'showConversation': null,
'account': this.props.account
'publication': null
}
},

showConversation: function () {
this.setState({
'showConversation': !this.state.showConversation
})
},

componentWillMount: function () {
if (this.props.pdfLocation) {
PDFJS.readPDFText(this.props.pdfLocation, {'modules': this.props.modules}, function (err, data) {
Expand All @@ -368,34 +350,16 @@ module.exports = React.createClass({
},

render: function () {

var conversationComp = null

if (this.state.showConversation) {
conversationComp = React.createElement(Conversation, {account: this.state.account})
}

return (
React.createElement(Sidebar, null,

React.createElement(Navbar, {staticPath: this.props.staticPath, account: this.state.account}),

React.createElement(Toolbar, {location: this.props.pdfLocation, fingerprint: this.props.fingerprint, showConversation: this.showConversation}),
React.createElement(Navbar, {staticPath: this.props.staticPath}),

React.createElement(Publication, {eventKey: "1", data: this.state.publication}),
React.createElement(Toolbar, {location: this.props.pdfLocation, fingerprint: this.props.fingerprint}),

React.createElement("br", null),
React.createElement("br", null),
/* <Conversation conversation={conversation} /> */

conversationComp,

React.createElement("br", null),
React.createElement("br", null),
React.createElement("br", null),
React.createElement("br", null),
React.createElement("br", null),
React.createElement("br", null),
React.createElement("br", null),
React.createElement(Publication, {eventKey: "1", data: this.state.publication}),

React.createElement(EmailForm, {fingerprint: this.props.fingerprint}),
React.createElement(Slack, {fingerprint: this.props.fingerprint}),
Expand Down Expand Up @@ -462,28 +426,23 @@ var Sharing = require('./sharing.jsx')
var Conversation = React.createClass({
displayName: 'Conversation',
propTypes: {
conversation: React.PropTypes.object,
account: React.PropTypes.object
conversation: React.PropTypes.object
},
// TODO It seems to me that the title should be tied to the first note.
// As we have it, a conversation object has a title, but no text, just an array of notes
// I'm not sure this is right.
getInitialState: function () {
return {
submitted: false,
text: null, // this.props.conversation && this.props.conversation.text || 'Error: Text not found',
title: null, // this.props.conversation && this.props.conversation.title || 'No Title',
hideButton: false
submitted: true,
text: this.props.conversation.text || 'Error: Text not found',
title: this.props.conversation.title || 'No Title'
}
},
onClick: function () {
// TODO Add in db.put() call here. Perhaps on handleChange, too.

this.setState({ submitted: !this.state.submitted })
},
showForm: function () {
this.setState({hideButton: !this.state.hideButton})
},
handleTitle: function (event) {
this.setState({ title: event.target.value })
},
Expand All @@ -493,7 +452,6 @@ var Conversation = React.createClass({
},

render: function () {

var conversationStyle = {
margin: '5px 0px',
border: '1px solid #999',
Expand Down Expand Up @@ -528,19 +486,21 @@ var Conversation = React.createClass({

return (
React.createElement("div", {style: conversationStyle},
(this.state.submitted) ?

this.state.submitted ?
React.createElement("p", {style: titleStyle}, title) :
React.createElement("input", {type: "input", style: inputTitleStyle, placeholder: "Conversation Title", onChange: this.handleTitle, defaultValue: title}),


(this.state.submitted) ?
this.state.submitted ?
React.createElement("p", {style: textStyle}, text) :
React.createElement("textarea", {type: "input", style: inputTitleStyle, placeholder: "Share an insight", onChange: this.handleText, defaultValue: text}),


React.createElement(Sharing, {account: this.props.account}),
React.createElement(Sharing, null),

React.createElement("button", {className: "btn btn-default", style: submitButtonStyle, onClick: this.onClick}, "Start new conversation")

React.createElement("button", {className: "btn btn-default", style: submitButtonStyle, showForm: this.showForm, onClick: this.onClick}, "Start new conversation")
)
)
}
Expand Down Expand Up @@ -973,6 +933,7 @@ var Login = React.createClass({
module.exports = Login

},{"./oauthGoogleButton.jsx":"/Users/richard/src/beagle/js/components/oauthGoogleButton.jsx","react":"/Users/richard/src/beagle/node_modules/react/react.js"}],"/Users/richard/src/beagle/js/components/navbar.jsx":[function(require,module,exports){
/* globals localStorage */
'use strict'

var React = require('React')
Expand All @@ -982,13 +943,22 @@ var staticPath = require('../utilities/staticPath.js')
var Navbar = React.createClass({
displayName: 'Navbar',
propTypes: {
staticPath: React.PropTypes.string,
account: React.PropTypes.object
staticPath: React.PropTypes.string
},
getInitialState: function () {

function checkAvatar () {
if (localStorage.userId && localStorage.avatar) {
return localStorage.avatar
} else {
localStorage.removeItem('avatar')
return null
}
}

return {
'staticPath': staticPath(this.props.staticPath, 'images/noun_11582.png'),
'avatar': this.props.account.avatar
'avatar': checkAvatar()
}
},
setAvatar: function (val) {
Expand Down Expand Up @@ -1358,21 +1328,21 @@ var React = require('react')
var PermissionsDropdown = require('./permissionsDropdown.jsx')
var UserBar = require('./userBar.jsx')

var account = require('../data/schema.js').account

var Sharing = React.createClass({
displayName: 'Sharing',
propTypes: {
'account': React.PropTypes.object
},
getInitialState: function () {
return {}
return {
}
},
onClick: function () {
// TODO Add in db.put() call here
},

render: function () {
var conversationStyle = {
padding: '10px 0px'
padding: '10px 0px',
// borderTop: '2px solid #AE8DC7',
// borderBottom: '2px solid #AE8DC7'
}
Expand Down Expand Up @@ -1402,7 +1372,7 @@ var Sharing = React.createClass({
React.createElement("i", {className: "fa fa-plus"}), " Add"
),

React.createElement(UserBar, {secondaryText: "email", account: this.props.account})
React.createElement(UserBar, {secondaryText: "email", account: account})

)
)
Expand All @@ -1411,7 +1381,7 @@ var Sharing = React.createClass({

module.exports = exports = Sharing

},{"./permissionsDropdown.jsx":"/Users/richard/src/beagle/js/components/permissionsDropdown.jsx","./userBar.jsx":"/Users/richard/src/beagle/js/components/userBar.jsx","react":"/Users/richard/src/beagle/node_modules/react/react.js"}],"/Users/richard/src/beagle/js/components/sidebar.jsx":[function(require,module,exports){
},{"../data/schema.js":"/Users/richard/src/beagle/js/data/schema.js","./permissionsDropdown.jsx":"/Users/richard/src/beagle/js/components/permissionsDropdown.jsx","./userBar.jsx":"/Users/richard/src/beagle/js/components/userBar.jsx","react":"/Users/richard/src/beagle/node_modules/react/react.js"}],"/Users/richard/src/beagle/js/components/sidebar.jsx":[function(require,module,exports){
var React = require('react')
var Alert = require('./alert.jsx')

Expand Down Expand Up @@ -1594,28 +1564,23 @@ var React = require('react')
var ReactBootstrap = require('react-bootstrap')
var ButtonToolbar = ReactBootstrap.ButtonToolbar
var Button = ReactBootstrap.Button

var Highlight = require('./highlight.jsx')
var Screenshot = require('./screenshot.jsx')

var Toolbar = React.createClass({
displayName: 'Toolbar',
propTypes: {
location: React.PropTypes.object,
fingerprint: React.PropTypes.object,
showConversation: React.PropTypes.func
fingerprint: React.PropTypes.object
// notate: React.PropTypes.boolean,
// highlight: React.PropTypes.boolean,
// screenshot: React.PropTypes.boolean,
// flag: React.PropTypes.boolean
},
showConversation: function () {
this.props.showConversation()
},
render: function () {
return (
React.createElement(ButtonToolbar, null,
React.createElement(Button, {onClick: this.showConversation},
React.createElement(Button, null,
"Note"
),
React.createElement(Button, null,
Expand Down
32 changes: 30 additions & 2 deletions js/components/conversation.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var React = require('react')
var Sharing = require('./sharing.jsx')
var schema = require('../data/schema.js')

var Conversation = React.createClass({
displayName: 'Conversation',
Expand All @@ -15,11 +16,38 @@ var Conversation = React.createClass({
submitted: false,
text: null, // this.props.conversation && this.props.conversation.text || 'Error: Text not found',
title: null, // this.props.conversation && this.props.conversation.title || 'No Title',
hideButton: false
hideButton: false,
author: this.props.account
}
},
onClick: function () {
// TODO Add in db.put() call here. Perhaps on handleChange, too.
// Shim the author ID.
// TODO Make sure that userId and id should be the same
var author = {}
if (this.state.author) {
author.id = this.state.author.userId
} else {
// TODO Log in the user programmatically automatically
throw new Error('You must log in before saving a conversation')
}

var that = this

// Save the conversation
schema.startBlankConversation({
'title': this.state.title,
'text': this.state.text,
'author': author
}, function (err, data) {
if (err) {
console.log(err)
} else {
// TODO Should we save the conversation in the view somehow?
console.log(data)
that.setState({conversation: data.conversation})
that.setState({note: data.note})
}
})

this.setState({ submitted: !this.state.submitted })
},
Expand Down
Loading

0 comments on commit 323d44b

Please sign in to comment.