From c1afb0aa2c6a000ce1f356b88b8b68b1948b4392 Mon Sep 17 00:00:00 2001 From: Sheldon Cooper Date: Tue, 21 Jul 2026 00:02:54 -0400 Subject: [PATCH] feat(ktb): add delete example and definition buttons; add pagination --- apps/ktb-static/script.js | 38 ++++++++++- apps/ktb-static/search.html | 116 +++++++++++++++++++++++++--------- apps/ktb-static/styles.css | 1 + apps/vdb-backend/src/index.ts | 26 ++++++++ 4 files changed, 148 insertions(+), 33 deletions(-) diff --git a/apps/ktb-static/script.js b/apps/ktb-static/script.js index 5dfc6e4..0beaf9a 100644 --- a/apps/ktb-static/script.js +++ b/apps/ktb-static/script.js @@ -2,7 +2,7 @@ document.addEventListener("alpine:init", () => { Alpine.store("dictionary", { search_results: { - terms: 0, + terms: 1, results: [ { lemma_name: "wiigel", @@ -136,6 +136,20 @@ document.addEventListener("alpine:init", () => { } }, + async delete_definition(definition_id, definition_text) { + if ( + window.confirm(`Du keshite imi ${definition_id}.\nPravda?`) + ) { + try { + const res = await axios.delete( + `http://localhost:1225/definition/${definition_id}`, + ); + } catch (e) { + console.error(e); + } + } + }, + async put_example(example_id, example_text, lemma_name) { try { const res = await axios.put("http://localhost:1225/example", { @@ -149,6 +163,20 @@ document.addEventListener("alpine:init", () => { } }, + async delete_example(example_id, example_text) { + if ( + window.confirm(`Du keshite tato ${example_id}.\nPravda?`) + ) { + try { + const res = await axios.delete( + `http://localhost:1225/example/${example_id}`, + ); + } catch (e) { + console.error(e); + } + } + }, + async put_word_form_text(word_form_id, word_form_text) { try { const res = await axios.put("http://localhost:1225/word-form", { @@ -162,6 +190,12 @@ document.addEventListener("alpine:init", () => { }, async post_new_word_form(lemma_name, lect_name, word_form_text) { + if(!lemma_name || !lect_name || !word_form_text) { + console.error(`Missing parameter:\n${JSON.stringify({ + lemma_name, lect_name, word_form_text + })}`); + } + try { const res = await axios.post( "http://localhost:1225/word-form", @@ -199,7 +233,7 @@ document.addEventListener("alpine:init", () => { }, md(text){ - console.log(marked.parse(text)); + console.debug(marked.parse(text)); return DOMPurify.sanitize(marked.parse(text), {ALLOWED_TAGS: ['br', 'em', 'strong', 'code', '#text']}); }, }); diff --git a/apps/ktb-static/search.html b/apps/ktb-static/search.html index cb50c3f..9f12af3 100644 --- a/apps/ktb-static/search.html +++ b/apps/ktb-static/search.html @@ -19,6 +19,8 @@ search_term: '', showPrefs: false, lects: [], + current_result_page: 0, + results_per_page: 30, md(text){ return $store.dictionary.md(text); }, @@ -92,9 +94,31 @@ @keydown.enter="$store.dictionary.fetch_all_terms(search_term)" placeholder="Tasta ko(tel) her..." /> +
+ +
+ + +
@@ -281,7 +324,6 @@ / - - +
+ + + + +
@@ -322,7 +371,12 @@ placeholder="Tasta tatoeba..." x-model="example_text"> +