PluginProbe
Extendify / 2.2.0
Extendify v2.2.0
3.2.3 3.2.2 3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 All 129 releases
extendify / src / HelpCenter / components / ai-chat / Rating.jsx

Rating.jsx in Extendify 2.2.0, at src/HelpCenter/components/ai-chat/Rating.jsx

61 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useState, useEffect } from '@wordpress/element';
2 import { __ } from '@wordpress/i18n';
3 import { Icon } from '@wordpress/icons';
4 import classnames from 'classnames';
5 import { thumbUp, thumbDown } from '@help-center/components/ai-chat/icons';
6 import { rateAnswer } from '@help-center/lib/api';
7
8 export const Rating = ({ answerId }) => {
9 const [rating, setRating] = useState(undefined);
10
11 useEffect(() => {
12 if (!answerId) return;
13 if (rating === undefined) return;
14 rateAnswer({ answerId, rating });
15 }, [rating, answerId]);
16
17 return (
18 <div className="mt-1 flex items-center justify-end gap-0.5 text-right">
19 <button
20 type="button"
21 aria-pressed={rating === 1}
22 aria-live="polite"
23 onClick={() => setRating((current) => (current === 1 ? 0 : 1))}
24 aria-label={
25 rating === 1
26 ? __('Remove rating', 'extendify-local')
27 : __('Rate that this answer was helpful', 'extendify-local')
28 }
29 className={classnames(
30 'm-0 h-5 w-5 border-0 bg-transparent p-0 hover:text-design-main',
31 {
32 'text-design-main': rating === 1,
33 'text-gray-500': rating !== 1,
34 },
35 )}>
36 <Icon className="fill-current" icon={thumbUp} />
37 </button>
38
39 <button
40 type="button"
41 aria-pressed={rating === -1}
42 aria-live="polite"
43 onClick={() => setRating((current) => (current === -1 ? 0 : -1))}
44 aria-label={
45 rating === -1
46 ? __('Remove rating', 'extendify-local')
47 : __('Rate that this answer was not helpful', 'extendify-local')
48 }
49 className={classnames(
50 'm-0 h-5 w-5 border-0 bg-transparent p-0 hover:text-design-main',
51 {
52 'text-design-main': rating === -1,
53 'text-gray-500': rating !== -1,
54 },
55 )}>
56 <Icon className="fill-current" icon={thumbDown} />
57 </button>
58 </div>
59 );
60 };
61