Skip to content

Commit 4e46d8c

Browse files
committed
feat: implement answers list
1 parent 443a84e commit 4e46d8c

3 files changed

Lines changed: 73 additions & 57 deletions

File tree

package/src/components/Poll/components/PollAnswersList.tsx

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback, useMemo, useState } from 'react';
2-
import { FlatList, type FlatListProps, Pressable, StyleSheet, Text, View } from 'react-native';
2+
import { FlatList, type FlatListProps, StyleSheet, Text, View } from 'react-native';
33

44
import { PollAnswer, VotingVisibility } from 'stream-chat';
55

@@ -13,7 +13,9 @@ import {
1313
useTheme,
1414
useTranslationContext,
1515
} from '../../../contexts';
16+
import { primitives } from '../../../theme';
1617
import { getDateString } from '../../../utils/i18n/getDateString';
18+
import { Button } from '../../ui';
1719
import { UserAvatar } from '../../ui/Avatar/UserAvatar';
1820
import { usePollAnswersPagination } from '../hooks/usePollAnswersPagination';
1921
import { usePollState } from '../hooks/usePollState';
@@ -34,31 +36,15 @@ export const AnswerListAddCommentButton = (props: PollButtonProps) => {
3436
setShowAddCommentDialog(true);
3537
}, [message, onPress, poll]);
3638

