diff --git a/src/client/components/my-factoids.js b/src/client/components/my-factoids.js new file mode 100644 index 000000000..01b88044a --- /dev/null +++ b/src/client/components/my-factoids.js @@ -0,0 +1,38 @@ +const h = require('react-hyperscript'); +const { Link } = require('react-router-dom'); +const { Component } = require('react'); + + +class MyFactoids extends Component { + constructor(props){ + super(props); + + this.state = { + factoidsLoaded: false, + factoids: [] + }; + + fetch('/api/document/my-factoids').then(res => res.json()).then(factoids => this.setState({ + factoids: factoids, + factoidsLoaded: true + })); + } + render(){ + let factoids = this.state.factoids.map(factoid => { + return h('div', [ + h(Link, { className: 'plain-link', to: `/document/${factoid.id}/${factoid.secret}`}, 'untitled factoid') + ]); + }); + + let content = this.state.factoidsLoaded ? h('div.factoid-list', [ + h('h2', 'My Factoids'), + ...factoids + ]) : h('div', 'loading'); + + return h('div.my-factoids', [ + content + ]); + } +} + +module.exports = MyFactoids; \ No newline at end of file diff --git a/src/client/router.js b/src/client/router.js index b364b7259..df96be4f2 100644 --- a/src/client/router.js +++ b/src/client/router.js @@ -12,7 +12,7 @@ const DebugDocumentSeeder = require('./components/debug-document-seeder'); const ExampleDocument = require('./components/example-document'); const DocumentSeeder = require('./components/document-seeder'); const DocumentViewChooser = require('./components/document-view-chooser'); - +const MyFactoids = require('./components/my-factoids'); let routes = [ { @@ -21,6 +21,12 @@ let routes = [ return h(Home); } }, + { + path: '/my-factoids', + render: props => { + return h( MyFactoids, props); + } + }, { path: '/new', render: () => { diff --git a/src/server/routes/api/document/index.js b/src/server/routes/api/document/index.js index 4d3e3fd93..01e893b67 100644 --- a/src/server/routes/api/document/index.js +++ b/src/server/routes/api/document/index.js @@ -56,6 +56,15 @@ let runLayout = doc => { return Promise.try( run ).then( getDoc ); }; +http.get('/my-factoids', (req, res) => { + ( + Promise.try( () => loadTable( 'document' ) ) + .then( db => db.rethink.table('document').pluck(['id', 'secret']).run(db.conn) ) + .then( r => r.toArray() ) + .then( results => res.json(results) ) + ); +}); + // get existing doc http.get('/:id', function( req, res ){ let id = req.params.id;