Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

Remove some unused code

Daoud Clarkebb9911fcc0cc
diff --git a/devdata/index-v2.tinysearch b/devdata/index-v2.tinysearch
index d74989e..fb660fc 100644
Binary files a/devdata/index-v2.tinysearch and b/devdata/index-v2.tinysearch differ
diff --git a/front-end/src/components/molecules/add-result.js b/front-end/src/components/molecules/add-result.js
index 17528bb..bac6ce1 100644
--- a/front-end/src/components/molecules/add-result.js
+++ b/front-end/src/components/molecules/add-result.js
@@ -30,28 +30,5 @@ export default define('add-result', class extends HTMLDivElement {
// Clicking on the form shouldn't close it
e.stopPropagation();
});
-
- this.addEventListener('submit', this.__urlSubmitted.bind(this));
- }
-
- async __urlSubmitted(e) {
- e.preventDefault();
- const value = this.querySelector('input').value;
- console.log("Input value", value);
-
- const query = document.querySelector('.search-bar input').value;
-
- const url = `${FETCH_URL}url=${encodeURIComponent(value)}&query=${encodeURIComponent(query)}`;
- const response = await fetch(url);
- if (response.status === 200) {
- const data = await response.text();
- console.log("Data", data);
-
- const addResultEvent = new CustomEvent('curate-add-result', {detail: data});
- globalBus.dispatch(addResultEvent);
- } else {
- console.log("Bad response", response);
- // TODO
- }
}
}, { extends: 'div' });
diff --git a/front-end/src/components/organisms/results.js b/front-end/src/components/organisms/results.js
deleted file mode 100644
index dcd2d4e..0000000
--- a/front-end/src/components/organisms/results.js
+++ /dev/null
@@ -1,202 +0,0 @@
-import {globalBus} from '../../utils/events.js';
-import Sortable from 'sortablejs';
-
-class ResultsHandler {
- constructor() {
- this.oldIndex = null;
- this.curating = false;
- this.__setup();
- }
-
- __setup() {
- this.__events();
- this.__initializeResults();
- }
-
- __events() {
- document.body.addEventListener('htmx:load', e => {
- this.__initializeResults();
- });
-
- window.addEventListener('message', e => {
- console.log("Message event", e);
- if (e.data === 'results-loaded') {
- this.__initializeResults();
- }
- });
-
- // Focus first element when coming from the search bar
- globalBus.on('focus-result', () => {
- const results = document.querySelector('.results');
- results.firstElementChild.firstElementChild.focus();
- });
-
- globalBus.on('curate-delete-result', (e) => {
- console.log("Curate delete result event", e);
- const results = document.querySelector('.results');
- this.__beginCurating.bind(this)();
-
- const children = results.getElementsByClassName('result');
- let deleteIndex = e.detail.data.delete_index;
- const child = children[deleteIndex];
- results.removeChild(child);
- const newResults = this.__getResults();
-
- const curationSaveEvent = new CustomEvent('save-curation', {
- detail: {
- type: 'delete',
- data: {
- timestamp: Date.now(),
- url: document.location.href,
- results: newResults,
- curation: {
- delete_index: deleteIndex
- }
- }
- }
- });
- globalBus.dispatch(curationSaveEvent);
- });
-
- globalBus.on('curate-validate-result', (e) => {
- console.log("Curate validate result event", e);
- this.__beginCurating.bind(this)();
- const results = document.querySelector('.results');
-
- const children = results.getElementsByClassName('result');
- const validateChild = children[e.detail.data.validate_index];
- validateChild.querySelector('.curate-approve').toggleValidate();
-
- const newResults = this.__getResults();
-
- const curationStartEvent = new CustomEvent('save-curation', {
- detail: {
- type: 'validate',
- data: {
- timestamp: Date.now(),
- url: document.location.href,
- results: newResults,
- curation: e.detail.data
- }
- }
- });
- globalBus.dispatch(curationStartEvent);
- });
-
- globalBus.on('begin-curating-results', (e) => {
- // We might not be online, or logged in, so save the curation in local storage in case:
- console.log("Begin curation event", e);
- this.__beginCurating.bind(this)();
- });
-
- globalBus.on('curate-add-result', (e) => {
- console.log("Add result", e);
- this.__beginCurating();
- const resultData = e.detail;
- const results = document.querySelector('.results');
- results.insertAdjacentHTML('afterbegin', resultData);
-
- const newResults = this.__getResults();
- const url = newResults[0].url;
-
- let detail = {
- type: 'add',
- data: {
- timestamp: Date.now(),
- url: document.location.href,
- results: newResults,
- curation: {
- insert_index: 0,
- url: url
- }
- }
- };
- console.log("Detail", detail);
- const curationSaveEvent = new CustomEvent('save-curation', {
- detail: detail
- });
- globalBus.dispatch(curationSaveEvent);
- });
- }
-
- __initializeResults() {
- const results = document.querySelector('.results');
-
- if (results) {
- const sortable = new Sortable(results, {
- "onStart": this.__sortableActivate.bind(this),
- "onEnd": this.__sortableDeactivate.bind(this),
- "handle": ".handle",
- });
- }
-
- this.curating = false;
- }
-
- __sortableActivate(event) {
- console.log("Sortable activate", event);
- this.__beginCurating();
- this.oldIndex = event.oldIndex;
- }
-
- __beginCurating() {
- if (!this.curating) {
- const results = this.__getResults();
- const curationStartEvent = new CustomEvent('save-curation', {
- detail: {
- type: 'begin',
- data: {
- timestamp: Date.now(),
- url: document.location.href,
- results: results,
- curation: {}
- }
- }
- });
- globalBus.dispatch(curationStartEvent);
- this.curating = true;
- }
- }
-
- __getResults() {
- const resultsElements = document.querySelectorAll('.results .result:not(.ui-sortable-placeholder)');
- const results = [];
- for (let resultElement of resultsElements) {
- const result = {
- url: resultElement.querySelector('a').href,
- title: resultElement.querySelector('.title').innerText,
- extract: resultElement.querySelector('.extract').innerText,
- validated: resultElement.querySelector('.curate-approve').classList.contains('validated'),
- source: resultElement.querySelector('.source').innerText,
- }
- results.push(result);
- }
- console.log("Results", results);
- return results;
- }
-
- __sortableDeactivate(event) {
- const newIndex = event.newIndex;
- console.log('Sortable deactivate', this.oldIndex, newIndex);
-
- const newResults = this.__getResults();
-
- const curationMoveEvent = new CustomEvent('save-curation', {
- detail: {
- type: 'move',
- data: {
- timestamp: Date.now(),
- url: document.location.href,
- results: newResults,
- curation: {
- old_index: this.oldIndex,
- new_index: newIndex,
- }
- }
- }
- });
- globalBus.dispatch(curationMoveEvent);
- }
-}
-
-const resultsHandler = new ResultsHandler();
diff --git a/front-end/src/index.js b/front-end/src/index.js
index 027f34c..1b51a75 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/results.js");
import("./components/organisms/save.js");
import("./components/molecules/add-button.js");
import("./components/molecules/add-result.js");
diff --git a/mwmbl/templates/home.html b/mwmbl/templates/home.html
index 49009b2..ffb8a8a 100644
--- a/mwmbl/templates/home.html
+++ b/mwmbl/templates/home.html
@@ -1,15 +1,17 @@
{% load humanize %}
{% include "title.html" %}
-<div is="mwmbl-add-result">
- <form class="modal-content" style="display: none">
+<div is="mwmbl-add-result" style="display: none">
+ <form class="modal-content"
+ hx-post="/app/add/"
+ hx-target=".main"
+ hx-include=".result"
+ hx-vals='{"query": "{{ query }}"{% if curation %}, "curation_id": {{ curation.id }}{% endif %}}'
+ hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
<span class="close">&times;</span>
- <input class="add-result" name="new_url" placeholder="Enter a URL...">
- <button class="button"
- hx-post="/app/add/"
- hx-target=".main"
- hx-include=".result"
- hx-vals='{"query": "{{ query }}"{% if curation %}, "curation_id": {{ curation.id }}{% endif %}}'
- hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>Save</button>
+ <label>
+ Enter a URL: <input class="add-result" name="new_url" placeholder="https://something.org">
+ </label>
+ <input type="submit" class="button" value="Save"/>
</form>
</div>
<div class="main">