37-
const {
38-
theme: {
39-
colors: { accent_dark_blue, bg_user },
40-
poll: {
41-
answersList: { buttonContainer },
42-
button: { text },
43-
},
44-
},
45-
} = useTheme();
46-
4739
return (
4840
<>
49-
<Pressable
41+
<Button
42+
variant={'secondary'}
43+
type={'outline'}
44+
size={'lg'}
45+
label={ownAnswer ? t('Update your comment') : t('Add a comment')}
5046
onPress={onPressHandler}
51-
style={({ pressed }) => [
52-
{ opacity: pressed ? 0.5 : 1 },
53-
styles.addCommentButtonContainer,
54-
{ backgroundColor: bg_user },
55-
buttonContainer,
56-
]}
57-
>
58-
<Text style={[styles.addCommentButtonText, { color: accent_dark_blue }, text]}>
59-
{ownAnswer ? t('Update your comment') : t('Add a comment')}
60-
</Text>
61-
</Pressable>
47+
/>
6248
{showAddCommentDialog ? (
6349
<PollInputDialog
6450
closeDialog={() => setShowAddCommentDialog(false)}
@@ -83,12 +69,12 @@ export const PollAnswerListItem = ({ answer }: { answer: PollAnswer }) => {
8369

8470
const {
8571
theme: {
86-
colors: { bg_user, black },
8772
poll: {
8873
answersList: { item: itemStyle },
8974
},
9075
},
9176
} = useTheme();
77+
const styles = useStyles();
9278

9379
const dateString = useMemo(
9480
() =>
@@ -107,20 +93,18 @@ export const PollAnswerListItem = ({ answer }: { answer: PollAnswer }) => {
10793
);
10894

10995
return (
110-
<View style={[styles.listItemContainer, { backgroundColor: bg_user }, itemStyle.container]}>
111-
<Text style={[styles.listItemAnswerText, { color: black }, itemStyle.answerText]}>
112-
{answer.answer_text}
113-
</Text>
96+
<View style={[styles.listItemContainer, itemStyle.container]}>
97+
<Text style={[styles.listItemAnswerText, itemStyle.answerText]}>{answer.answer_text}</Text>
11498
<View style={[styles.listItemInfoContainer, itemStyle.infoContainer]}>
11599
<View style={[styles.listItemUserInfoContainer, itemStyle.userInfoContainer]}>
116100
{!isAnonymous && answer.user?.image ? (
117-
<UserAvatar user={answer.user} size='xs' showBorder />
101+
<UserAvatar user={answer.user} size='md' showBorder />
118102
) : null}
119-
<Text style={{ color: black, fontSize: 14, marginLeft: 2 }}>
103+
<Text style={styles.listItemInfoUserName}>
120104
{isAnonymous ? t('Anonymous') : answer.user?.name}
121105
</Text>
122106
</View>
123-
<Text style={{ color: black }}>{dateString}</Text>
107+
<Text style={styles.listItemInfoDate}>{dateString}</Text>
124108
</View>
125109
</View>
126110
);
@@ -136,18 +120,19 @@ export const PollAnswersListContent = ({
136120
const { hasNextPage, loadMore, pollAnswers } = usePollAnswersPagination();
137121
const {
138122
theme: {
139-
colors: { white },
140123
poll: {
141-
answersList: { container },
124+
answersList: { container, contentContainer },
142125
},
143126
},
144127
} = useTheme();
128+
const styles = useStyles();
145129

146130
return (
147-
<View style={[styles.container, { backgroundColor: white }, container]}>
131+
<View style={[styles.container, container]}>
148132
<FlatList
149133
data={pollAnswers}
150134
keyExtractor={(item) => `poll_answer_${item.id}`}
135+
contentContainerStyle={[styles.contentContainer, contentContainer]}
151136
onEndReached={() => hasNextPage && loadMore()}
152137
renderItem={renderPollAnswerListItem}
153138
{...additionalFlatListProps}
@@ -172,23 +157,54 @@ export const PollAnswersList = ({
172157
</PollContextProvider>
173158
);
174159

175-
const styles = StyleSheet.create({
176-
addCommentButtonContainer: {
177-
alignItems: 'center',
178-
borderRadius: 12,
179-
paddingHorizontal: 16,
180-
paddingVertical: 18,
181-
},
182-
addCommentButtonText: { fontSize: 16 },
183-
container: { flex: 1, margin: 16 },
184-
listItemAnswerText: { fontSize: 16, fontWeight: '500' },
185-
listItemContainer: {
186-
borderRadius: 12,
187-
marginBottom: 8,
188-
paddingBottom: 20,
189-
paddingHorizontal: 16,
190-
paddingTop: 12,
191-
},
192-
listItemInfoContainer: { flexDirection: 'row', justifyContent: 'space-between', marginTop: 24 },
193-
listItemUserInfoContainer: { alignItems: 'center', flexDirection: 'row' },
194-
});
160+
const useStyles = () => {
161+
const {
162+
theme: { semantics },
163+
} = useTheme();
164+
return useMemo(
165+
() =>
166+
StyleSheet.create({
167+
addCommentButtonContainer: {
168+
alignItems: 'center',
169+
borderRadius: 12,
170+
paddingHorizontal: 16,
171+
paddingVertical: 18,
172+
},
173+
contentContainer: { gap: primitives.spacingMd },
174+
addCommentButtonText: { fontSize: 16 },
175+
container: {
176+
flex: 1,
177+
padding: primitives.spacingMd,
178+
backgroundColor: semantics.backgroundElevationElevation1,
179+
},
180+
listItemAnswerText: {
181+
fontSize: primitives.typographyFontSizeMd,
182+
lineHeight: primitives.typographyLineHeightRelaxed,
183+
fontWeight: primitives.typographyFontWeightSemiBold,
184+
color: semantics.textPrimary,
185+
},
186+
listItemContainer: {
187+
borderRadius: primitives.radiusLg,
188+
padding: primitives.spacingMd,
189+
backgroundColor: semantics.backgroundCoreSurfaceCard,
190+
},
191+
listItemInfoContainer: {
192+
flexDirection: 'row',
193+
justifyContent: 'space-between',
194+
alignItems: 'center',
195+
marginTop: 24,
196+
},
197+
listItemInfoUserName: {
198+
color: semantics.textPrimary,
199+
fontSize: primitives.typographyFontSizeSm,
200+
marginLeft: primitives.spacingXxs,
201+
},
202+
listItemInfoDate: {
203+
fontSize: primitives.typographyFontSizeSm,
204+
color: semantics.textTertiary,
205+
},
206+
listItemUserInfoContainer: { alignItems: 'center', flexDirection: 'row' },
207+
}),
208+
[semantics],
209+
);
210+
};

package/src/components/Poll/components/PollModalHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const useStyles = () => {
6161
},
6262
centerContainer: {
6363
alignItems: 'center',
64-
flex: 1,
64+
flex: 2,
6565
justifyContent: 'center',
6666
},
6767
sideContainer: {

package/src/contexts/themeContext/utils/theme.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,8 @@ export type Theme = {
762762
wrapper: ViewStyle;
763763
};
764764
answersList: {
765-
buttonContainer: ViewStyle;
766765
container: ViewStyle;
766+
contentContainer: ViewStyle;
767767
item: {
768768
answerText: TextStyle;
769769
container: ViewStyle;
@@ -1601,8 +1601,8 @@ export const defaultTheme: Theme = {
16011601
wrapper: {},
16021602
},
16031603
answersList: {
1604-
buttonContainer: {},
16051604
container: {},
1605+
contentContainer: {},
16061606
item: {
16071607
answerText: {},
16081608
container: {},

0 commit comments

Comments
 (0)