Skip to content

Commit 525d2b2

Browse files
authored
chore: go oss (#63) follow-up nits (#64)
### Description <!-- Please add PR description (don't leave blank) - example: This PR [adds/removes/fixes/replaces] the [feature/bug/etc] --> This Pull request implements some tiny changes carried over from #63 and addresses some todo that are simple enough. #### Changes Made - Implemented the submission visual cue on the word editor - this turns the submission loading button green after a word submission is successfully done before the redirection to he jargons editor dashboard - Added "babblebey" to funding/sponsor this project section - Extracted `addToRecentSearches` logic from `search` to `word.astro` layout - this ensures that words are added to recent searches when viewed and not only when they are searched using the search feature ### Related Issue <!-- Please prefix the issue number with Fixes/Resolves - example: Fixes #123 or Resolves #123 --> - Resolves #10 - #55 & #63 ### Screenshots/Screencasts <!-- Please provide screenshots or video recording that demos your changes (especially if it's a visual change) --> [screencast-bpconcjcammlapcogcnnelfmaeghhagj-2024.04.26-21_45_48.webm](https://github.com/babblebey/jargons.dev/assets/25631971/6ae8e447-9791-4de5-8ff9-46eb10bd2b8a) ### Notes to Reviewer <!-- Please state here if you added a new npm packages, or any extra information that can help reviewer better review you changes --> _NA_
1 parent 1a33f06 commit 525d2b2

7 files changed

Lines changed: 38 additions & 39 deletions

File tree

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: [babblebey]

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,8 @@ We welcome contributions to jargons.dev! There are two main ways you can contrib
7575
2. **Other Contributions:**
7676
Theses are contributions other than adding or editing words in the dictionary, feel free to contribute in other ways such as code improvements, bug fixes, or feature enhancements.
7777

78-
To get started with contributing, please refer to our [Contribution Guide](./CONTRIBUTING.md). Thank you for contributing to the jargons.dev project!
78+
To get started with contributing, please refer to our [Contribution Guide](./CONTRIBUTING.md). Thank you for contributing to the jargons.dev project!
79+
80+
## Support
81+
82+
Do leave the project a star ⭐️

src/components/islands/search.jsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,6 @@ 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-
*/
163-
$addToRecentSearchesFn({
164-
word: word.textContent,
165-
url: word.href
166-
});
167159
router.push(word.href);
168160
}
169161
}
@@ -249,14 +241,6 @@ function SearchResult({ result = [], cursor, searchTerm }) {
249241
href={`/browse/${doc.slug}`}
250242
onClick={(e) => {
251243
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-
*/
256-
$addToRecentSearchesFn({
257-
word: e.currentTarget.textContent,
258-
url: e.currentTarget.href
259-
});
260244
router.push(e.currentTarget.href);
261245
}}
262246
className={`${cursor === i && "bg-gray-100 _cursor"} flex items-center justify-between no-underline w-full p-2 md:p-4 hover:bg-gray-100`}

src/components/islands/word-editor.jsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useStore } from "@nanostores/react";
44
import useRouter from "../../lib/hooks/use-router.js";
55
import { capitalizeText } from "../../lib/utils/index.js";
66
import useWordEditor from "../../lib/hooks/use-word-editor.js";
7-
import { $isWordSubmitLoading } from "../../lib/stores/dictionary.js";
7+
import { $isWordSubmitLoading, $isWordSubmitted } from "../../lib/stores/dictionary.js";
88

