From d7a08bbf0979ae88809eb37dda5bab3a021e4645 Mon Sep 17 00:00:00 2001 From: Wysogota Date: Mon, 22 Aug 2022 17:36:46 +0300 Subject: [PATCH] Fix undefined container position --- .../src/components/Title/TagButtons/index.jsx | 53 ++++++++----------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/client/src/components/Title/TagButtons/index.jsx b/client/src/components/Title/TagButtons/index.jsx index 3253417..c66f206 100644 --- a/client/src/components/Title/TagButtons/index.jsx +++ b/client/src/components/Title/TagButtons/index.jsx @@ -1,16 +1,19 @@ import React, { useEffect, useRef, useState } from 'react'; import { useSelector } from 'react-redux'; +import { Link } from 'react-router-dom'; import { Button, Dropdown } from 'react-bootstrap'; import { isEmpty } from 'lodash'; import cx from 'classnames'; +import { getLocaleValue } from '../../../common/functions'; import styles from './TagButtons.module.scss'; -import { Link } from 'react-router-dom'; import CONSTANTS from '../../../constants'; const { PARAM_NAME: { FILTER: { TAGS } }, PAGES: { CATALOG: { path } } } = CONSTANTS; +const getPath = (id) => `${path}?${TAGS}=${id}`; + const TagButtons = (props) => { const { tags, tagClassName, shouldOverflow } = props; const { theme, theme: { invertedColor, mainColor, bgInvertedHoveredTheme } } = useSelector(({ themes }) => themes); @@ -35,7 +38,7 @@ const TagButtons = (props) => { }, []); useEffect(() => { - if (shouldOverflow) { + if (shouldOverflow && containerPosition) { if (!isEmpty(tagsRef.current)) { tagsRef.current.forEach((tag) => { @@ -67,8 +70,6 @@ const TagButtons = (props) => { } }, [tagsRef, theme, overflowedTagsRef, containerPosition]); - const getPath = (id) => `${path}?${TAGS}=${id}`; - const containerClasses = cx( shouldOverflow ? styles.visible_container : styles.conatiner ); @@ -93,36 +94,28 @@ const TagButtons = (props) => { return (
{ - tags.map(({ id, attributes: { name } }, i) => { - const localeName = name[CONSTANTS.DEFAULT_LOCALE]; - return ( - - ); - }) + tags.map(({ id, attributes: { name } }, i) => ( + + )) }
{shouldOverflow && shouldDisplayDropdown && { - tags.map(({ id, attributes: { name } }, i) => { - const localeName = name[CONSTANTS.DEFAULT_LOCALE]; - return ( - overflowedTagsRef.current[i] = tag} - className={overflowedTagsClasses} - > - {localeName} - - ); - }) + tags.map(({ id, attributes: { name } }, i) => ( + overflowedTagsRef.current[i] = tag} + className={overflowedTagsClasses} + > + {getLocaleValue(name)} + + )) } }