forked from mirrors/bookwyrm
Clear localstorage items
This commit is contained in:
parent
dfaf085843
commit
053e2cea0d
2 changed files with 17 additions and 3 deletions
|
@ -1,4 +1,5 @@
|
|||
/* exported StatusCache */
|
||||
/* globals BookWyrm */
|
||||
|
||||
let StatusCache = new class {
|
||||
constructor() {
|
||||
|
@ -25,6 +26,10 @@ let StatusCache = new class {
|
|||
// Used in set reading goal
|
||||
let key = event.target.dataset.cacheDraft;
|
||||
let value = event.target.value;
|
||||
if (!value) {
|
||||
window.localStorage.removeItem(key);
|
||||
return;
|
||||
}
|
||||
|
||||
window.localStorage.setItem(key, value);
|
||||
}
|
||||
|
@ -39,6 +44,9 @@ let StatusCache = new class {
|
|||
// Used in set reading goal
|
||||
let key = node.dataset.cacheDraft;
|
||||
let value = window.localStorage.getItem(key);
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
node.value = value;
|
||||
}
|
||||
|
@ -51,17 +59,21 @@ let StatusCache = new class {
|
|||
*/
|
||||
submitStatus(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const bookwyrm = this;
|
||||
const form = event.currentTarget;
|
||||
|
||||
this.ajaxPost(form).catch(error => {
|
||||
BookWyrm.ajaxPost(form).catch(error => {
|
||||
// @todo Display a notification in the UI instead.
|
||||
console.warn('Request failed:', error);
|
||||
});
|
||||
|
||||
// Clear form data
|
||||
form.reset();
|
||||
|
||||
// Clear localstorage
|
||||
form.querySelectorAll('[data-cache-draft]')
|
||||
.forEach(node => window.localStorage.removeItem(node.dataset.cacheDraft));
|
||||
|
||||
// Close modals
|
||||
}
|
||||
}();
|
||||
|
||||
|
|
|
@ -249,9 +249,11 @@
|
|||
<script>
|
||||
var csrf_token = '{{ csrf_token }}';
|
||||
</script>
|
||||
|
||||
<script src="{% static "js/bookwyrm.js" %}"></script>
|
||||
<script src="{% static "js/localstorage.js" %}"></script>
|
||||
<script src="{% static "js/status_cache.js" %}"></script>
|
||||
|
||||
{% block scripts %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue