Skip to content

Commit

Permalink
✨ feat: add feature check spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
nxhawk committed Oct 27, 2024
1 parent f90a43a commit 34cf837
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 7 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@
"@tensorflow/tfjs-converter": "^4.22.0",
"@tensorflow/tfjs-core": "^4.22.0",
"axios": "^1.7.7",
"diff": "^7.0.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.35.0",
"framer-motion": "^11.11.10",
"lucide-react": "^0.453.0",
"next-themes": "^0.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.27.0"
"react-router-dom": "^6.27.0",
"react-speech-recognition": "^3.10.0"
},
"devDependencies": {
"@types/diff": "^5.2.3",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react-speech-recognition": "^3.9.5",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
"@vitejs/plugin-react-swc": "^3.5.0",
Expand Down
9 changes: 6 additions & 3 deletions src/components/logo/Logo.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Heading } from "@chakra-ui/react";
import { Link } from "react-router-dom";

const Logo = () => {
return (
<Heading as="h5" size="md" textTransform="uppercase">
English Hub
</Heading>
<Link to={"/"}>
<Heading as="h5" size="md" textTransform="uppercase">
English Hub
</Heading>
</Link>
);
};

Expand Down
7 changes: 6 additions & 1 deletion src/features/dictionary/DictionaryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SearchBar from "@/components/search-bar/SearchBar";
import WordResult from "@/components/word-result/WordResult";
import { searchWord } from "@/config/api/dictionary/apiDictionary";
import { IWord, IWordNotFound } from "@/types/dictionary";
import { HStack } from "@chakra-ui/react";
import { Heading, HStack, VStack } from "@chakra-ui/react";
import { AxiosResponse } from "axios";
import React from "react";
import { useSearchParams } from "react-router-dom";
Expand Down Expand Up @@ -35,6 +35,11 @@ const DictionaryPage = () => {

return (
<>
<VStack>
<Heading size="lg" textTransform="uppercase">
Dictionary
</Heading>
</VStack>
<HStack justifyContent="center" marginY="15px">
<SearchBar word={word} />
</HStack>
Expand Down
4 changes: 3 additions & 1 deletion src/features/learn-through-images/LearnThroughImagesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ const LearnThroughImagesPage = () => {
return (
<div>
<VStack marginTop={"10px"} marginBottom={"20px"}>
<Heading size="lg">Image identification</Heading>
<Heading size="lg" textTransform="uppercase">
Image identification
</Heading>
</VStack>
<HStack gap={{ base: "10px", lg: "25px" }}>
<div>
Expand Down
77 changes: 76 additions & 1 deletion src/features/spell-check/SpellCheckPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,80 @@
import "regenerator-runtime/runtime";
import SpeechRecognition, { useSpeechRecognition } from "react-speech-recognition";
import { Button, Heading, HStack, Textarea, VStack } from "@chakra-ui/react";
import React from "react";
import { CircleStop, Mic } from "lucide-react";
import TextDiff from "./TextDiff";

const SpellCheckPage = () => {
return <div>SpellCheckPage</div>;
const { transcript, listening, resetTranscript, browserSupportsSpeechRecognition } = useSpeechRecognition();
const [targetTranscript, setTargetTranscript] = React.useState<string>("");

if (!browserSupportsSpeechRecognition) {
return <span>Browser doesn&rsquo;t support speech recognition.</span>;
}

const handleStartListening = () => {
resetTranscript();
SpeechRecognition.startListening({ continuous: true });
};

const handleStopListening = () => {
SpeechRecognition.stopListening();
};

return (
<div className="mb-5">
<VStack marginTop={"10px"} marginBottom={"20px"}>
<Heading size="lg" textTransform="uppercase">
Spelling check
</Heading>
</VStack>
<HStack flexWrap={"wrap"} gap={"30px"} alignItems={"flex-start"}>
<VStack w={{ base: "100%", md: "50%" }} gap={"15px"} alignItems={"flex-start"}>
<VStack gap={"10px"} alignItems={"flex-start"} w="full">
<Heading size="lg">Target transcript</Heading>
<Textarea
width={"full"}
rows={4}
minH={"100px"}
variant={"outline"}
value={targetTranscript}
onChange={(e) => setTargetTranscript(e.target.value)}
/>
</VStack>
<VStack gap={"10px"} alignItems={"flex-start"} w="full">
<Heading size="lg">Speech to text</Heading>
<Textarea width={"full"} rows={4} minH={"200px"} variant={"outline"} isReadOnly value={transcript} />
{!listening ? (
<Button
colorScheme="blue"
textTransform="uppercase"
rightIcon={<Mic className="w-5 h-5" />}
onClick={handleStartListening}
>
start recording
</Button>
) : (
<Button
colorScheme="blue"
textTransform="uppercase"
rightIcon={<CircleStop className="w-5 h-5" />}
onClick={handleStopListening}
>
stop recording
</Button>
)}
</VStack>
</VStack>
<div className="flex-1">
<VStack gap={"10px"} alignItems={"flex-start"} w="full">
<Heading size="lg">Comparision</Heading>
<TextDiff text1={targetTranscript.toLowerCase()} text2={transcript.toLowerCase()} />
</VStack>
</div>
</HStack>
</div>
);
};

export default SpellCheckPage;
27 changes: 27 additions & 0 deletions src/features/spell-check/TextDiff.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";
import { diffChars } from "diff";

type Props = {
text1: string;
text2: string;
};

const TextDiff = ({ text1, text2 }: Props) => {
const differences = diffChars(text1, text2);
const renderDifference = (part: { value: string; added?: boolean; removed?: boolean }, index: number) => {
const style: React.CSSProperties = {
color: part.added ? "red" : part.removed ? "red" : "green",
fontSize: "25px",
};

return (
<span key={index} style={style}>
{part.value}
</span>
);
};

return <div>{differences.map(renderDifference)}</div>;
};

export default TextDiff;
27 changes: 27 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,16 @@
dependencies:
"@types/node" "*"

"@types/diff@^5.2.3":
version "5.2.3"
resolved "https://registry.yarnpkg.com/@types/diff/-/diff-5.2.3.tgz#dcdcfa40df9f011f9465180e0196dfbd921971d9"
integrity sha512-K0Oqlrq3kQMaO2RhfrNQX5trmt+XLyom88zS0u84nnIcLvFnRUMRRHmrGny5GSM+kNO9IZLARsdQHDzkhAgmrQ==

"@types/dom-speech-recognition@*":
version "0.0.4"
resolved "https://registry.yarnpkg.com/@types/dom-speech-recognition/-/dom-speech-recognition-0.0.4.tgz#3ac5eddfbaa0dacf7eca3d8979ef4f3e519d8e19"
integrity sha512-zf2GwV/G6TdaLwpLDcGTIkHnXf8JEf/viMux+khqKQKDa8/8BAUtXXZS563GnvJ4Fg0PBLGAaFf2GekEVSZ6GQ==

"@types/estree@1.0.5":
version "1.0.5"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4"
Expand Down Expand Up @@ -975,6 +985,13 @@
dependencies:
"@types/react" "*"

"@types/react-speech-recognition@^3.9.5":
version "3.9.5"
resolved "https://registry.yarnpkg.com/@types/react-speech-recognition/-/react-speech-recognition-3.9.5.tgz#7ef421e11c0d8827192022385ba58511235c6729"
integrity sha512-m3Sg3Xtj/YcEUu+nLPGwI6oq1wcSblsuyAmXgBfW6Nprfmtl+A+kH4ruPzzFKnFkq6WmmRxdsLvt0nLRAAJtBw==
dependencies:
"@types/dom-speech-recognition" "*"

"@types/react@*", "@types/react@^18.3.3":
version "18.3.3"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.3.3.tgz#9679020895318b0915d7a3ab004d92d33375c45f"
Expand Down Expand Up @@ -1684,6 +1701,11 @@ didyoumean@^1.2.2:
resolved "https://registry.yarnpkg.com/didyoumean/-/didyoumean-1.2.2.tgz#989346ffe9e839b4555ecf5666edea0d3e8ad037"
integrity sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==

diff@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-7.0.0.tgz#3fb34d387cd76d803f6eebea67b921dab0182a9a"
integrity sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw==

dir-glob@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f"
Expand Down Expand Up @@ -3408,6 +3430,11 @@ react-router@6.27.0:
dependencies:
"@remix-run/router" "1.20.0"

react-speech-recognition@^3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/react-speech-recognition/-/react-speech-recognition-3.10.0.tgz#7aa43bb28d78b92671864dabba3a70489ccad27b"
integrity sha512-EVSr4Ik8l9urwdPiK2r0+ADrLyDDrjB0qBRdUWO+w2MfwEBrj6NuRmy1GD3x7BU/V6/hab0pl8Lupen0zwlJyw==

react-style-singleton@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/react-style-singleton/-/react-style-singleton-2.2.1.tgz#f99e420492b2d8f34d38308ff660b60d0b1205b4"
Expand Down

0 comments on commit 34cf837

Please sign in to comment.