mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-13 10:55:57 +00:00
Finally testing, things should be working a bit better now
This commit is contained in:
@@ -18,11 +18,11 @@ const Homebrew = React.createClass({
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
url : '',
|
||||
welcomeText : '',
|
||||
changelog : '',
|
||||
version : '0.0.0',
|
||||
account : undefined,
|
||||
brew : {}
|
||||
user : undefined,
|
||||
|
||||
brew : {},
|
||||
brews : []
|
||||
};
|
||||
},
|
||||
componentWillMount: function() {
|
||||
@@ -38,23 +38,8 @@ const Homebrew = React.createClass({
|
||||
|
||||
|
||||
Router = CreateRouter({
|
||||
'/edit/:id' : (args) => {
|
||||
if(!this.props.brew.editId){
|
||||
return <ErrorPage errorId={args.id}/>
|
||||
}
|
||||
|
||||
return <EditPage />
|
||||
},
|
||||
|
||||
'/share/:id' : (args) => {
|
||||
if(!this.props.brew.shareId){
|
||||
return <ErrorPage errorId={args.id}/>
|
||||
}
|
||||
|
||||
return <SharePage
|
||||
id={args.id}
|
||||
brew={this.props.brew} />
|
||||
},
|
||||
'/edit/:id' : <EditPage />,
|
||||
'/share/:id' : <SharePage />,
|
||||
/*
|
||||
'/user/:username' : (args) => {
|
||||
return <UserPage
|
||||
@@ -68,15 +53,9 @@ const Homebrew = React.createClass({
|
||||
'/print' : (args, query) => {
|
||||
return <PrintPage query={query}/>;
|
||||
},
|
||||
'/new' : (args) => {
|
||||
return <NewPage />
|
||||
},
|
||||
'/changelog' : (args) => {
|
||||
return <SharePage
|
||||
brew={{title : 'Changelog', text : this.props.changelog}} />
|
||||
},
|
||||
'*' : <HomePage
|
||||
welcomeText={this.props.welcomeText} />,
|
||||
'/new' : <NewPage />,
|
||||
'/changelog' : <SharePage />,
|
||||
'*' : <HomePage />,
|
||||
});
|
||||
},
|
||||
render : function(){
|
||||
|
||||
@@ -13,7 +13,7 @@ const StaticSave = React.createClass({
|
||||
};
|
||||
},
|
||||
handleClick : function(){
|
||||
Actions.saveNew();
|
||||
Actions.create();
|
||||
},
|
||||
render : function(){
|
||||
if(this.props.status === 'saving'){
|
||||
|
||||
@@ -14,23 +14,9 @@ const BrewInterface = require('homebrewery/brewInterface/brewInterface.jsx');
|
||||
|
||||
|
||||
const Actions = require('homebrewery/brew.actions.js');
|
||||
//const Store = require('homebrewery/brew.store.js');
|
||||
|
||||
//
|
||||
|
||||
const HomePage = React.createClass({
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
welcomeText : '',
|
||||
};
|
||||
},
|
||||
componentWillMount: function() {
|
||||
Actions.init({
|
||||
brew : {
|
||||
text : this.props.welcomeText
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
handleSave : function(){
|
||||
Actions.saveNew();
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "homebrewery",
|
||||
"description": "Create authentic looking D&D homebrews using only markdown",
|
||||
"version": "2.7.1",
|
||||
"version": "3.0.0",
|
||||
"scripts": {
|
||||
"dev": "node scripts/dev.js",
|
||||
"quick": "node scripts/quick.js",
|
||||
|
||||
@@ -17,8 +17,8 @@ const config = require('nconf')
|
||||
require('mongoose')
|
||||
.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI || 'mongodb://localhost/naturalcrit')
|
||||
.connection.on('error', () => {
|
||||
console.log('Error : Could not connect to a Mongo Database.');
|
||||
console.log(' If you are running locally, make sure mongodb.exe is running.');
|
||||
console.error('Error : Could not connect to a Mongo Database.');
|
||||
console.error(' If you are running locally, make sure mongodb.exe is running.');
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -88,10 +88,9 @@ const BrewData = {
|
||||
return newBrew.save();
|
||||
},
|
||||
update : (newBrew) => {
|
||||
return Brew.findOneAndUpdate({ editId : newBrew.editId }, {
|
||||
...newBrew,
|
||||
updatedAt : Date.now()
|
||||
}, {new : true, upsert : true}).exec(); //TODO: TEST THIS that this returns a reocrd
|
||||
return Brew.findOneAndUpdate({ editId : newBrew.editId },
|
||||
_.merge(newBrew, { updatedAt : Date.now() }),
|
||||
{new : true, upsert : true}).exec(); //TODO: TEST THIS that this returns a reocrd
|
||||
},
|
||||
remove : (editId) => {
|
||||
return Brew.find({ editId }).remove().exec();
|
||||
|
||||
@@ -12,20 +12,22 @@ const docs = {
|
||||
|
||||
|
||||
const vitreumRender = require('vitreum/steps/render');
|
||||
const templateFn = require('./client/template.js');
|
||||
const templateFn = require('../client/template.js');
|
||||
//TODO: Catch errors here?
|
||||
const renderPage = (req, res, next) => {
|
||||
return vitreumRender('homebrew', templateFn, {
|
||||
url : req.originalUrl,
|
||||
version : require('./package.json').version,
|
||||
version : require('../package.json').version,
|
||||
//TODO: add in login path?
|
||||
|
||||
user : req.account && req.account.username,
|
||||
brews : req.brews,
|
||||
brew : req.brew
|
||||
})
|
||||
.then(res.send)
|
||||
.catch(next)
|
||||
.then((page) => {
|
||||
return res.send(page)
|
||||
})
|
||||
.catch(next);
|
||||
};
|
||||
|
||||
|
||||
@@ -66,10 +68,16 @@ router.get('/search', (req, res, next) => {
|
||||
|
||||
//Changelog Page
|
||||
router.get('/changelog', (req, res, next) => {
|
||||
req.brew = { text : docs.changelog };
|
||||
req.brew = {
|
||||
text : docs.changelog,
|
||||
title : 'Changelog'
|
||||
};
|
||||
return next();
|
||||
}, renderPage);
|
||||
|
||||
//New Page
|
||||
router.get('/new', renderPage);
|
||||
|
||||
//Home Page
|
||||
router.get('/', (req, res, next) => {
|
||||
req.brew = { text : docs.welcomeBrew };
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const _ = require('lodash');
|
||||
const dispatch = require('pico-flux').dispatch;
|
||||
|
||||
const request = require('superagent');
|
||||
@@ -6,6 +7,42 @@ const Store = require('./brew.store.js');
|
||||
let pendingTimer;
|
||||
const PENDING_TIMEOUT = 3000;
|
||||
|
||||
const APIActions = {
|
||||
save : () => {
|
||||
clearTimeout(pendingTimer);
|
||||
const brew = Store.getBrew();
|
||||
dispatch('SET_STATUS', 'saving');
|
||||
request
|
||||
.put('/api/brew/' + brew.editId)
|
||||
.send(brew)
|
||||
.end((err, res) => {
|
||||
if(err) return dispatch('SET_STATUS', 'error', err);
|
||||
dispatch('SET_BREW', res.body);
|
||||
dispatch('SET_STATUS', 'ready');
|
||||
});
|
||||
},
|
||||
create : () => {
|
||||
dispatch('SET_STATUS', 'saving');
|
||||
request.post('/api/brew')
|
||||
.send(Store.getBrew())
|
||||
.end((err, res)=>{
|
||||
if(err) return dispatch('SET_STATUS', 'error', err);
|
||||
localStorage.setItem('homebrewery-new', null);
|
||||
const brew = res.body;
|
||||
window.location = '/edit/' + brew.editId;
|
||||
});
|
||||
},
|
||||
delete : (editId) => {
|
||||
dispatch('SET_STATUS', 'deleting');
|
||||
request.delete('/api/brew/' + editId)
|
||||
.send()
|
||||
.end((err, res)=>{
|
||||
if(err) return dispatch('SET_STATUS', 'error', err);
|
||||
window.location = '/';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const Actions = {
|
||||
init : (initState) => {
|
||||
Store.init(initState);
|
||||
@@ -21,33 +58,10 @@ const Actions = {
|
||||
},
|
||||
pendingSave : () => {
|
||||
clearTimeout(pendingTimer);
|
||||
pendingTimer = setTimeout(Actions.save, PENDING_TIMEOUT);
|
||||
pendingTimer = setTimeout(APIActions.save, PENDING_TIMEOUT);
|
||||
dispatch('SET_STATUS', 'pending');
|
||||
},
|
||||
save : () => {
|
||||
clearTimeout(pendingTimer);
|
||||
const brew = Store.getBrew();
|
||||
dispatch('SET_STATUS', 'saving');
|
||||
request
|
||||
.put('/api/update/' + brew.editId)
|
||||
.send(brew)
|
||||
.end((err, res) => {
|
||||
if(err) return dispatch('SET_STATUS', 'error', err);
|
||||
dispatch('SET_BREW', res.body);
|
||||
dispatch('SET_STATUS', 'ready');
|
||||
});
|
||||
},
|
||||
saveNew : () => {
|
||||
dispatch('SET_STATUS', 'saving');
|
||||
request.post('/api')
|
||||
.send(Store.getBrew())
|
||||
.end((err, res)=>{
|
||||
if(err) return dispatch('SET_STATUS', 'error', err);
|
||||
localStorage.setItem('homebrewery-new', null);
|
||||
const brew = res.body;
|
||||
window.location = '/edit/' + brew.editId;
|
||||
});
|
||||
},
|
||||
|
||||
localPrint : ()=>{
|
||||
localStorage.setItem('print', Store.getBrewText());
|
||||
window.open('/print?dialog=true&local=print','_blank');
|
||||
@@ -57,4 +71,4 @@ const Actions = {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Actions;
|
||||
module.exports = _.merge(Actions, APIActions);
|
||||
Reference in New Issue
Block a user