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.

CategoryDetails.tsx 4.6 KiB

пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import React, { useState } from "react";
  2. import styles from './CategoryDetails.module.scss';
  3. import { useLocation } from 'react-router';
  4. import queryString from 'query-string';
  5. import { ReactComponent as ChevronLeft } from '../../assets/icons/chevron-left.svg';
  6. import { ReactComponent as SearchIcon } from '../../assets/icons/bx-search-alt.svg';
  7. import { ReactComponent as PlusCircledIcon } from '../../assets/icons/plus-circle.svg';
  8. import { ReactComponent as ComposeIcon } from '../../assets/icons/compose.svg';
  9. import { ReactComponent as ExportLine } from '../../assets/icons/export-line.svg';
  10. import { CircularProgressbar } from "react-circular-progressbar";
  11. import { NavLink } from "react-router-dom";
  12. import { IShelf } from "../../structure/shelf";
  13. import { useHistory } from "react-router-dom";
  14. import { userProfileData } from "../../App";
  15. import { PopoverOptions } from "../popover-options/PopoverOptions";
  16. export const CategoryDetails: React.FC = () => {
  17. const location = useLocation();
  18. const category_id: any = queryString.parse(location.pathname)['/category-details/category_id'];
  19. const shelfCount: number = userProfileData.categories[category_id].shelves.length;
  20. const [shelfResult, setShelfResult] = useState<Array<IShelf>>(userProfileData.categories[category_id].shelves);
  21. const history = useHistory();
  22. const searchShelf = (text: string) => {
  23. if (text.length > 0) {
  24. let result = userProfileData.categories[category_id].shelves.filter(shelf => {
  25. return shelf.name.toLowerCase().includes(text.toLowerCase());
  26. });
  27. setShelfResult(result);
  28. } else {
  29. setShelfResult(userProfileData.categories[category_id].shelves);
  30. }
  31. }
  32. return <section className="modalPage">
  33. <header className={styles.navHeader}>
  34. <button onClick={() => window.history.back()}>
  35. <ChevronLeft />
  36. </button>
  37. <h5> Shelves </h5>
  38. <figure>
  39. {/* eslint-disable-next-line */}
  40. <img src={ userProfileData.image } alt="profile-image" />
  41. </figure>
  42. </header>
  43. <header className={styles.tabHeading}>
  44. <div className={styles.icon}>
  45. { userProfileData.categories[category_id].icon }
  46. </div>
  47. <div className={styles.headingDetails}>
  48. <h4> { userProfileData.categories[category_id].name } </h4>
  49. <p> { shelfCount } { shelfCount > 1 ? 'Shelves' : 'Shelf' } </p>
  50. </div>
  51. <PopoverOptions options={[{
  52. icon: <ComposeIcon />,
  53. title: 'Edit',
  54. function: () => { console.log("Edit Clicked") }
  55. }]} />
  56. </header>
  57. <section className={styles.searchHolder}>
  58. <div className={styles.searchBar}>
  59. <input type="text" placeholder={'Search Shelves'} onInput={(event) => searchShelf(event.currentTarget.value)} />
  60. <SearchIcon />
  61. </div>
  62. </section>
  63. <NavLink to={'/add-shelf'} className={styles.addButton}>
  64. <PlusCircledIcon /> Add Shelf
  65. </NavLink>
  66. <section className={styles.Shelf}>
  67. <ul>
  68. { shelfResult.map((shelf, index) => {
  69. return <li key={shelf.name} onClick={() => {
  70. history.push('/shelf-details/category_id=' + category_id + '&&shelf_id=' + index);
  71. }}>
  72. <div className={styles.progress}>
  73. <CircularProgressbar value={shelf.words.length > 0 ? (shelf.revisedWords.length * 100/ shelf.words.length) : 0} strokeWidth={7}
  74. styles={{
  75. path: {
  76. stroke: 'white',
  77. strokeLinecap: 'round',
  78. },
  79. trail: {
  80. stroke: 'rgba(255, 255, 255, 0.25)',
  81. strokeLinecap: 'round',
  82. }}
  83. } />
  84. <span className={styles.text}> { shelf.words.length > 0 ? (shelf.revisedWords.length * 100/ shelf.words.length) : 0 }% </span>
  85. </div>
  86. <h5> { shelf.name } </h5>
  87. <p> { shelf.words.length } words </p>
  88. </li>
  89. }) }
  90. </ul>
  91. </section>
  92. </section>
  93. }