Skip to content

Panic button v2 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 24 additions & 66 deletions es/plugins/autosave.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
var localStorage = window.hasOwnProperty('localStorage') ? window.localStorage : false;
import axios from 'axios';
import { useEffect } from 'react';
import { loadProject } from '../actions/project-actions';

var TIMEOUT_DELAY = 50000;
var TIMEOUT_DELAY = 500;

var timeout = null;

export default function autosave(autosaveKey, delay,isAdmin,json) {


export default function autosave(autosaveKey, delay,selectPanicButton) {

return function (store, stateExtractor) {

Expand All @@ -18,78 +14,40 @@ export default function autosave(autosaveKey, delay,isAdmin,json) {
if (!autosaveKey) return;
if (!localStorage) return;

//revert//


// if (localStorage.getItem(autosaveKey) !== null) {
// var data = localStorage.getItem(autosaveKey);
// var json = JSON.parse(data);


// var path='http://127.0.0.1:5000/get'
// axios.get(path).then((res)=>{
var count=0
console.log("then block")
// json =res.data


var items=json["layers"]["layer-1"]["items"]
if(!isAdmin){ setInterval(function() {
if (count%2==0){
let tempItems={...items}
for (var key in tempItems){
console.log(tempItems[key])
if((tempItems[key]["type"]=="panic-button")||tempItems[key]["type"]=="panic-button-orange"){
delete tempItems[key]
}
}
json["layers"]["layer-1"]["items"]=tempItems
}else{
json["layers"]["layer-1"]["items"]=items
}
count=count+1
store.dispatch(loadProject(json));

},1000);
}else{
store.dispatch(loadProject(json));

//revert
if (localStorage.getItem(autosaveKey) !== null) {
var data = localStorage.getItem(autosaveKey);
var json = JSON.parse(data);
store.dispatch(loadProject(json));
}

// })

// }

// if (localStorage.getItem(autosaveKey) !== null) {
// var data = localStorage.getItem(autosaveKey);
// var json = JSON.parse(data);
// store.dispatch(loadProject(json));
// }



//update
store.subscribe(function () {
if (localStorage.getItem(autosaveKey) !== null) {
var data = localStorage.getItem(autosaveKey);
var json = JSON.parse(data);
var items=json["layers"]["layer-1"]["items"]
var ids=items.keys
for (id in ids ){
console.log(id)
}
// store.dispatch(loadProject(json));
}
// if (timeout) clearTimeout(timeout);
if (timeout) clearTimeout(timeout);
timeout = setTimeout(function () {
var state = stateExtractor(store.getState());
let json=state.scene.toJS()
console.log(state.scene.toJS(),"state")
localStorage.setItem(autosaveKey, JSON.stringify(state.scene.toJS()));
let items =json["layers"]["layer-1"]["items"]
let panic_id=[]
for (var key in items) {
let item= items[key]
if (item["selected"]==true){
console.log("selected")
panic_id.push(item["id"])
}

selectPanicButton(panic_id)

}

/*let scene = state.sceneHistory.last;
if (scene) {
let json = JSON.stringify(scene.toJS());
localStorage.setItem(autosaveKey, json);
}*/
}, delay);
}, 100);
});
};
}