99
/**
1010
* Main Word Editor Component - Island
@@ -28,16 +28,21 @@ export default function WordEditor({ title = "", content = "", metadata = {}, ac
2828
* Detached Editor Submit Button Component - Island
2929
*/
3030
export function SubmitButton({ children = "Submit" }) {
31+
const isSubmitted = useStore($isWordSubmitted);
3132
const isSubmitLoading = useStore($isWordSubmitLoading);
3233

3334
return (
34-
<button className="flex items-center justify-center no-underline text-white bg-gray-900 hover:bg-gray-700 focus:ring-0 font-medium rounded-lg text-base px-5 py-2.5 text-center ml-1 sm:ml-3"
35+
<button className={`flex items-center justify-center no-underline text-white ${isSubmitted ? "bg-green-700" : "bg-gray-900 hover:bg-gray-700"} focus:ring-0 font-medium rounded-lg text-base px-5 py-2.5 text-center ml-1 sm:ml-3`}
3536
type="submit"
3637
form="jargons.dev:word_editor"
37-
disabled={isSubmitLoading}
38+
disabled={isSubmitLoading || isSubmitted}
3839
>
3940
{ isSubmitLoading ? (
4041
<div className="flex-none h-4 w-4 md:w-6 md:h-6 rounded-full border-2 border-gray-400 border-b-gray-200 border-r-gray-200 animate-spin" />
42+
) : !isSubmitLoading && isSubmitted ? (
43+
<svg className="h-4 w-4 md:w-6 md:h-6 text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
44+
<path stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M5 11.917 9.724 16.5 19 7.5"/>
45+
</svg>
4146
) : (
4247
children
4348
) }
@@ -50,7 +55,11 @@ export function SubmitButton({ children = "Submit" }) {
5055
*/
5156
function Editor({ eTitle, eContent, eMetadata, className, action, ...props }) {
5257
const router = useRouter();
58+
const isSubmitted = useStore($isWordSubmitted);
59+
const isSubmitLoading = useStore($isWordSubmitLoading);
5360
const { title, setTitle, content, setContent } = useWordEditor();
61+
62+
const isDone = isSubmitLoading || isSubmitted;
5463

5564
useEffect(() => {
5665
setTitle(eTitle);
@@ -61,7 +70,6 @@ function Editor({ eTitle, eContent, eMetadata, className, action, ...props }) {
6170
* Word Submit Handler
6271
* @param {import("react").FormEvent} e
6372
*
64-
* @todo implement a submitted State that updates after submission for visual cue before routing
6573
* @todo handle error for when submission isn't successful
6674
*/
6775
async function handleSubmit(e) {
@@ -71,6 +79,8 @@ function Editor({ eTitle, eContent, eMetadata, className, action, ...props }) {
7179
method: "POST",
7280
body: formData,
7381
});
82+
$isWordSubmitted.set(true);
83+
$isWordSubmitLoading.set(false);
7484
response.status === 200 && router.push("/editor");
7585
}
7686

@@ -91,17 +101,18 @@ function Editor({ eTitle, eContent, eMetadata, className, action, ...props }) {
91101
name="title"
92102
value={title}
93103
placeholder="New Word"
94-
readOnly={action === "edit"}
95104
onChange={(e) => setTitle(e.target.value)}
96-
className={`${action === "edit" && "cursor-not-allowed"} block w-full pb-2 mb-3 text-gray-900 border-b text-lg font-bold focus:outline-none`}
105+
readOnly={action === "edit" || isDone}
106+
className={`${(action === "edit" || isDone) && "cursor-not-allowed"} block w-full pb-2 mb-3 text-gray-900 border-b text-lg font-bold focus:outline-none`}
97107
/>
98108
<textarea
99109
required
100110
id="content"
101111
name="content"
102112
value={content}
103113
onChange={(e) => setContent(e.target.value)}
104-
className="w-full h-1 grow resize-none appearance-none border-none focus:outline-none scrollbar"
114+
readOnly={isDone}
115+
className={`${isDone && "cursor-not-allowed select-none"} w-full h-1 grow resize-none appearance-none border-none focus:outline-none scrollbar`}
105116
/>
106117
<input
107118
type="hidden"
@@ -182,7 +193,7 @@ const DummyPreviewNavbar = () => (
182193
<><span className="text-sm mr-0.5"></span>K</>
183194
</kbd>
184195
</div>
185-
<button className="flex @md:hidden font-bold">
196+
<button className="cursor-not-allowed flex @md:hidden font-bold">
186197
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-5 h-5">
187198
<path strokeLinecap="round" strokeLinejoin="round" d="m21 21-5.197-5.197m0 0A7.5 7.5 0 1 0 5.196 5.196a7.5 7.5 0 0 0 10.607 10.607Z" />
188199
</svg>

src/layouts/word.astro

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,11 @@ const editUrl = `/editor/edit/${frontmatter.url.split("/")[3].split(".")[0]}`;
6161
..nice if we can find another means ;)
6262
-->
6363
<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-
// });
64+
import { $addToRecentSearchesFn } from "../lib/stores/search.js";
65+
$addToRecentSearchesFn({
66+
word: document.querySelector("h1").textContent.trim(),
67+
url: document.location.href
68+
});
7769
</script>
7870
</main>
7971
</BaseLayout>

src/lib/stores/dictionary.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ export const $wordEditor = map({
1717
content: ""
1818
});
1919

20-
export const $isWordSubmitLoading = atom(false);
20+
export const $isWordSubmitLoading = atom(false);
21+
22+
export const $isWordSubmitted = atom(false);

src/lib/stores/search.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export const $recentSearches = map({});
1818
* @todo implement logic to allow holding maximum of 5 words by removing older words when new a one gets added
1919
*/
2020
export function $addToRecentSearchesFn({ word, url }) {
21+
// Re-initialise the state with current localStorage value
22+
$recentSearches.set({...JSON.parse(localStorage.getItem("jargons.dev:recent_searches"))});
23+
2124
const lowercaseKey = word.toLowerCase();
2225
const key = lowercaseKey.includes(" ") ? lowercaseKey.split(" ").join("-") : lowercaseKey;
2326
const isInRecentSearch = $recentSearches.get()[key];

0 commit comments

Comments
 (0)