React app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

102 line
4.2 KiB

  1. import React, { useState } from "react";
  2. import styles from './WordDetails.module.scss';
  3. import { userProfileData } from "../../App";
  4. import queryString from 'query-string';
  5. import { useLocation } from "react-router-dom";
  6. import { IShelf } from "../../structure/shelf";
  7. import { IWord } from "../../structure/word";
  8. import { ReactComponent as SpeakerIcon } from '../../assets/icons/speaker.svg';
  9. import { ReactComponent as MoreIcon } from '../../assets/icons/more-alt.svg';
  10. import { ReactComponent as ChevronLeft } from '../../assets/icons/chevron-left.svg';
  11. import { ReactComponent as PlusIcon } from '../../assets/icons/plus.svg';
  12. export const WordDetails: React.FC = () => {
  13. const location = useLocation();
  14. const category_id: any = queryString.parse(location.pathname)['/word-details/category_id'];
  15. const shelf_id: any = queryString.parse(location.pathname)['shelf_id'];
  16. const word_id: any = queryString.parse(location.pathname)['word_id'];
  17. const shelf: IShelf = userProfileData.categories[category_id].shelves[shelf_id];
  18. const word: IWord = shelf.words[word_id];
  19. const [showAddWord, setShowAddWord] = useState<Boolean>(false);
  20. const [newNote, setNewNote] = useState<string>('');
  21. return <section className="modalPage">
  22. <header className={styles.navHeader}>
  23. <button onClick={() => window.history.back()}>
  24. <ChevronLeft />
  25. </button>
  26. <h5> { shelf.name } </h5>
  27. <figure>
  28. {/* eslint-disable-next-line */}
  29. <img src={ userProfileData.image } alt="profile-image" />
  30. </figure>
  31. </header>
  32. <section className={styles.cardDetails}>
  33. { word.tag && <span className={styles.tag}> { word.tag } </span> }
  34. <div className={styles.container}>
  35. <button className={styles.audioButton}>
  36. <SpeakerIcon />
  37. </button>
  38. <h2> { word.name } <span> { word.pronounciation } </span> </h2>
  39. <button className={styles.moreButton}>
  40. <MoreIcon />
  41. </button>
  42. </div>
  43. <ul className={styles.multipleMeaningList}>
  44. { word.grammaticalDetails.map((detail, index) => {
  45. return <li key={index}>
  46. <h6> { detail.typeName } </h6>
  47. <p> { detail.description } </p>
  48. { detail.sentence && <p className={styles.sentence}> "{ detail.sentence }" </p> }
  49. </li>
  50. }) }
  51. { word.similarWords.length > 0 && <li>
  52. <h6> Similar: </h6>
  53. <div className={styles.wordLinks}>
  54. { word.similarWords.map((similarWord, index) => <button key={index}> { similarWord } </button>) }
  55. </div>
  56. </li> }
  57. </ul>
  58. </section>
  59. <section className={styles.notes}>
  60. <header>
  61. <h5> My Notes: </h5>
  62. <button onClick={() => setShowAddWord(true)}> Add Notes </button>
  63. </header>
  64. { word.notes && <ol>
  65. { word.notes.map((note, index) => <li> {note} </li>) }
  66. </ol> }
  67. </section>
  68. { showAddWord && <div className={styles.popupHolder}>
  69. <div className={styles.background} onClick={() => setShowAddWord(false)}></div>
  70. <section className={styles.popup}>
  71. <header>
  72. <PlusIcon />
  73. <h5> Add Category </h5>
  74. </header>
  75. <section className={styles.form}>
  76. <textarea placeholder={'Enter your notes here'} onInput={(e) => {
  77. setNewNote(e.currentTarget.value);
  78. }}></textarea>
  79. <button className={styles.addButton} disabled={!newNote}
  80. onClick={() => {
  81. userProfileData.categories[category_id].shelves[shelf_id].words[word_id].notes?.push(newNote);
  82. setShowAddWord(false);
  83. }}>
  84. Add
  85. </button>
  86. </section>
  87. </section>
  88. </div> }
  89. </section>
  90. }