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