Skip to content

Commit

Permalink
Fix undefined container position
Browse files Browse the repository at this point in the history
  • Loading branch information
Wysogota committed Aug 22, 2022
1 parent eb7f369 commit d7a08bb
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions client/src/components/Title/TagButtons/index.jsx
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -35,7 +38,7 @@ const TagButtons = (props) => {
}, []);

useEffect(() => {
if (shouldOverflow) {
if (shouldOverflow && containerPosition) {

if (!isEmpty(tagsRef.current)) {
tagsRef.current.forEach((tag) => {
Expand Down Expand Up @@ -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
);
Expand All @@ -93,36 +94,28 @@ const TagButtons = (props) => {
return (
<div className={styles.tags_container}>
<div ref={containerRef} className={containerClasses}>{
tags.map(({ id, attributes: { name } }, i) => {
const localeName = name[CONSTANTS.DEFAULT_LOCALE];
return (
<Button
key={localeName}
ref={(tag) => tagsRef.current[i] = tag}
variant={invertedColor}
className={tagsClasses}
>
<Link to={getPath(id)} >{localeName}</Link>
</Button>
);
})
tags.map(({ id, attributes: { name } }, i) => (
<Button key={id}
ref={(tag) => tagsRef.current[i] = tag}
variant={invertedColor}
className={tagsClasses}
>
<Link to={getPath(id)} >{getLocaleValue(name)}</Link>
</Button>
))
}</div>
{shouldOverflow && shouldDisplayDropdown && <Dropdown>
<Dropdown.Toggle className={toggleClasses} variant={mainColor}></Dropdown.Toggle>
<Dropdown.Menu variant={invertedColor} align='end' renderOnMount>{
tags.map(({ id, attributes: { name } }, i) => {
const localeName = name[CONSTANTS.DEFAULT_LOCALE];
return (
<Dropdown.Item as={Link}
key={localeName}
to={getPath(id)}
ref={(tag) => overflowedTagsRef.current[i] = tag}
className={overflowedTagsClasses}
>
{localeName}
</Dropdown.Item>
);
})
tags.map(({ id, attributes: { name } }, i) => (
<Dropdown.Item as={Link} key={id}
to={getPath(id)}
ref={(tag) => overflowedTagsRef.current[i] = tag}
className={overflowedTagsClasses}
>
{getLocaleValue(name)}
</Dropdown.Item>
))
}</Dropdown.Menu>
</Dropdown>}
</div>
Expand Down

0 comments on commit d7a08bb

Please sign in to comment.