mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-13 06:32:39 +00:00
Edit page finally converted over
This commit is contained in:
@@ -3,6 +3,9 @@ const dispatch = require('pico-flux').dispatch;
|
||||
const request = require('superagent');
|
||||
const Store = require('./brew.store.js');
|
||||
|
||||
let pendingTimer;
|
||||
const PENDING_TIMEOUT = 3000;
|
||||
|
||||
const Actions = {
|
||||
init : (initState) => {
|
||||
Store.init(initState);
|
||||
@@ -17,9 +20,13 @@ const Actions = {
|
||||
dispatch('UPDATE_META', meta);
|
||||
},
|
||||
|
||||
|
||||
|
||||
pendingSave : () => {
|
||||
clearTimeout(pendingTimer);
|
||||
pendingTimer = setTimeout(Actions.save, PENDING_TIMEOUT);
|
||||
dispatch('SET_STATUS', 'pending');
|
||||
},
|
||||
save : () => {
|
||||
clearTimeout(pendingTimer);
|
||||
const brew = Store.getBrew();
|
||||
dispatch('SET_STATUS', 'saving');
|
||||
request
|
||||
@@ -27,8 +34,8 @@ const Actions = {
|
||||
.send(brew)
|
||||
.end((err, res) => {
|
||||
if(err) return dispatch('SET_STATUS', 'error', err);
|
||||
dispatch('SET_STATUS', 'ready');
|
||||
dispatch('SET_BREW', res.body);
|
||||
dispatch('SET_STATUS', 'ready');
|
||||
});
|
||||
},
|
||||
|
||||
@@ -45,6 +52,9 @@ const Actions = {
|
||||
localPrint : ()=>{
|
||||
localStorage.setItem('print', Store.getBrewText());
|
||||
window.open('/print?dialog=true&local=print','_blank');
|
||||
},
|
||||
print : ()=>{
|
||||
window.open(`/print/${Store.getBrew().shareId}?dialog=true`, '_blank').focus();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -37,8 +37,9 @@ const Store = flux.createStore({
|
||||
State.brew = _.merge({}, State.brew, meta);
|
||||
},
|
||||
SET_STATUS : (status, error) => {
|
||||
State.status = status;
|
||||
if(status == State.status) return false;
|
||||
if(error) State.errors = error;
|
||||
State.status = status;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -65,5 +66,4 @@ Store.getStatus = ()=>{
|
||||
return State.status;
|
||||
};
|
||||
|
||||
|
||||
module.exports = Store;
|
||||
Reference in New Issue
Block a user