Skip to content

Commit 594616e

Browse files
committed
chore: all votes screen
1 parent 193b99c commit 594616e

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

package/src/components/Poll/components/PollOption.tsx

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
useOwnCapabilitiesContext,
1515
usePollContext,
1616
useTheme,
17+
useTranslationContext,
1718
} from '../../../contexts';
1819

1920
import { Check } from '../../../icons';
@@ -26,6 +27,7 @@ import { usePollState } from '../hooks/usePollState';
2627
export type PollOptionProps = {
2728
option: PollOptionClass;
2829
showProgressBar?: boolean;
30+
forceIncoming?: boolean;
2931
};
3032

3133
export type PollAllOptionsContentProps = PollContextValue & {
@@ -36,6 +38,7 @@ export type PollAllOptionsContentProps = PollContextValue & {
3638
export const PollAllOptionsContent = ({
3739
additionalScrollViewProps,
3840
}: Pick<PollAllOptionsContentProps, 'additionalScrollViewProps'>) => {
41+
const { t } = useTranslationContext();
3942
const { name, options } = usePollState();
4043

4144
const {
@@ -50,12 +53,13 @@ export const PollAllOptionsContent = ({
5053
return (
5154
<ScrollView style={[styles.allOptionsWrapper, wrapper]} {...additionalScrollViewProps}>
5255
<View style={[styles.allOptionsTitleContainer, titleContainer]}>
56+
<Text style={styles.allOptionsTitleMeta}>{t('Question')}</Text>
5357
<Text style={[styles.allOptionsTitleText, titleText]}>{name}</Text>
5458
</View>
5559
<View style={[styles.allOptionsListContainer, listContainer]}>
5660
{options?.map((option: PollOptionClass) => (
5761
<View key={`full_poll_options_${option.id}`} style={styles.optionWrapper}>
58-
<PollOption key={option.id} option={option} showProgressBar={false} />
62+
<PollOption key={option.id} option={option} forceIncoming />
5963
</View>
6064
))}
6165
</View>
@@ -78,19 +82,15 @@ export const PollAllOptions = ({
7882
</PollContextProvider>
7983
);
8084

81-
export const PollOption = ({ option, showProgressBar = true }: PollOptionProps) => {
82-
const { latestVotesByOption, maxVotedOptionIds, voteCountsByOption } = usePollState();
85+
export const PollOption = ({ option, showProgressBar = true, forceIncoming }: PollOptionProps) => {
86+
const { latestVotesByOption, voteCountsByOption, voteCount } = usePollState();
8387
const styles = useStyles();
8488

8589
const relevantVotes = useMemo(
8690
() => latestVotesByOption?.[option.id] || [],
8791
[latestVotesByOption, option.id],
8892
);
89-
const maxVotes = useMemo(
90-
() =>
91-
maxVotedOptionIds?.[0] && voteCountsByOption ? voteCountsByOption[maxVotedOptionIds[0]] : 0,
92-
[maxVotedOptionIds, voteCountsByOption],
93-
);
93+
9494
const votes = voteCountsByOption[option.id] || 0;
9595

9696
const {
@@ -105,13 +105,15 @@ export const PollOption = ({ option, showProgressBar = true }: PollOptionProps)
105105
} = useTheme();
106106
const isPollCreatedByClient = useIsPollCreatedByCurrentUser();
107107

108-
const unFilledColor = isPollCreatedByClient
109-
? semantics.chatPollProgressTrackOutgoing
110-
: semantics.chatPollProgressTrackIncoming;
108+
const unFilledColor =
109+
isPollCreatedByClient && !forceIncoming
110+
? semantics.chatPollProgressTrackOutgoing
111+
: semantics.chatPollProgressTrackIncoming;
111112

112-
const filledColor = isPollCreatedByClient
113-
? semantics.chatPollProgressFillOutgoing
114-
: semantics.chatPollProgressFillIncoming;
113+
const filledColor =
114+
isPollCreatedByClient && !forceIncoming
115+
? semantics.chatPollProgressFillOutgoing
116+
: semantics.chatPollProgressFillIncoming;
115117

116118
return (
117119
<View style={[styles.container, container]}>
@@ -133,7 +135,7 @@ export const PollOption = ({ option, showProgressBar = true }: PollOptionProps)
133135
{showProgressBar ? (
134136
<View style={styles.progressBarContainer}>
135137
<ProgressBar
136-
progress={votes / maxVotes}
138+
progress={votes / voteCount}
137139
filledColor={filledColor}
138140
emptyColor={unFilledColor}
139141
/>
@@ -273,6 +275,13 @@ const useAllOptionStyles = () => {
273275
lineHeight: primitives.typographyLineHeightRelaxed,
274276
fontWeight: primitives.typographyFontWeightSemiBold,
275277
color: semantics.textPrimary,
278+
paddingTop: primitives.spacingXs,
279+
},
280+
allOptionsTitleMeta: {
281+
fontSize: primitives.typographyFontSizeSm,
282+
color: semantics.textTertiary,
283+
lineHeight: primitives.typographyLineHeightNormal,
284+
fontWeight: primitives.typographyFontWeightMedium,
276285
},
277286
allOptionsWrapper: {
278287
flex: 1,

package/src/components/Poll/hooks/usePollState.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export type UsePollStateSelectorReturnType = {
3232
ownVotesByOptionId: Record<string, PollVote>;
3333
voteCountsByOption: Record<string, number>;
3434
votingVisibility: VotingVisibility | undefined;
35+
voteCount: number;
3536
};
3637

3738
export type UsePollStateReturnType = UsePollStateSelectorReturnType & {
@@ -56,6 +57,7 @@ const selector = (nextValue: PollState): UsePollStateSelectorReturnType => ({
5657
ownVotesByOptionId: nextValue.ownVotesByOptionId,
5758
voteCountsByOption: nextValue.vote_counts_by_option,
5859
votingVisibility: nextValue.voting_visibility,
60+
voteCount: nextValue.vote_count,
5961
});
6062

6163
export const usePollState = (): UsePollStateReturnType => {
@@ -76,6 +78,7 @@ export const usePollState = (): UsePollStateReturnType => {
7678
ownVotesByOptionId,
7779
voteCountsByOption,
7880
votingVisibility,
81+
voteCount,
7982
} = usePollStateStore(selector);
8083

8184
const addOption = useCallback(
@@ -109,5 +112,6 @@ export const usePollState = (): UsePollStateReturnType => {
109112
ownVotesByOptionId,
110113
voteCountsByOption,
111114
votingVisibility,
115+
voteCount,
112116
};
113117
};

0 commit comments

Comments
 (0)