From b2114fc03803873ccf17d434845654aa158a6175 Mon Sep 17 00:00:00 2001 From: vict0rsch Date: Fri, 20 Oct 2023 15:53:56 -0400 Subject: [PATCH] errors & cmd+enter --- src/fullMemory/bibMatcher.css | 17 +++++-- src/fullMemory/bibMatcher.html | 16 +++++-- src/fullMemory/bibMatcher.js | 85 ++++++++++++++++++++-------------- 3 files changed, 75 insertions(+), 43 deletions(-) diff --git a/src/fullMemory/bibMatcher.css b/src/fullMemory/bibMatcher.css index 5376a58a..94e628e6 100644 --- a/src/fullMemory/bibMatcher.css +++ b/src/fullMemory/bibMatcher.css @@ -168,10 +168,6 @@ input { max-width: 200px; margin: auto; } -#bib-text { - max-width: 100%; - margin: 1rem; -} #match-results { padding: 1rem; @@ -297,6 +293,19 @@ th { } } +/* +-------------------- +----- Errors ----- +-------------------- +*/ + +#bibmatch-errors { + background: #ececec; + border: 2px solid orange; + padding: 16px; + border-radius: 4px; +} + /* ------------------------ ----- Checkboxes ----- diff --git a/src/fullMemory/bibMatcher.html b/src/fullMemory/bibMatcher.html index 66a17da5..66554d24 100644 --- a/src/fullMemory/bibMatcher.html +++ b/src/fullMemory/bibMatcher.html @@ -28,7 +28,7 @@

Bib Matcher

-
+

Paste the content of your .bib file and PaperMemory will automatically match the Arxiv entries to publications by @@ -43,9 +43,9 @@

Bib Matcher

- -

+
+ +
@@ -66,12 +66,18 @@

Bib Matcher

+
-
+ +

diff --git a/src/fullMemory/bibMatcher.js b/src/fullMemory/bibMatcher.js index 1aa45ea8..4d0233cf 100644 --- a/src/fullMemory/bibMatcher.js +++ b/src/fullMemory/bibMatcher.js @@ -1,23 +1,38 @@ var STOPMATCH = false; const setListeners = () => { - const stopMatch = document.getElementById("match-bib-stop"); - stopMatch.addEventListener("click", () => { + addListener("match-bib-stop", "click", () => { STOPMATCH = true; setHTML("match-bib-stop", ''); }); - document.getElementById("copy-results").addEventListener("click", () => { - copyTextToClipboard(document.getElementById("match-results").innerText); + addListener("copy-results", "click", () => { + copyTextToClipboard(findEl("match-results").innerText); setHTML("copy-results", "Copied!"); setTimeout(() => { setHTML("copy-results", "Copy to clipboard"); }, 1500); }); - const bibMatcher = document.getElementById("match-bib"); - bibMatcher.addEventListener("click", async () => { - const text = document.getElementById("bib-text").value; - let parsed = parseBibText(text); + addListener("bib-text", "keydown", (e) => { + if (document.activeElement === findEl("bib-text")) { + if ((e.metaKey || e.ctrlKey) && e.keyCode == 13) { + dispatch("match-bib", "click"); + findEl("match-bib").focus(); + } + } + }); + addListener("match-bib", "click", async () => { resetMatchResults(); + const text = findEl("bib-text").value; + let parsed, stop; + + try { + parsed = parseBibText(text); + } catch (error) { + showError(error); + stop = true; + } + if (stop) return; + console.log("parsed: ", parsed); let arxivIndices = []; let arxivs = []; @@ -43,6 +58,7 @@ const setListeners = () => { }); console.log("arxivs: ", arxivs); + showId("matching-feedback-container"); arxivs.length ? setHTML( "n-arxivs", @@ -61,23 +77,19 @@ const setListeners = () => { }; const resetMatchResults = () => { - setHTML("match-results-title", ""); hideId("result-controls"); hideId("match-results"); setHTML("match-results", ""); hideId("bib-header"); setHTML("bib-desc", ""); + hideId("errors-container"); + setHTML("bibmatch-errors", ""); + hideId("matching-feedback-container"); }; const showPapers = (parsed, matched, arxivIndices) => { const nMatched = matched.filter((e) => e).length; - const found = - nMatched > 1 ? `Found ${nMatched} matches` : `Found ${nMatched} match`; - if (!nMatched) { - showId("match-results"); - setHTML("match-results", ""); - return; - } + if (!nMatched) return; const showOnlyMatches = val("show-only-matches"); const desc = showOnlyMatches ? `

Showing only ${nMatched} new matched entries

` @@ -89,7 +101,6 @@ const showPapers = (parsed, matched, arxivIndices) => { .filter((e) => e) .map(bibtexToString) .join("
"); - setHTML("match-results-title", found + " (showing only matches)"); showId("match-results"); setHTML("match-results", html); showId("result-controls", "flex"); @@ -107,16 +118,11 @@ const showPapers = (parsed, matched, arxivIndices) => { } } const html = htmls.join("
"); - setHTML( - "match-results-title", - found + ` (showing all ${parsed.length} entries)` - ); showId("match-results"); setHTML("match-results", html); showId("result-controls", "flex"); } showId("bib-header"); - setHTML("match-results-title", found); setHTML("bib-desc", desc); }; @@ -133,6 +139,11 @@ const setKey = (bibtex, key) => { return bibtexToString(obj); }; +const showError = (msg) => { + showId("errors-container"); + setHTML("bibmatch-errors", msg); +}; + const matchItems = async (papersToMatch) => { showId("matching-progress-container", "flex"); setHTML("matching-status-total", papersToMatch.length); @@ -228,6 +239,7 @@ const matchItems = async (papersToMatch) => { return matchedBibtexStrs; } } + updateMatchedTitles(matchedBibtexStrs, sources, venues); hideId("match-bib-stop"); changeProgress(100); setHTML("matching-status", "All done!

"); @@ -235,21 +247,26 @@ const matchItems = async (papersToMatch) => { }; const updateMatchedTitles = (matchedBibtexStrs, sources, venues) => { + const htmls = []; const entries = matchedBibtexStrs.filter((e) => e).map(bibtexToObject); - const keys = entries.map((e) => e.citationKey); - const titles = entries.map((e) => e.title.replaceAll("{", "").replaceAll("}", "")); - const htmls = [""]; - for (const [idx, title] of titles.entries()) { - htmls.push( - ` - - - - - ` + if (entries.length) { + const keys = entries.map((e) => e.citationKey); + const titles = entries.map((e) => + e.title.replaceAll("{", "").replaceAll("}", "") ); + htmls.push("
${keys[idx]}${title}${venues[idx]}${sources[idx]}
"); + for (const [idx, title] of titles.entries()) { + htmls.push( + ` + + + + + ` + ); + } + htmls.push("
${keys[idx]}${title}${venues[idx]}${sources[idx]}
"); } - htmls.push(""); setHTML( "matched-list", `

Papers successfully matched: ${entries.length}

` + htmls.join("")