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

filters page Atividades #210 #216

Closed
Show file tree
Hide file tree
Changes from all 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
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;
}
33 changes: 30 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,42 @@ function Activities({ translation }) {
})
.sort((a, b) => sortByDesc(a, b, 'date'));

const categories = Array.from(new Set(activities.map(item => item.category.label)));

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>
{categories.map((category, index) => (
<button
key={index}
onClick={() => handleCategoryClick(category)}
className={`${selectedCategory === category ? 'activeTab' : 'inactiveTab'} rounded-pill`}
>
{capitalize(category)} <span>{calculateCategoryTotal(category)}</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);
}
Loading