An open source, non-profit web search engine
Remove unused save.js code
Daoud Clarkeae7e6d26382f
diff --git a/devdata/index-v2.tinysearch b/devdata/index-v2.tinysearchindex 5a9cf2f..321dd37 100644Binary files a/devdata/index-v2.tinysearch and b/devdata/index-v2.tinysearch differdiff --git a/front-end/src/components/organisms/save.js b/front-end/src/components/organisms/save.jsdeleted file mode 100644index 73a23d8..0000000--- a/front-end/src/components/organisms/save.js+++ /dev/null@@ -1,112 +0,0 @@-import define from '../../utils/define.js';-import {globalBus} from "../../utils/events.js";-import config from "../../../config.js";---const CURATION_KEY_PREFIX = "curation-";-const CURATION_URL = config.publicApiURL + "curation/";---const template = () => /*html*/`- <span></span>-`;---export default define('save', class extends HTMLDivElement {- constructor() {- super();- this.currentCurationId = null;- this.classList.add('save');- this.sendId = 0;- this.sending = false;- this.__setup();- }-- __setup() {- this.innerHTML = template();- this.__events();- // TODO: figure out when to call __sendToApi()- // setInterval(this.__sendToApi.bind(this), 1000);- }-- __events() {- globalBus.on('save-curation', (e) => {- // We might not be online, or logged in, so save the curation in local storage in case:- console.log("Curation event", e);- this.__setCuration(e.detail);- this.__sendToApi();- });- }-- __setCuration(curation) {- this.sendId += 1;- const key = CURATION_KEY_PREFIX + this.sendId;- localStorage.setItem(key, JSON.stringify(curation));- }-- __getOldestCurationKey() {- let oldestId = Number.MAX_SAFE_INTEGER;- let oldestKey = null;- for (let i=0; i<localStorage.length; ++i) {- const key = localStorage.key(i);- if (key.startsWith(CURATION_KEY_PREFIX)) {- const timestamp = parseInt(key.substring(CURATION_KEY_PREFIX.length));- if (timestamp < oldestId) {- oldestKey = key;- oldestId = timestamp;- }- }- }- return oldestKey;- }-- async __sendToApi() {- if (this.sending) {- return;- }- this.sending = true;- const csrftoken = document.cookie- .split('; ')- .find((row) => row.startsWith('csrftoken='))- ?.split('=')[1];-- if (!csrftoken) {- console.log("No auth");- return;- }-- const key = this.__getOldestCurationKey();- if (key !== null) {- const value = JSON.parse(localStorage.getItem(key));- console.log("Value", value);- const url = CURATION_URL + value['type'];-- const data = value['data'];- console.log("Data", data);- const response = await fetch(url, {- method: 'POST',- cache: 'no-cache',- headers: {'Content-Type': 'application/json', 'X-CSRFToken': csrftoken},- credentials: "same-origin",- mode: "same-origin",- body: JSON.stringify(data),- });-- console.log("Save curation API response", response);-- if (response.status === 200) {- localStorage.removeItem(key);- } else {- console.log("Bad response, skipping");- return;- }-- const responseData = await response.json();- console.log("Response data", responseData);- // There may be more to send, wait a second and see- setTimeout(this.__sendToApi.bind(this), 1000);- }- this.sending = false;- }-}, { extends: 'div' });-diff --git a/front-end/src/index.js b/front-end/src/index.jsindex 7a63338..41b9f4f 100644--- a/front-end/src/index.js+++ b/front-end/src/index.js@@ -15,7 +15,6 @@ import 'vite/modulepreload-polyfill';if (!redirected) {// Load components only after redirects are checked.- import("./components/organisms/save.js");import("./components/molecules/add-button.js");import("./components/molecules/add-result.js");import("./components/molecules/result.js");diff --git a/mwmbl/templates/index.html b/mwmbl/templates/index.htmlindex 36f044a..d7f3730 100644--- a/mwmbl/templates/index.html+++ b/mwmbl/templates/index.html@@ -64,7 +64,6 @@hx-target=".main"></form>- <div is="mwmbl-save"></div>{% if user.is_authenticated %}<p class="login-info">Logged in as {{ user.username }}</p><a class="button" href="/accounts/logout/">Log out</a>