From 0637d6d6c45eab16792729c93a0fb59e9ebeadc2 Mon Sep 17 00:00:00 2001 From: Sarah Ahmad Date: Sun, 1 Sep 2019 13:35:22 -0500 Subject: [PATCH 1/5] rough draft of url docs before routes --- client/components/Editor.js | 8 +++++++- client/components/Form.js | 36 ++++++++++++++++++++++++++++++++++ client/components/index.js | 1 + client/components/user-home.js | 5 ++++- client/routes.js | 2 ++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 client/components/Form.js diff --git a/client/components/Editor.js b/client/components/Editor.js index f2321b7..997d7a1 100644 --- a/client/components/Editor.js +++ b/client/components/Editor.js @@ -20,7 +20,13 @@ export class Editor extends React.Component { } componentDidMount() { - this.doc = connection.get('demo', 'inputbox') + //this.doc = connection.get('demo', 'inputbox') + this.doc = connection.get( + this.props.match.params.user, + this.props.match.params.name + ) + console.log(this.doc.collection) + console.log(this.doc.id) this.doc.subscribe(err => { if (err) throw err diff --git a/client/components/Form.js b/client/components/Form.js new file mode 100644 index 0000000..0ac475e --- /dev/null +++ b/client/components/Form.js @@ -0,0 +1,36 @@ +import React from 'react' +import connection from '../connect' +import {withRouter} from 'react-router-dom' + +export class Form extends React.Component { + constructor(props) { + super(props) + + this.goto = this.goto.bind(this) + } + + componentDidMount() { + //stuff + } + goto(event) { + console.log(this.props.history) + //console.log(process.env.NODE_ENV) + //hardcoded link later do this better with routes and stuff :) + //so that we have one user friendly link + if (process.env.NODE_ENV === 'development') { + this.props.history.push('/doc1') + } else { + this.props.history.push( + 'https://code-share-code.herokuapp.com/document/doc1' + ) + } + } + + render() { + let main = + + return main + } +} + +export default withRouter(Form) diff --git a/client/components/index.js b/client/components/index.js index 8ee2f23..ffb2de9 100644 --- a/client/components/index.js +++ b/client/components/index.js @@ -8,3 +8,4 @@ export {default as UserHome} from './user-home' export {Login, Signup} from './auth-form' export {Editor} from './Editor' +export {Form} from './Form' diff --git a/client/components/user-home.js b/client/components/user-home.js index 8b0f1e0..6ad9ddc 100644 --- a/client/components/user-home.js +++ b/client/components/user-home.js @@ -3,6 +3,7 @@ import PropTypes from 'prop-types' import {connect} from 'react-redux' import {Editor} from './Editor' +import {Form} from './Form' /** * COMPONENT @@ -10,11 +11,13 @@ import {Editor} from './Editor' export const UserHome = props => { const {email} = props + const username = email.slice(0, email.indexOf('@')) return (

Welcome, {email}

- + {/* */} +
) } diff --git a/client/routes.js b/client/routes.js index 0f6f794..8b3e48c 100644 --- a/client/routes.js +++ b/client/routes.js @@ -4,6 +4,7 @@ import {withRouter, Route, Switch} from 'react-router-dom' import PropTypes from 'prop-types' import {Login, Signup, UserHome} from './components' import {me} from './store' +import {Editor} from './components/Editor' /** * COMPONENT @@ -25,6 +26,7 @@ class Routes extends Component { {/* Routes placed here are only available after logging in */} + )} {/* Displays our Login component as a fallback */} From 066b3566ce6a2cfadded11be3ddd4a67be67813b Mon Sep 17 00:00:00 2001 From: Sarah Ahmad Date: Sun, 1 Sep 2019 21:04:52 -0500 Subject: [PATCH 2/5] thunk will not work just a save for what does --- client/components/Editor.js | 3 +- client/components/Form.js | 36 --------------- client/components/MyForm.js | 81 ++++++++++++++++++++++++++++++++++ client/components/index.js | 2 +- client/components/user-home.js | 9 ++-- client/routes.js | 2 +- client/store/doc.js | 22 +++++++++ client/store/index.js | 4 +- server/api/docs.js | 25 +++++++++++ server/api/index.js | 1 + server/db/models/doc.js | 15 +++++++ server/db/models/index.js | 8 +++- server/db/sdb.js | 19 -------- 13 files changed, 163 insertions(+), 64 deletions(-) delete mode 100644 client/components/Form.js create mode 100644 client/components/MyForm.js create mode 100644 client/store/doc.js create mode 100644 server/api/docs.js create mode 100644 server/db/models/doc.js delete mode 100644 server/db/sdb.js diff --git a/client/components/Editor.js b/client/components/Editor.js index 997d7a1..4155046 100644 --- a/client/components/Editor.js +++ b/client/components/Editor.js @@ -20,10 +20,11 @@ export class Editor extends React.Component { } componentDidMount() { + console.log(this.props.match.params) //this.doc = connection.get('demo', 'inputbox') this.doc = connection.get( this.props.match.params.user, - this.props.match.params.name + this.props.match.params.docname ) console.log(this.doc.collection) console.log(this.doc.id) diff --git a/client/components/Form.js b/client/components/Form.js deleted file mode 100644 index 0ac475e..0000000 --- a/client/components/Form.js +++ /dev/null @@ -1,36 +0,0 @@ -import React from 'react' -import connection from '../connect' -import {withRouter} from 'react-router-dom' - -export class Form extends React.Component { - constructor(props) { - super(props) - - this.goto = this.goto.bind(this) - } - - componentDidMount() { - //stuff - } - goto(event) { - console.log(this.props.history) - //console.log(process.env.NODE_ENV) - //hardcoded link later do this better with routes and stuff :) - //so that we have one user friendly link - if (process.env.NODE_ENV === 'development') { - this.props.history.push('/doc1') - } else { - this.props.history.push( - 'https://code-share-code.herokuapp.com/document/doc1' - ) - } - } - - render() { - let main = - - return main - } -} - -export default withRouter(Form) diff --git a/client/components/MyForm.js b/client/components/MyForm.js new file mode 100644 index 0000000..3871904 --- /dev/null +++ b/client/components/MyForm.js @@ -0,0 +1,81 @@ +import React, {Component} from 'react' +import {connect} from 'react-redux' +import connection from '../connect' +import {withRouter} from 'react-router-dom' +import {updateDocThunk} from '../store/doc' +import {Container, Form as AForm, TextArea, Button} from 'semantic-ui-react' + +//Props has username availabe, so why dont we +//make a query to the database to check all documents +//with username and also +//make a thunk that posts new ones and routes to them here + +export class MyForm extends React.Component { + constructor(props) { + super(props) + + this.state = { + doc: '' + } + + this.handleChange = this.handleChange.bind(this) + this.handleSubmit = this.handleSubmit.bind(this) + } + + componentDidMount() { + //stuff + console.log(connection) + } + + handleChange(event) { + this.setState({ + [event.target.name]: event.target.value + }) + } + + handleSubmit(event) { + event.preventDefault() + console.log('you clicked me') + let userId = this.props.userId + let docname = this.state.doc + console.log(this.props) + console.log(this.state) + console.log(this.props.match) + + //this.props.postDoc(userId, docname) + // this.props.history.push(`/products/${productId}`) + } + + render() { + let main = ( + + +