Skip to content

Commit a2df68a

Browse files
committed
feat: add (but paused) logic to add viewed word to recent searches
1 parent 176c8f8 commit a2df68a

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/components/islands/search.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ function SearchDialog() {
156156
e.preventDefault();
157157
if (document.querySelector("._cursor")) {
158158
const word = document.querySelector("._cursor");
159+
/**
160+
* @todo extract this `$addToRecentSearchesFn` operation to `word` layout..
161+
* ..so words are added to recent searches when viewed (not only when searched)
162+
*/
159163
$addToRecentSearchesFn({
160164
word: word.textContent,
161165
url: word.href
@@ -245,6 +249,10 @@ function SearchResult({ result = [], cursor, searchTerm }) {
245249
href={`/browse/${doc.slug}`}
246250
onClick={(e) => {
247251
e.preventDefault();
252+
/**
253+
* @todo extract this `$addToRecentSearchesFn` operation to `word` layout..
254+
* ..so words are added to recent searches when viewed (not only when searched)
255+
*/
248256
$addToRecentSearchesFn({
249257
word: e.currentTarget.textContent,
250258
url: e.currentTarget.href

src/layouts/word.astro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,26 @@ const editUrl = `/editor/edit/${frontmatter.url.split("/")[3].split(".")[0]}`;
5454
<article class="w-full max-w-screen-lg prose">
5555
<slot />
5656
</article>
57+
58+
<!-- Scripts
59+
TODO [THOUGHTS]: I didn't want to implement anything using the `script` tag at all, but this looked to be..
60+
..the only means of adding current word to recent searches when word is opened on client-side, will be..
61+
..nice if we can find another means ;)
62+
-->
63+
<script>
64+
/**
65+
* This (Commented out for now) should rightfully add current word to recentSearches on view; which should..
66+
* ..extract the functionality from the `search` island `onClick` search result..
67+
* ..but see @todo below
68+
*
69+
* @todo it's exhibiting similar behaviour reported in issue @link below
70+
* @link https://github.com/babblebey/jargons.dev/issues/10
71+
*/
72+
// import { $addToRecentSearchesFn } from "../lib/stores/search.js";
73+
// $addToRecentSearchesFn({
74+
// word: document.querySelector("h1").textContent.trim(),
75+
// url: document.location.href
76+
// });
77+
</script>
5778
</main>
5879
</BaseLayout>

0 commit comments

Comments
 (0)