瀏覽代碼

feat(Polls): Display creator name for polls

master
Vlad Piersec 3 年之前
父節點
當前提交
e51655a93a

+ 7
- 1
css/_polls.scss 查看文件

@@ -21,6 +21,12 @@
21 21
     margin-bottom: 8px;
22 22
 }
23 23
 
24
+.poll-creator {
25
+    color: #C2C2C2;
26
+    font-weight: 600;
27
+    margin: 4px 0 16px 0;
28
+}
29
+
24 30
 .poll-answer-container {
25 31
     background: #3D3D3D;
26 32
     border-radius: 3px;
@@ -134,7 +140,7 @@ ol.poll-result-list {
134 140
 .poll-question {
135 141
     font-size: 16px;
136 142
     font-weight: 600;
137
-    margin-bottom: 16px;
143
+    line-height: 26px;
138 144
 }
139 145
 
140 146
 .poll-answer-voters {

+ 1
- 0
lang/main.json 查看文件

@@ -634,6 +634,7 @@
634 634
     "passwordSetRemotely": "Set by another participant",
635 635
     "passwordDigitsOnly": "Up to {{number}} digits",
636 636
     "polls": {
637
+        "by": "By {{ name }}",
637 638
         "create": {
638 639
             "addOption": "Add option",
639 640
             "answerPlaceholder": "Option {{index}}",

+ 13
- 0
react/features/base/util/hooks.js 查看文件

@@ -0,0 +1,13 @@
1
+// @flow
2
+import { useSelector } from 'react-redux';
3
+
4
+/**
5
+ * Takes a redux selector and binds it to specific values.
6
+ *
7
+ * @param {Function} selector - The selector function.
8
+ * @param {...any} args - The values to bind to.
9
+ * @returns {any}
10
+ */
11
+export function useBoundSelector(selector: Function, ...args: any[]) {
12
+    return useSelector(state => selector(state, ...args));
13
+}

+ 5
- 1
react/features/polls/components/AbstractPollAnswer.js 查看文件

@@ -7,6 +7,7 @@ import { useDispatch, useSelector } from 'react-redux';
7 7
 
8 8
 import { sendAnalytics, createPollEvent } from '../../analytics';
9 9
 import { getLocalParticipant, getParticipantById } from '../../base/participants';
10
+import { useBoundSelector } from '../../base/util/hooks';
10 11
 import { registerVote, setVoteChanging } from '../actions';
11 12
 import { COMMAND_ANSWER_POLL } from '../constants';
12 13
 import type { Poll } from '../types';
@@ -24,6 +25,7 @@ type InputProps = {
24 25
  **/
25 26
 export type AbstractProps = {
26 27
     checkBoxStates: Function,
28
+    creatorName: string,
27 29
     poll: Poll,
28 30
     setCheckbox: Function,
29 31
     skipAnswer: Function,
@@ -56,6 +58,7 @@ const AbstractPollAnswer = (Component: AbstractComponent<AbstractProps>) => (pro
56 58
 
57 59
         return new Array(poll.answers.length).fill(false);
58 60
     });
61
+    const participant = useBoundSelector(getParticipantById, poll.senderId);
59 62
 
60 63
     const setCheckbox = useCallback((index, state) => {
61 64
         const newCheckBoxStates = [ ...checkBoxStates ];
@@ -67,7 +70,7 @@ const AbstractPollAnswer = (Component: AbstractComponent<AbstractProps>) => (pro
67 70
 
68 71
     const dispatch = useDispatch();
69 72
 
70
-    const localParticipant = useSelector(state => getParticipantById(state, localId));
73
+    const localParticipant = useBoundSelector(getParticipantById, localId);
71 74
     const localName: string = localParticipant.name ? localParticipant.name : 'Fellow Jitster';
72 75
 
73 76
     const submitAnswer = useCallback(() => {
@@ -99,6 +102,7 @@ const AbstractPollAnswer = (Component: AbstractComponent<AbstractProps>) => (pro
99 102
 
100 103
     return (<Component
101 104
         checkBoxStates = { checkBoxStates }
105
+        creatorName = { participant ? participant.name : '' }
102 106
         poll = { poll }
103 107
         setCheckbox = { setCheckbox }
104 108
         skipAnswer = { skipAnswer }

+ 5
- 0
react/features/polls/components/AbstractPollResults.js 查看文件

@@ -6,6 +6,8 @@ import { useTranslation } from 'react-i18next';
6 6
 import { useDispatch, useSelector } from 'react-redux';
7 7
 
8 8
 import { sendAnalytics, createPollEvent } from '../../analytics';
9
+import { getParticipantById } from '../../base/participants/functions';
10
+import { useBoundSelector } from '../../base/util/hooks';
9 11
 import { setVoteChanging } from '../actions';
10 12
 import { getPoll } from '../functions';
11 13
 
@@ -33,6 +35,7 @@ export type AnswerInfo = {
33 35
 export type AbstractProps = {
34 36
     answers: Array<AnswerInfo>,
35 37
     changeVote: Function,
38
+    creatorName: string,
36 39
     showDetails: boolean,
37 40
     question: string,
38 41
     t: Function,
@@ -51,6 +54,7 @@ const AbstractPollResults = (Component: AbstractComponent<AbstractProps>) => (pr
51 54
     const { pollId } = props;
52 55
 
53 56
     const pollDetails = useSelector(getPoll(pollId));
57
+    const participant = useBoundSelector(getParticipantById, pollDetails.senderId);
54 58
 
55 59
     const [ showDetails, setShowDetails ] = useState(false);
56 60
     const toggleIsDetailed = useCallback(() => {
@@ -105,6 +109,7 @@ const AbstractPollResults = (Component: AbstractComponent<AbstractProps>) => (pr
105 109
         <Component
106 110
             answers = { answers }
107 111
             changeVote = { changeVote }
112
+            creatorName = { participant ? participant.name : '' }
108 113
             haveVoted = { pollDetails.lastVote !== null }
109 114
             question = { pollDetails.question }
110 115
             showDetails = { showDetails }

+ 4
- 0
react/features/polls/components/web/PollAnswer.js 查看文件

@@ -9,6 +9,7 @@ import type { AbstractProps } from '../AbstractPollAnswer';
9 9
 
10 10
 const PollAnswer = (props: AbstractProps) => {
11 11
     const {
12
+        creatorName,
12 13
         checkBoxStates,
13 14
         poll,
14 15
         setCheckbox,
@@ -25,6 +26,9 @@ const PollAnswer = (props: AbstractProps) => {
25 26
                 <div className = 'poll-question'>
26 27
                     <span>{ poll.question }</span>
27 28
                 </div>
29
+                <div className = 'poll-creator'>
30
+                    { t('polls.by', { name: creatorName }) }
31
+                </div>
28 32
             </div>
29 33
             <ol className = 'poll-answer-list'>
30 34
                 {

+ 4
- 0
react/features/polls/components/web/PollResults.js 查看文件

@@ -16,6 +16,7 @@ const PollResults = (props: AbstractProps) => {
16 16
     const {
17 17
         answers,
18 18
         changeVote,
19
+        creatorName,
19 20
         haveVoted,
20 21
         showDetails,
21 22
         question,
@@ -29,6 +30,9 @@ const PollResults = (props: AbstractProps) => {
29 30
                 <div className = 'poll-question'>
30 31
                     <strong>{ question }</strong>
31 32
                 </div>
33
+                <div className = 'poll-creator'>
34
+                    { t('polls.by', { name: creatorName }) }
35
+                </div>
32 36
             </div>
33 37
             <ol className = 'poll-result-list'>
34 38
                 {answers.map(({ name, percentage, voters, voterCount }, index) =>

Loading…
取消
儲存