import React, { useState } from "react"; import styles from './AddWord.module.scss'; import { ReactComponent as ChevronLeft } from '../../assets/icons/chevron-left.svg'; import { ReactComponent as SearchIcon } from '../../assets/icons/bx-search-alt.svg'; import { ReactComponent as SpeakerIcon } from '../../assets/icons/speaker.svg'; import { ReactComponent as AddIcon } from '../../assets/icons/plus.svg'; import { NavLink, useHistory } from "react-router-dom"; import { userProfileData } from "../../App"; import { getWordResult } from "../../services/words"; import { Word } from "../../shared/models/word"; export const AddWord: React.FC = () => { const [searchResult, setSearchResult] = useState>(); const [selectedWord, setSelectedWord] = useState(); const [searchWord, setSearchWord] = useState(''); const history = useHistory(); const searchWords = () => { if (searchWord.length > 0) { getWordResult(searchWord).then((wordResult: any) => { let result: Array = wordResult.data; setSearchResult(result); }, err => { console.log("Unable to search Words", err) }); } } return
{!selectedWord &&
Add a Word
} {selectedWord &&
Add to Shelf
}
{/* eslint-disable-next-line */} profile-image
{!selectedWord &&
setSearchWord(event.currentTarget.value)} />
{ searchResult &&
    {searchResult.map((word) => { return
  • {word.name} {word.pronounciation}

    {word.grammaticalDetails[0]?.type}

    {word.grammaticalDetails[0]?.description}

  • })}
}
} {selectedWord &&
    All Shelves
    {userProfileData.categories.map((category, categoryIndex) => { return category.shelves.map((shelf, shelfIndex) => { return
  • { let findWord = userProfileData.categories[categoryIndex].shelves[shelfIndex].words.find(word => word.name.toLowerCase().includes(selectedWord.name.toLowerCase())); if (findWord) { alert("Word already Present!"); } else { // userProfileData.categories[categoryIndex].shelves[shelfIndex].words.push(selectedWord); history.push('/shelf-details/category_id=' + categoryIndex + '&&shelf_id=' + shelfIndex); } }}>
    {category.icon}
    {category.name}
  • }) })} Create New Shelf
}
}