Skip to content
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

feat: Remove local storage #1305

Merged
merged 2 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
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
54 changes: 0 additions & 54 deletions game/end_to_end_tests/test_localstorage.py

This file was deleted.

24 changes: 1 addition & 23 deletions game/static/game/js/blocklyControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,6 @@ ocargo.BlocklyControl.prototype.reset = function() {
this.clearIncorrectBlock();
};


ocargo.BlocklyControl.prototype.teardown = function() {
if (localStorage && !ANONYMOUS && USER_LOGGED_IN) {
var text = this.serialize();
try {
if (NIGHT_MODE) {
localStorage.setItem('blocklyNightModeWorkspaceXml-' + LEVEL_ID, text);
} else {
localStorage.setItem('blocklyWorkspaceXml-' + LEVEL_ID, text);
}
} catch (e) {
// No point in even logging, as page is unloading
}
}
};

ocargo.BlocklyControl.prototype.deserialize = function(text) {
try {
var oldXml = Blockly.Xml.workspaceToDom(Blockly.mainWorkspace);
Expand Down Expand Up @@ -163,15 +147,9 @@ ocargo.BlocklyControl.prototype.loadPreviousAttempt = function() {
e.innerHTML = text;
return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}
// Use the user's last attempt if available, else use whatever's in local storage
// Use the user's last attempt if available
if (WORKSPACE) {
this.deserialize(decodeHTML(WORKSPACE));
} else {
if (NIGHT_MODE) {
this.deserialize(localStorage.getItem('blocklyNightModeWorkspaceXml-' + LEVEL_ID));
} else {
this.deserialize(localStorage.getItem('blocklyWorkspaceXml-' + LEVEL_ID));
}
}

this.redrawBlockly();
Expand Down
38 changes: 0 additions & 38 deletions game/static/game/js/level_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ ocargo.LevelEditor = function(levelId) {
$('#play_night_tab').show()
}

// So that we store the current state when the page unloads
window.addEventListener('unload', storeStateInLocalStorage);

// Setup max_fuel
setupMaxFuel();

Expand All @@ -117,9 +114,6 @@ ocargo.LevelEditor = function(levelId) {

setupTrashcan();

// If there's any previous state in local storage retrieve it
retrieveStateFromLocalStorage();

// Draw everything
drawAll();

Expand Down Expand Up @@ -247,7 +241,6 @@ ocargo.LevelEditor = function(levelId) {

$('#clear').click(function() {
clear();
localStorage.removeItem('levelEditorState');
drawAll();
});

Expand Down Expand Up @@ -2597,37 +2590,6 @@ ocargo.LevelEditor = function(levelId) {
ownedLevels.save(level, levelId, callback);
}

function storeStateInLocalStorage() {
if (localStorage) {
var state = extractState();

// Append additional non-level orientated editor state
state.id = saveState.id;
state.savedState = saveState.savedState;
state.owned = saveState.owned;

localStorage.levelEditorState = JSON.stringify(state);
}
}

function retrieveStateFromLocalStorage() {
if (localStorage) {
if (localStorage.levelEditorState) {
var state = JSON.parse(localStorage.levelEditorState);

if (state) {
restoreState(state);
}

// Restore additional non-level orientated editor state
saveState.id = state.id;
saveState.savedState = state.savedState;
saveState.owned = state.owned;
}

}
}

function isLevelValid() {
// Check to see if a road has been created
if (nodes === undefined || nodes.length == 0) {
Expand Down
20 changes: 1 addition & 19 deletions game/static/game/js/pythonControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,10 @@ ocargo.PythonControl = function () {
if (PYTHON_WORKSPACE) {
this.setCode(PYTHON_WORKSPACE);
} else {
try {
this.setCode(
localStorage.getItem('pythonWorkspace-' + LEVEL_ID));
} catch (e) {
this.reset();
}
this.reset();
}
};

this.teardown = function () {
if (localStorage && !ANONYMOUS && USER_LOGGED_IN) {
var text = this.getCode();
try {
localStorage.setItem('pythonWorkspace-' + LEVEL_ID, text);

} catch (e) {
// No point in even logging, as page is unloading
}
}
};


/*********************/
/** Private methods **/
/*********************/
Expand Down
47 changes: 1 addition & 46 deletions game/static/game/js/saving.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
var ocargo = ocargo || {};

ocargo.Saving = function () {
this.getListOfWorkspacesFromLocalStorage = function () {
var query = /blocklySavedWorkspaceXml-([0-9]+)$/;
var i, results = [];
for (i in localStorage) {
if (localStorage.hasOwnProperty(i)) {
var matches = query.exec(i);
if (matches) {
var json = JSON.parse(localStorage.getItem(i));
results.push({
id: matches[1],
name: json.name,
workspace: json.workspace
});
}
}
}
return results;
};
};
ocargo.Saving = function () {};

function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
Expand All @@ -44,10 +25,6 @@ ocargo.Saving.prototype.retrieveListOfWorkspaces = function (callback) {
}
});
}
else if (localStorage) {
var results = this.getListOfWorkspacesFromLocalStorage();
callback(null, results);
}
else {
callback("Not logged in and no local storage available");
}
Expand All @@ -67,13 +44,6 @@ ocargo.Saving.prototype.retrieveWorkspace = function (id, callback) {
}
});
}
//setTimeout is used here in order to ensure that these lines of code are executed after the correct tab is selected
else if (localStorage) {
setTimeout(function () {
var json = JSON.parse(localStorage.getItem('blocklySavedWorkspaceXml-' + id));
callback(null, json);
}, 0)
}
else {
callback("Not logged in and no local storage available");
}
Expand All @@ -98,10 +68,6 @@ ocargo.Saving.prototype.deleteWorkspace = function (id, callback) {
callback(xhr.status + ": " + errmsg + " " + err + " " + xhr.responseText);
}
});
} else if (localStorage) {
localStorage.removeItem('blocklySavedWorkspaceXml-' + id);
var results = this.getListOfWorkspacesFromLocalStorage();
callback(null, results);
} else {
callback("Not logged in and no local storage available");
}
Expand All @@ -128,17 +94,6 @@ ocargo.Saving.prototype.saveWorkspace = function (workspace, id, callback) {
}
});
}
else if (localStorage) {
if (!id) {
// Need to generate a unique integer, for our purposes this should do
id = new Date().getTime();
}

localStorage.setItem('blocklySavedWorkspaceXml-' + id, JSON.stringify(workspace));

var results = this.getListOfWorkspacesFromLocalStorage();
callback(null, results);
}
else {
callback("Not logged in and no local storage available");
}
Expand Down