Skip to content

Commit

Permalink
Implementation of filters on the Activities page (As-Raparigas-do-Cod…
Browse files Browse the repository at this point in the history
  • Loading branch information
msantosdevlab authored Jul 13, 2024
1 parent 9d98bd8 commit b0dfe05
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 38 deletions.
247 changes: 212 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions src/pages/Activities/activities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,31 @@
.activity-feature-image {
width: 80px;
}

.inactiveTab, .activeTab {
padding: 6px 18px;
text-decoration: none;
margin-right: 15px;
}

.inactiveTab {
border: 1px solid $light-gray;
background-color: transparent;
color: $brand-color;
}

.activeTab {
background-color: $green;
color: $white;
border: 1px solid $green;
}

.activeTab > span, .inactiveTab > span {
padding: 5px;
background-color: $brand-color;
border-radius: 50px;
font-size: 10px;
color: $white;
line-height: 1.5;
vertical-align: middle;
}
42 changes: 39 additions & 3 deletions src/pages/Activities/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import React, { useState } from 'react';
import { Container, Row, Col } from 'react-bootstrap';

import PageLayout from 'components/PageLayout';
import OrganizationFeature from 'components/OrganizationFeature';
import EventCard from 'components/EventCard';

import Constants from 'constants';
import { sortByDesc } from 'utils';
import { sortByDesc, capitalize } from 'utils';

import projectoEducacao from '../../assets/projeto_educacao.png';
import inclusaoDigital from '../../assets/inclusao_digital.png';
Expand Down Expand Up @@ -76,15 +76,51 @@ function Activities({ translation }) {
})
.sort((a, b) => sortByDesc(a, b, 'date'));

const calculateCategoryTotal = (category) => {
return (
activitiesRefined &&
activitiesRefined.filter((item) => item.category.label === category).length
);
};

const total = activitiesRefined && activitiesRefined.length;
const [selectedCategory, setSelectedCategory] = useState('');

const handleCategoryClick = (category) => {
setSelectedCategory(category);
};

const filteredEvents = selectedCategory
? activitiesRefined.filter((event) => event.category.label === selectedCategory)
: activitiesRefined;

return (
<PageLayout
customBanner={<ActivitiesFeaturesBanner t={translation} />}
title={translation('ActivitiesPage-PageName')}
descriptionParagraphs={[translation('ActivitiesPage-Description')]}
breadcrumbsData={breadcrumbs}>
<Container fluid="md" className="">
<button
onClick={() => handleCategoryClick('')}
className={`${selectedCategory === '' ? 'activeTab' : 'inactiveTab'} rounded-pill`}>
Todos <span>{total}</span>
</button>
{Object.values(Constants.Categories).map((category, index) => {
const label = category.label;
return (
<button
key={`categories-${index}`}
onClick={() => handleCategoryClick(label)}
className={`${
selectedCategory === label ? 'activeTab' : 'inactiveTab'
} rounded-pill`}>
{capitalize(label)} <span>{calculateCategoryTotal(label)}</span>
</button>
);
})}
<Row className={'mt-4 mb-5'} xs={1} lg={4}>
{activitiesRefined.map((item, key) => (
{filteredEvents.map((item, key) => (
<Col key={key} className={'mt-4'}>
<span className={'event-card-wrapper'}>
<EventCard item={item} key={item.id} />
Expand Down
4 changes: 4 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ export function importAll(r) {
});
return images;
}

export function capitalize(word) {
return word.charAt(0).toUpperCase() + word.slice(1);
}

0 comments on commit b0dfe05

Please sign in to comment.