Skip to content

Commit

Permalink
Implemented useTajpuriya hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Thepuja committed Jul 15, 2024
1 parent c649cbf commit b3a3a82
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 66 deletions.
66 changes: 0 additions & 66 deletions nepalingo-web/src/hooks/getTajpuriya.tsx

This file was deleted.

45 changes: 45 additions & 0 deletions nepalingo-web/src/hooks/useTajpuriya.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useState, useEffect } from "react";
import { DictionaryProps } from "./useDictionary";

const useTajpuriya = (props: Omit<DictionaryProps, 'language'>) => {

const word = props.word
const [translatedText, setTranslatedText] = useState("")
const [dictionaryText, setDictionaryText] = useState("");
useEffect(() => {
const sourceFile = "./TajpuriyaDictionary.csv";

fetch(sourceFile)
.then((r) => r.text())
.then((text) => {

setDictionaryText(text);
})
.catch((error) => {
console.error("Error fetching words:", error);
});

}, []);

useEffect(() => {
if (dictionaryText) {
const loadDict = () => {
const dictArray = dictionaryText.split("\n")
dictArray.forEach((line) => {

const [englishWord, tajpuriyaWord] = line.split(",")

if (englishWord == word) {

setTranslatedText(tajpuriyaWord)
}
})
};
loadDict();
}

}, [dictionaryText, word]);
return translatedText

};
export default useTajpuriya;

0 comments on commit b3a3a82

Please sign in to comment.