Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit a66edc9

Browse files
add badges
1 parent 910927b commit a66edc9

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

src/containers/MyGigsFilter/GigsFilter/index.jsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
1-
import React from "react";
1+
import React, { useEffect, useRef } from "react";
22
import PT from "prop-types";
33
import _ from "lodash";
44
import RadioButton from "../../../components/RadioButton";
55
import * as utils from "../../../utils";
66

77
import "./styles.scss";
88

9-
const GigsFilter = ({ gigStatus, gigsStatuses, updateGigFilter }) => {
9+
const GigsFilter = ({
10+
gigStatus,
11+
gigsStatuses,
12+
updateGigFilter,
13+
openJobsCount,
14+
}) => {
1015
const bucketOptions = utils.createRadioOptions(gigsStatuses, gigStatus);
1116

17+
const ref = useRef(null);
18+
19+
useEffect(() => {
20+
if (!ref.current) {
21+
return;
22+
}
23+
24+
const openJobsElement = ref.current.children[0].children[1];
25+
const badgeElement = utils.icon.createBadgeElement(
26+
openJobsElement,
27+
`${openJobsCount}`
28+
);
29+
30+
return () => {
31+
badgeElement.parentElement.removeChild(badgeElement);
32+
};
33+
}, [openJobsCount]);
34+
1235
return (
1336
<div styleName="filter">
14-
<div styleName="buckets vertical-list">
37+
<div styleName="buckets vertical-list" ref={ref}>
1538
<RadioButton
1639
options={bucketOptions}
1740
onChange={(newBucketOptions) => {
@@ -31,6 +54,7 @@ GigsFilter.propTypes = {
3154
gigStatus: PT.string,
3255
gigsStatuses: PT.arrayOf(PT.string),
3356
updateGigFilter: PT.func,
57+
openJobsCount: PT.number,
3458
};
3559

3660
export default GigsFilter;

src/containers/MyGigsFilter/GigsFilter/styles.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,19 @@ $filter-padding-y: 3 * $base-unit;
2525
margin: $base-unit 0;
2626
}
2727
}
28+
:global {
29+
.count-badge {
30+
display: inline-block;
31+
margin: -2px 0 0 $base-unit;
32+
padding: 2px 5px 0;
33+
font-weight: bold;
34+
font-size: 11px;
35+
line-height: 14px;
36+
text-align: center;
37+
color: white;
38+
vertical-align: middle;
39+
background: #EF476F;
40+
border-radius: 13px;
41+
}
42+
}
2843
}

src/containers/MyGigsFilter/index.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ import { connect } from "react-redux";
55
import GigsFilter from "./GigsFilter";
66
import actions from "../../actions";
77
import { updateQuery } from "../../utils/url";
8+
import * as constants from "../../constants";
89

9-
const MyGigsFilter = ({ gigStatus, gigsStatuses, updateGigFilter }) => {
10+
const MyGigsFilter = ({
11+
gigStatus,
12+
gigsStatuses,
13+
updateGigFilter,
14+
openJobsCount,
15+
}) => {
1016
const location = useLocation();
1117
const propsRef = useRef(null);
1218
propsRef.current = { location };
@@ -16,6 +22,7 @@ const MyGigsFilter = ({ gigStatus, gigsStatuses, updateGigFilter }) => {
1622
<GigsFilter
1723
gigStatus={gigStatus}
1824
gigsStatuses={gigsStatuses}
25+
openJobsCount={openJobsCount}
1926
updateGigFilter={(gigFilterChanged) => {
2027
updateGigFilter(gigFilterChanged);
2128
updateQuery(gigFilterChanged);
@@ -31,11 +38,13 @@ MyGigsFilter.propTypes = {
3138
gigStatus: PT.string,
3239
gigsStatuses: PT.arrayOf(PT.string),
3340
updateGigFilter: PT.func,
41+
openJobsCount: PT.number,
3442
};
3543

3644
const mapStateToProps = (state) => ({
3745
state: state,
3846
gigStatus: state.filter.gig.status,
47+
openJobsCount: state.myGigs[constants.GIGS_FILTER_STATUSES.OPEN_JOBS].total,
3948
gigsStatuses: state.lookup.gigsStatuses,
4049
});
4150

0 commit comments

Comments
 (0)