mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-05 12:22:44 +00:00
rework the whole thing
This commit is contained in:
@@ -55,11 +55,16 @@
|
|||||||
text-align : center;
|
text-align : center;
|
||||||
text-transform : initial;
|
text-transform : initial;
|
||||||
}
|
}
|
||||||
.save-menu .navItem i.fa-power-off {
|
.save-menu {
|
||||||
color : red;
|
.dropdown {
|
||||||
&.active {
|
z-index: 1000;
|
||||||
color : rgb(0, 182, 52);
|
}
|
||||||
filter : drop-shadow(0 0 2px rgba(0, 182, 52, 0.765))
|
.navItem i.fa-power-off {
|
||||||
|
color : red;
|
||||||
|
&.active {
|
||||||
|
color : rgb(0, 182, 52);
|
||||||
|
filter : drop-shadow(0 0 2px rgba(0, 182, 52, 0.765))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.patreon.navItem{
|
.patreon.navItem{
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ const googleDriveActive = require('../../googleDrive.png');
|
|||||||
const googleDriveInactive = require('../../googleDriveMono.png');
|
const googleDriveInactive = require('../../googleDriveMono.png');
|
||||||
|
|
||||||
const SAVE_TIMEOUT = 3000;
|
const SAVE_TIMEOUT = 3000;
|
||||||
const AUTOSAVE_TIMEOUT = 10000;
|
|
||||||
|
|
||||||
const EditPage = createClass({
|
const EditPage = createClass({
|
||||||
displayName : 'EditPage',
|
displayName : 'EditPage',
|
||||||
@@ -64,21 +63,27 @@ const EditPage = createClass({
|
|||||||
errors : null,
|
errors : null,
|
||||||
htmlErrors : Markdown.validate(this.props.brew.text),
|
htmlErrors : Markdown.validate(this.props.brew.text),
|
||||||
url : '',
|
url : '',
|
||||||
autoSave : true
|
autoSave : true,
|
||||||
|
autoSaveWarning : false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
savedBrew : null,
|
savedBrew : null,
|
||||||
|
|
||||||
componentDidMount : function(){
|
componentDidMount : function(){
|
||||||
this.setState({ autoSave: JSON.parse(localStorage.getItem('AUTOSAVE_ON')) });
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
url : window.location.href
|
url : window.location.href
|
||||||
});
|
});
|
||||||
|
|
||||||
this.savedBrew = JSON.parse(JSON.stringify(this.props.brew)); //Deep copy
|
this.savedBrew = JSON.parse(JSON.stringify(this.props.brew)); //Deep copy
|
||||||
|
|
||||||
this.trySave();
|
this.setState({ autoSave: JSON.parse(localStorage.getItem('AUTOSAVE_ON')) }, ()=>{
|
||||||
|
if(this.state.autoSave){
|
||||||
|
this.trySave();
|
||||||
|
} else {
|
||||||
|
this.setState({ autoSaveWarning: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
window.onbeforeunload = ()=>{
|
window.onbeforeunload = ()=>{
|
||||||
if(this.state.isSaving || this.state.isPending){
|
if(this.state.isSaving || this.state.isPending){
|
||||||
return 'You have unsaved changes!';
|
return 'You have unsaved changes!';
|
||||||
@@ -147,13 +152,6 @@ const EditPage = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
trySave : function(){
|
trySave : function(){
|
||||||
// if(!this.state.autoSave){
|
|
||||||
// if(this.autoSaveInterval){
|
|
||||||
// clearInterval(this.autoSaveInterval);
|
|
||||||
// }
|
|
||||||
// this.autoSaveInterval = setInterval(this.trySave, 10000);
|
|
||||||
// return;
|
|
||||||
// };
|
|
||||||
if(!this.debounceSave) this.debounceSave = _.debounce(this.save, SAVE_TIMEOUT);
|
if(!this.debounceSave) this.debounceSave = _.debounce(this.save, SAVE_TIMEOUT);
|
||||||
if(this.hasChanges()){
|
if(this.hasChanges()){
|
||||||
this.debounceSave();
|
this.debounceSave();
|
||||||
@@ -340,6 +338,18 @@ const EditPage = createClass({
|
|||||||
</Nav.item>;
|
</Nav.item>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.state.autoSaveWarning){
|
||||||
|
setTimeout(()=>this.setState({ autoSaveWarning: false }), 4000);
|
||||||
|
this.setAutosaveWarning();
|
||||||
|
|
||||||
|
return <Nav.item className='save error' icon='fas fa-exclamation-circle'>
|
||||||
|
Reminder...
|
||||||
|
<div className='errorContainer'>
|
||||||
|
Autosave has been turned off, and you haven't saved for {Math.round((new Date() - new Date(this.props.brew.updatedAt)) / 1000 / 60)} minutes.
|
||||||
|
</div>
|
||||||
|
</Nav.item>;
|
||||||
|
}
|
||||||
|
|
||||||
if(this.state.isSaving){
|
if(this.state.isSaving){
|
||||||
return <Nav.item className='save' icon='fas fa-spinner fa-spin'>saving...</Nav.item>;
|
return <Nav.item className='save' icon='fas fa-spinner fa-spin'>saving...</Nav.item>;
|
||||||
}
|
}
|
||||||
@@ -355,14 +365,20 @@ const EditPage = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleAutoSave : function(){
|
handleAutoSave : function(){
|
||||||
|
if(this.warningTimer) clearTimeout(this.warningTimer);
|
||||||
this.setState((prevState)=>({
|
this.setState((prevState)=>({
|
||||||
autoSave : !prevState.autoSave
|
autoSave : !prevState.autoSave,
|
||||||
|
autoSaveWarning : prevState.autoSave
|
||||||
}), ()=>{
|
}), ()=>{
|
||||||
if(this.state.autoSave) this.trySave();
|
|
||||||
localStorage.setItem('AUTOSAVE_ON', JSON.stringify(this.state.autoSave));
|
localStorage.setItem('AUTOSAVE_ON', JSON.stringify(this.state.autoSave));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setAutosaveWarning : function(){
|
||||||
|
this.warningTimer = setTimeout(()=>{this.setState({ autoSaveWarning: true });}, 15000);
|
||||||
|
this.warningTimer;
|
||||||
|
},
|
||||||
|
|
||||||
renderAutoSaveButton : function(){
|
renderAutoSaveButton : function(){
|
||||||
return <Nav.item onClick={this.handleAutoSave}>
|
return <Nav.item onClick={this.handleAutoSave}>
|
||||||
Autosave <i className={this.state.autoSave ? 'fas fa-power-off active' : 'fas fa-power-off'}></i>
|
Autosave <i className={this.state.autoSave ? 'fas fa-power-off active' : 'fas fa-power-off'}></i>
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
position : absolute;
|
position : absolute;
|
||||||
top : 100%;
|
top : 100%;
|
||||||
left : 50%;
|
left : 50%;
|
||||||
z-index : 100000;
|
z-index : 500;
|
||||||
width : 140px;
|
width : 140px;
|
||||||
padding : 3px;
|
padding : 3px;
|
||||||
color : white;
|
color : white;
|
||||||
|
|||||||
Reference in New Issue
Block a user