Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor input word #39

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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"}
}
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "my-project",
"name": "dico",
"version": "0.1.0",
"private": true,
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions src/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export default function Main() {
//! Memoize the toast
const toasty = new Toasts(toast);
const handleInputWord = (e: React.ChangeEvent<HTMLInputElement>) => {
return setWord(e.target.value);
const wordFormatted = e.target.value.trim().toLowerCase();
return setWord(wordFormatted);
};
function handleSubmission(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
Expand All @@ -35,7 +36,7 @@ export default function Main() {
setWord("");
return;
}
setSearch(word.trim().toLowerCase());
setSearch(word);
}
return (
<>
Expand Down
8 changes: 3 additions & 5 deletions src/hooks/useSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
Loading