From 12fc9778e169327a36807bdd6330d4ecc78bbcfd Mon Sep 17 00:00:00 2001 From: Jason Suarez Date: Fri, 29 Mar 2024 11:19:51 +0100 Subject: [PATCH 1/2] Update project name in package.json and add tasks for vscode --- .vscode/tasks.json | 24 ++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..dfa617e --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,24 @@ + +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + // { + // "label": "dev npm", + // "type": "npm", + // "script": "dev", + // "runOptions": { + // "runOn": "folderOpen" + // }, + + // }, + { + "label": "dev shell", + "type": "shell", + "command": "npm run dev", + "runOptions": { + "runOn": "folderOpen"} + } + ] +} \ No newline at end of file diff --git a/package.json b/package.json index 25d8014..57dd58c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "my-project", + "name": "dico", "version": "0.1.0", "private": true, "scripts": { From f3e809d90a19085eb90a2773942854943c686bc8 Mon Sep 17 00:00:00 2001 From: Jason Suarez Date: Fri, 29 Mar 2024 11:29:49 +0100 Subject: [PATCH 2/2] Refactor input word handling and fix error message --- src/components/Main.tsx | 5 +++-- src/hooks/useSearch.ts | 8 +++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/components/Main.tsx b/src/components/Main.tsx index ca6f1f7..de612bc 100644 --- a/src/components/Main.tsx +++ b/src/components/Main.tsx @@ -24,7 +24,8 @@ export default function Main() { //! Memoize the toast const toasty = new Toasts(toast); const handleInputWord = (e: React.ChangeEvent) => { - return setWord(e.target.value); + const wordFormatted = e.target.value.trim().toLowerCase(); + return setWord(wordFormatted); }; function handleSubmission(e: React.FormEvent) { e.preventDefault(); @@ -35,7 +36,7 @@ export default function Main() { setWord(""); return; } - setSearch(word.trim().toLowerCase()); + setSearch(word); } return ( <> diff --git a/src/hooks/useSearch.ts b/src/hooks/useSearch.ts index 1297818..d8751c4 100644 --- a/src/hooks/useSearch.ts +++ b/src/hooks/useSearch.ts @@ -23,11 +23,9 @@ export function useSearchWord() { setIsLoading(true); // Check if word is in local storage - const isWord = LocalStorageCache.hasItem(word.trim().toLocaleLowerCase()); + const isWord = LocalStorageCache.hasItem(word); if (isWord) { - const localTrad = LocalStorageCache.getItem( - word.trim().toLocaleLowerCase() - ); + const localTrad = LocalStorageCache.getItem(word); setTranslations(localTrad); setIsTranslations(true); setIsLoading(false); @@ -43,7 +41,7 @@ export function useSearchWord() { setIsLoading(false); setWord(""); if (error.statusCode === 404) { - toasty.error("❌ Mot introuvable dans le dictionnaire."); + toasty.error("❌ Mot introuvable dans le dictionnaire."); return; } toasty.unknown();