Skip to content

Commit 8ce5de0

Browse files
authored
Merge pull request #5780 from HSLdevcom/AB#465
Ab#465 - feedback component
2 parents d312eb8 + 2abefe9 commit 8ce5de0

25 files changed

Lines changed: 579 additions & 448 deletions

app/component/Geolocator.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const GeolocatorWithPosition = connectToStores(
1313
(context, props) => {
1414
const locationState = context.getStore('PositionStore').getLocationState();
1515
const { createReturnPath, path } = props;
16-
const { from, to, hash } = props.match.params;
16+
const { from, to, hash, secondHash } = props.match.params;
1717

1818
const redirect = () => {
1919
const locationForUrl = locationToUri(locationState);
@@ -36,7 +36,13 @@ const GeolocatorWithPosition = connectToStores(
3636
save = '3'; // save destination only
3737
}
3838
}
39-
const returnPath = createReturnPath(path, newFrom, newTo, hash);
39+
const returnPath = createReturnPath(
40+
path,
41+
newFrom,
42+
newTo,
43+
hash,
44+
secondHash,
45+
);
4046

4147
const newLocation = {
4248
...props.match.location,

app/component/Icon.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import cx from 'classnames';
55
const Icon = ({
66
className,
77
color,
8+
fill,
89
height,
910
id,
1011
img,
@@ -22,7 +23,7 @@ const Icon = ({
2223
id={id}
2324
style={{
2425
color: color || null,
25-
fill: color || null,
26+
fill: fill || color || null,
2627
height: height ? `${height}em` : null,
2728
width: width ? `${width}em` : null,
2829
outline: 0,
@@ -34,7 +35,7 @@ const Icon = ({
3435
{background}
3536
<g
3637
style={{
37-
fill: color || null,
38+
fill: fill || color || null,
3839
height: height ? `${height}em` : null,
3940
width: width ? `${width}em` : null,
4041
outline: 0,
@@ -56,6 +57,7 @@ const Icon = ({
5657
Icon.propTypes = {
5758
className: PropTypes.string,
5859
color: PropTypes.string,
60+
fill: PropTypes.string,
5961
height: PropTypes.number,
6062
id: PropTypes.string,
6163
img: PropTypes.string.isRequired,

app/component/Popover.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ export default function Popover({ onClose, message, buttonText }) {
6767
})}
6868
>
6969
{buttonText || (
70-
<FormattedMessage
71-
id="popover-button-got-it"
72-
defaultMessage="Got it!"
73-
/>
70+
<FormattedMessage id="acknowledged" defaultMessage="Got it!" />
7471
)}
7572
</button>
7673
</div>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import PropTypes from 'prop-types';
2+
import cx from 'classnames';
3+
import React from 'react';
4+
import { FormattedMessage, useIntl } from 'react-intl';
5+
import Icon from '../Icon';
6+
import { useConfigContext } from '../../configurations/ConfigContext';
7+
8+
export default function Feedback({
9+
recommended, // true if ranked as best by personalisation algo
10+
feedback, // true=likes, false=dislikes, undefined=no feedback yet
11+
giveFeedback, // callback to submit user's feedback action
12+
}) {
13+
const intl = useIntl();
14+
const { colors } = useConfigContext();
15+
16+
let status;
17+
if (feedback === true) {
18+
status = 'personalisation-liked';
19+
} else if (feedback === false) {
20+
status = 'personalisation-disliked';
21+
} else {
22+
status = 'personalisation-ask';
23+
}
24+
25+
const favIcon = recommended
26+
? 'icon_star-with-circle'
27+
: 'icon_star-unselected';
28+
const iconMap = {
29+
'personalisation-ask': {
30+
img: favIcon,
31+
className: cx('favourite', { selected: recommended }),
32+
fill: recommended ? '#c53291' : '#FFF',
33+
},
34+
'personalisation-liked': { img: 'icon_thumb', color: colors.primary },
35+
'personalisation-disliked': {
36+
img: 'icon_thumb-down',
37+
color: colors.primary,
38+
},
39+
};
40+
const iconProps = iconMap[status];
41+
42+
return (
43+
<div className="feedback-container">
44+
<div
45+
className={cx('feedback-section', {
46+
'feedback-text-posted': status !== 'personalisation-ask',
47+
})}
48+
>
49+
<Icon {...iconProps} height={1.4} width={1.4} />
50+
<span>&nbsp;&nbsp;&nbsp;</span>
51+
<FormattedMessage id={status} />
52+
</div>
53+
{status === 'personalisation-ask' && (
54+
<div className="feedback-section">
55+
<button
56+
type="button"
57+
className="thumb-button"
58+
onClick={() => giveFeedback(true)}
59+
aria-label={intl.formatMessage({ id: 'personalisation-aria-like' })}
60+
>
61+
<Icon
62+
img="icon_thumb"
63+
color={colors.primary}
64+
height={1}
65+
width={1}
66+
/>
67+
</button>
68+
<button
69+
type="button"
70+
className="thumb-button"
71+
onClick={() => giveFeedback(false)}
72+
aria-label={intl.formatMessage({
73+
id: 'personalisation-aria-dislike',
74+
})}
75+
>
76+
<Icon
77+
img="icon_thumb-down"
78+
color={colors.primary}
79+
height={1}
80+
width={1}
81+
/>
82+
</button>
83+
</div>
84+
)}
85+
</div>
86+
);
87+
}
88+
89+
Feedback.propTypes = {
90+
recommended: PropTypes.bool,
91+
feedback: PropTypes.bool,
92+
giveFeedback: PropTypes.func.isRequired,
93+
};

0 commit comments

Comments
 (0)