Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Header.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import React, { useMemo } from "react";
  2. import PropTypes from "prop-types";
  3. import {
  4. CategoryHeaderIcon,
  5. HeaderAltLocation,
  6. HeaderButton,
  7. HeaderButtons,
  8. HeaderContainer,
  9. HeaderLocation,
  10. HeaderOptions,
  11. HeaderSelect,
  12. IconStyled,
  13. MySwapsTitle,
  14. RefreshIcon,
  15. SelectOption,
  16. } from "./Header.styled";
  17. import { ReactComponent as GridSquare } from "../../../assets/images/svg/offer-grid-square.svg";
  18. import { ReactComponent as GridLine } from "../../../assets/images/svg/offer-grid-line.svg";
  19. import { ReactComponent as Down } from "../../../assets/images/svg/down-arrow.svg";
  20. import selectedTheme from "../../../themes";
  21. import { sortEnum } from "../../../enums/sortEnum";
  22. import { useTranslation } from "react-i18next";
  23. import { Tooltip } from "@mui/material";
  24. import SkeletonHeader from "./SkeletonHeader/SkeletonHeader";
  25. import { useSelector } from "react-redux";
  26. import { selectHeaderString } from "../../../store/selectors/filtersSelectors";
  27. const DownArrow = (props) => (
  28. <IconStyled {...props}>
  29. <Down />
  30. </IconStyled>
  31. );
  32. const Header = (props) => {
  33. const { t } = useTranslation();
  34. const sorting = props.sorting;
  35. const headerString = useSelector(selectHeaderString);
  36. // Changing header string on refresh or on load
  37. const showAltString = useMemo(() => {
  38. return (
  39. sorting.selectedSortOption === sortEnum.INITIAL ||
  40. sorting.selectedSortOption === sortEnum.NEW ||
  41. !sorting.selectedSortOption
  42. );
  43. }, [sorting.selectedSortOption]);
  44. const handleChangeSelect = (event) => {
  45. // let chosenOption;
  46. sorting.changeSorting(event.target.value);
  47. // for (const sortOption in sortEnum) {
  48. // if (sortEnum[sortOption].value === event.target.value) {
  49. // chosenOption = sortEnum[sortOption];
  50. // sorting.changeSorting(chosenOption);
  51. // }
  52. // }
  53. };
  54. return (
  55. <>
  56. <SkeletonHeader
  57. skeleton={props.skeleton}
  58. />
  59. <HeaderContainer skeleton={props.skeleton}>
  60. {/* Setting appropriate header title if page is market place or my offers */}
  61. <Tooltip title={headerString}>
  62. <>
  63. {!props.myOffers ? (
  64. <>
  65. <CategoryHeaderIcon />
  66. <HeaderLocation initial={showAltString}>
  67. {headerString}
  68. </HeaderLocation>
  69. {showAltString && (
  70. <HeaderAltLocation>{t("header.newOffers")}</HeaderAltLocation>
  71. )}
  72. </>
  73. ) : (
  74. <MySwapsTitle>
  75. <RefreshIcon /> {t("header.myOffers")}
  76. </MySwapsTitle>
  77. )}
  78. </>
  79. </Tooltip>
  80. {/* ^^^^^^ */}
  81. <HeaderOptions>
  82. <HeaderButtons>
  83. {/* Setting display of offer cards to full width */}
  84. <HeaderButton
  85. iconColor={
  86. props.isGrid
  87. ? selectedTheme.colors.iconStrokeColor
  88. : selectedTheme.colors.primaryPurple
  89. }
  90. onClick={() => props.setIsGrid(false)}
  91. >
  92. <GridLine />
  93. </HeaderButton>
  94. {/* ^^^^^^ */}
  95. {/* Setting display of offer cards to half width (Grid) */}
  96. <HeaderButton
  97. iconColor={
  98. props.isGrid
  99. ? selectedTheme.colors.primaryPurple
  100. : selectedTheme.colors.iconStrokeColor
  101. }
  102. onClick={() => props.setIsGrid(true)}
  103. >
  104. <GridSquare />
  105. </HeaderButton>
  106. {/* ^^^^^^ */}
  107. </HeaderButtons>
  108. {/* Select option to choose sorting */}
  109. <HeaderSelect
  110. value={
  111. sorting.selectedSortOption?.value
  112. ? sorting.selectedSortOption
  113. : "default"
  114. }
  115. IconComponent={DownArrow}
  116. onChange={handleChangeSelect}
  117. >
  118. <SelectOption style={{ display: "none" }} value="default">
  119. {t("reviews.sortBy")}
  120. </SelectOption>
  121. {Object.keys(sortEnum).map((property) => {
  122. if (sortEnum[property].value === 0) return;
  123. return (
  124. <SelectOption
  125. value={sortEnum[property]}
  126. key={sortEnum[property].value}
  127. >
  128. {sortEnum[property].mainText}
  129. </SelectOption>
  130. );
  131. })}
  132. </HeaderSelect>
  133. {/* ^^^^^^ */}
  134. </HeaderOptions>
  135. </HeaderContainer>
  136. </>
  137. );
  138. };
  139. Header.propTypes = {
  140. children: PropTypes.node,
  141. setIsGrid: PropTypes.func,
  142. isGrid: PropTypes.bool,
  143. filters: PropTypes.any,
  144. category: PropTypes.string,
  145. myOffers: PropTypes.bool,
  146. skeleton: PropTypes.bool,
  147. sorting: PropTypes.any,
  148. };
  149. Header.defaultProps = {
  150. isGrid: false,
  151. };
  152. export default Header;