PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
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 0.5.0 0.6.0 All 127 releases
extendify / src / HelpCenter / components / ai-chat / Rating.jsx

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

63 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { thumbDown, thumbUp } from '@help-center/components/ai-chat/icons';
2 import { rateAnswer } from '@help-center/lib/api';
3 import { useEffect, useState } from '@wordpress/element';
4 import { __ } from '@wordpress/i18n';
5 import { Icon } from '@wordpress/icons';
6 import classnames from 'classnames';
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 >
37 <Icon className="fill-current" icon={thumbUp} />
38 </button>
39
40 <button
41 type="button"
42 aria-pressed={rating === -1}
43 aria-live="polite"
44 onClick={() => setRating((current) => (current === -1 ? 0 : -1))}
45 aria-label={
46 rating === -1
47 ? __('Remove rating', 'extendify-local')
48 : __('Rate that this answer was not helpful', 'extendify-local')
49 }
50 className={classnames(
51 'm-0 h-5 w-5 border-0 bg-transparent p-0 hover:text-design-main',
52 {
53 'text-design-main': rating === -1,
54 'text-gray-500': rating !== -1,
55 },
56 )}
57 >
58 <Icon className="fill-current" icon={thumbDown} />
59 </button>
60 </div>
61 );
62 };
63