Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chosen tags #258

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions app/[locale]/projects/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,23 @@ const ProjectsPage = () => {
setLoading(true);
const existingTags = structuredClone(tags);

// we set tag active to true
for (const exisitingTag of existingTags) {
// we set tags chosen to active and all the others to not
if (existingTags.every(value => value.isActive)) {
existingTags.forEach(existingTag => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of putting comment explaining your code you could extract this part into a function and call it

existingTag.isActive = false;
});
}

existingTags.forEach(exisitingTag => {
if (exisitingTag.name === tag.name) {
exisitingTag.isActive = !exisitingTag.isActive;
break;
}
});

if (existingTags.every(value => !value.isActive)) {
existingTags.forEach(existingTag => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can save the existingTags.every(value => !value.isActive from before into a boolean and check it in here (you would probably need to check for !yourBooleanValue)

And you will save one array function

existingTag.isActive = true;
});
}

setTags(existingTags);
Expand Down
8 changes: 4 additions & 4 deletions components/Projects/FiltersBar/FilterBtnsGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ const FilterBtnsGroup = ({
filters,
handleFilterOptionChange,
}: FilterBtnsGroupProps) => {
const handleBtnFilterClick = (filter: ProjectFilter) => {
handleFilterOptionChange(filter);
};
// const handleBtnFilterClick = (filter: ProjectFilter) => {
// handleFilterOptionChange(filter);
// };

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the comments please

return (
<div className="flex gap-2 flex-wrap">
{filters.map(filter => (
<FilterBtn
key={filter.name}
filter={filter}
onBtnClick={() => handleBtnFilterClick(filter)}
onBtnClick={() => handleFilterOptionChange(filter)}
/>
))}
</div>
Expand Down
64 changes: 11 additions & 53 deletions components/Projects/FiltersBar/FiltersBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Link from 'next/link';
import { ProjectPaginationFilter } from '@/types/project';
import { useTranslations } from 'next-intl';
import { SearchInput } from '@/components/Common/Inputs/SearchInput';
import FiltersWindow from './FiltersWindow';

interface FiltersBarProps {
filters: ProjectFilter[];
Expand Down Expand Up @@ -115,59 +116,16 @@ const FiltersBar: React.FC<FiltersBarProps> = ({
height={27}
/>
{/* settings window on burger click */}
{toggleFiltersWindow ? (
<>
<div
ref={filterRef}
className="z-[101] absolute -bottom-[23.5rem] md:-bottom-[16.75rem] right-2 px-[34px] py-[27px] rounded-md border border-blue-600 min-w-[300px] md:min-w-0 md:w-[863px] min-h-[260px] md:h-[209px] p-5 bg-gray-50 dark:bg-gray-600"
>
<div className="flex flex-col gap-[22px]">
<h3 className="text-base font-bold leading-normal">
{t('projectsFilters')}{' '}
</h3>
{/* sort by ProjectPaginationFilter (sortoptions,sortoptionsmapper) */}
<div className="flex gap-4 md:gap-[26px] justify-center md:justify-normal md:items-center">
<span className="body-roman text-gray-500 dark:text-gray-400 w-[60px] max-w-[60px]">
{t('filters')}
</span>
<div className="flex gap-[18px] md:gap-10 flex-wrap w-full">
{sortOptions.map(sortOption => (
<Radiobox
key={sortOption}
id={sortOption}
value={sortOption}
checked={selectedSortOption === sortOption}
onChange={handleCategoryOptionSelection}
/>
))}
</div>
</div>
{/* sort by set languages */}
<div className="flex gap-4 md:gap-[26px] justify-center md:justify-normal md:items-center">
<span className="body-roman text-gray-500 dark:text-gray-400 w-[60px] max-w-[60px] leading-tight">
{t('tags')}
</span>
<div className="flex gap-2 flex-wrap w-full">
{filters.map(filter => (
<FilterTagBtn
key={filter.name}
btnText={filter.name}
toggleIsFilterActive={() =>
handleFilterOptionChange(filter)
}
isSelected={filter.isActive}
/>
))}
</div>
</div>
</div>
<div className="absolute -top-[0.75rem] right-[10px] -mb-[1px] inline-block overflow-hidden">
<div className="h-3 w-[18px] origin-bottom-left rotate-45 transform border border-blue-600 bg-gray-50 dark:bg-gray-500 "></div>
</div>
</div>
<div className="fixed z-[100] top-0 left-0 w-full h-screen opacity-[30%] bg-gray-900" />
</>
) : null}
{toggleFiltersWindow && (
<FiltersWindow
filterRef={filterRef}
sortOptions={sortOptions}
selectedSortOption={selectedSortOption}
handleCategoryOptionSelection={handleCategoryOptionSelection}
filters={filters}
handleFilterOptionChange={handleFilterOptionChange}
/>
)}
</div>
<SearchInput
onChange={setSearchByProjectName}
Expand Down
79 changes: 79 additions & 0 deletions components/Projects/FiltersBar/FiltersWindow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import Radiobox from '@/components/utils/Radiobox';
import React, { Ref } from 'react';
import { useTranslations } from 'next-intl';
import FilterTagBtn from './FilterTagBtn';
import { ProjectFilter } from '@/types';

interface FiltersWindow {
filterRef: Ref<HTMLDivElement>;
sortOptions: string[];
selectedSortOption: any;
handleCategoryOptionSelection: any;
filters: ProjectFilter[];
handleFilterOptionChange: any;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the name to FiltersWindowProps like we do in the project for components props.

Also don't use any , change your interface to have defined values.

const FiltersWindow = ({
filterRef,
sortOptions,
selectedSortOption,
handleCategoryOptionSelection,
filters,
handleFilterOptionChange,
}: FiltersWindow) => {
const t = useTranslations('Projects.FiltersBar');

return (
<div>
<div
ref={filterRef}
className="z-[101] absolute -bottom-[23.5rem] md:-bottom-[16.75rem] right-2 px-[34px] py-[27px] rounded-md border border-blue-600 min-w-[300px] md:min-w-0 md:w-[863px] min-h-[260px] md:h-[209px] p-5 bg-gray-50 dark:bg-gray-600"
>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the z-[101]? will it work with smaller z index ?

<div className="flex flex-col gap-[22px]">
<h3 className="text-base font-bold leading-normal">
{t('projectsFilters')}{' '}
</h3>
{/* sort by ProjectPaginationFilter (sortoptions,sortoptionsmapper) */}
<div className="flex gap-4 md:gap-[26px] justify-center md:justify-normal md:items-center">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment

<span className="body-roman text-gray-500 dark:text-gray-400 w-[60px] max-w-[60px]">
{t('filters')}
</span>
<div className="flex gap-[18px] md:gap-10 flex-wrap w-full">
{sortOptions.map(sortOption => (
<Radiobox
key={sortOption}
id={sortOption}
value={sortOption}
checked={selectedSortOption === sortOption}
onChange={handleCategoryOptionSelection}
/>
))}
</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional - This could be extracted into a separate component, let's say RadioboxList

</div>
{/* sort by set languages */}
<div className="flex gap-4 md:gap-[26px] justify-center md:justify-normal md:items-center">
<span className="body-roman text-gray-500 dark:text-gray-400 w-[60px] max-w-[60px] leading-tight">
{t('tags')}
</span>
<div className="flex gap-2 flex-wrap w-full">
{filters.map(filter => (
<FilterTagBtn
key={filter.name}
btnText={filter.name}
toggleIsFilterActive={() => handleFilterOptionChange(filter)}
isSelected={filter.isActive}
/>
))}
</div>
</div>
</div>
<div className="absolute -top-[0.75rem] right-[10px] -mb-[1px] inline-block overflow-hidden">
<div className="h-3 w-[18px] origin-bottom-left rotate-45 transform border border-blue-600 bg-gray-50 dark:bg-gray-500 "></div>
</div>
</div>
<div className="fixed z-[100] top-0 left-0 w-full h-screen opacity-[30%] bg-gray-900" />
</div>
);
};

export default FiltersWindow;