Skip to content

Commit

Permalink
added useQuote hook
Browse files Browse the repository at this point in the history
  • Loading branch information
NancyAanchal committed Jul 9, 2024
1 parent e41dfbb commit f2c8717
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 65 deletions.
14 changes: 0 additions & 14 deletions Tajpuriya quotes.txt

This file was deleted.

1 change: 1 addition & 0 deletions nepalingo-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"ts-node": "^10.9.2",
"typescript": "^5.5.2",
"vite": "^5.3.1",
"vite-plugin-string": "^1.2.3",
"vite-tsconfig-paths": "^4.3.2"
}
}
83 changes: 64 additions & 19 deletions nepalingo-web/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions nepalingo-web/src/components/userAuth/UserAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const User_auth: React.FC = () => {
setAction(newAction);
setError(null);
setSuccess(false);
setEmail(""); // the email and password field will reset everytime action is changed
setPassword("");
};

return (
Expand Down
64 changes: 33 additions & 31 deletions nepalingo-web/src/hooks/useNewari.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
import useSWR from 'swr'
import { DictionaryProps, DictionaryResponse } from './useDictionary'
import useSWR from "swr";
import { DictionaryProps, DictionaryResponse } from "./useDictionary";

const fetcher = (url: string) =>
fetch(import.meta.env.VITE_NEPALBHASA_API_URL + url, {}).then((r) =>
r.json()
);

const fetcher = (url: string) => fetch(import.meta.env.VITE_NEPALBHASA_API_URL + url, {
}).then(r => r.json())
const useNewari = (props: Omit<DictionaryProps, "language">) => {
let { data, error, isLoading } = useSWR(

Check failure on line 10 in nepalingo-web/src/hooks/useNewari.tsx

View workflow job for this annotation

GitHub Actions / test_build

'data' is never reassigned. Use 'const' instead

Check failure on line 10 in nepalingo-web/src/hooks/useNewari.tsx

View workflow job for this annotation

GitHub Actions / test_build

'error' is never reassigned. Use 'const' instead

Check failure on line 10 in nepalingo-web/src/hooks/useNewari.tsx

View workflow job for this annotation

GitHub Actions / test_build

'isLoading' is never reassigned. Use 'const' instead
`/dict/en/search/${props.word}`,
fetcher
);

const useNewari = (props: Omit<DictionaryProps, 'language'>) => {
let { data, error, isLoading } = useSWR(`/dict/en/search/${props.word}`, fetcher)
let response: DictionaryResponse = {

Check failure on line 15 in nepalingo-web/src/hooks/useNewari.tsx

View workflow job for this annotation

GitHub Actions / test_build

'response' is never reassigned. Use 'const' instead
language: "newari",
word: props.word,
//Mapping the meanings from the api to create a custom response based on DictionaryResponse
meanings: data?.meanings?.map(
(meaning: {
audio?: { file: string; directory: string };
image?: string;
meaning_np?: string;
meaning_nb?: string;
meaning_en?: string;
}) => ({
audio: meaning?.audio,
image: meaning?.image,
meaningOriginal: meaning?.meaning_nb,
meaningNp: meaning?.meaning_np,
meaningEn: meaning?.meaning_en,
})
),
};

let response: DictionaryResponse = {
language: 'newari',
word: props.word,
//Mapping the meanings from the api to create a custom response based on DictionaryResponse
meanings:
data?.meanings?.map((meaning: {
audio?: { file: string, directory: string },
image?: string,
meaning_np?: string,
meaning_nb?: string,
meaning_en?: string,
}) => (
{
audio: meaning?.audio,
image: meaning?.image,
meaningOriginal: meaning?.meaning_nb,
meaningNp: meaning?.meaning_np,
meaningEn: meaning?.meaning_en,

})
)
}

return { response, error, isLoading }
}
return { response, error, isLoading };
};

export default useNewari;
Loading

0 comments on commit f2c8717

Please sign in to comment.