Skip to content

Commit ca873e5

Browse files
committed
chore: move add comment button to correct file
1 parent d3de92c commit ca873e5

File tree

2 files changed

+68
-66
lines changed

2 files changed

+68
-66
lines changed

package/src/components/Poll/components/Button.tsx

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import React, { useCallback, useState } from 'react';
1+
import React, { useCallback } from 'react';
22
import { Pressable, StyleSheet, Text } from 'react-native';
33

44
import { Poll, PollOption } from 'stream-chat';
55

6-
import { PollInputDialog } from './PollInputDialog';
7-
8-
import {
9-
useOwnCapabilitiesContext,
10-
usePollContext,
11-
useTheme,
12-
useTranslationContext,
13-
} from '../../../contexts';
6+
import { useOwnCapabilitiesContext, usePollContext, useTheme } from '../../../contexts';
147
import { Check } from '../../../icons';
158
import type { DefaultStreamChatGenerics } from '../../../types/types';
169
import { MessageType } from '../../MessageList/hooks/useMessageList';
@@ -52,60 +45,6 @@ export const GenericPollButton = ({ onPress, title }: { onPress?: () => void; ti
5245
);
5346
};
5447

55-
export const AnswerListAddCommentButton = (props: PollButtonProps) => {
56-
const { t } = useTranslationContext();
57-
const { message, poll } = usePollContext();
58-
const { addComment, ownAnswer } = usePollState();
59-
const [showAddCommentDialog, setShowAddCommentDialog] = useState(false);
60-
const { onPress } = props;
61-
62-
const onPressHandler = useCallback(() => {
63-
if (onPress) {
64-
onPress({ message, poll });
65-
return;
66-
}
67-
68-
setShowAddCommentDialog(true);
69-
}, [message, onPress, poll]);
70-
71-
const {
72-
theme: {
73-
colors: { accent_dark_blue, bg_user },
74-
poll: {
75-
answersList: { buttonContainer },
76-
button: { text },
77-
},
78-
},
79-
} = useTheme();
80-
81-
return (
82-
<>
83-
<Pressable
84-
onPress={onPressHandler}
85-
style={({ pressed }) => [
86-
{ opacity: pressed ? 0.5 : 1 },
87-
styles.answerListAddCommentContainer,
88-
{ backgroundColor: bg_user },
89-
buttonContainer,
90-
]}
91-
>
92-
<Text style={[styles.text, { color: accent_dark_blue }, text]}>
93-
{ownAnswer ? t<string>('Update your comment') : t<string>('Add a comment')}
94-
</Text>
95-
</Pressable>
96-
{showAddCommentDialog ? (
97-
<PollInputDialog
98-
closeDialog={() => setShowAddCommentDialog(false)}
99-
initialValue={ownAnswer?.answer_text ?? ''}
100-
onSubmit={addComment}
101-
title={t<string>('Add a comment')}
102-
visible={showAddCommentDialog}
103-
/>
104-
) : null}
105-
</>
106-
);
107-
};
108-
10948
export const VoteButton = ({ onPress, option }: PollVoteButtonProps) => {
11049
const { message, poll } = usePollContext();
11150
const { isClosed, ownVotesByOptionId } = usePollState();

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

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

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

6-
import { AnswerListAddCommentButton } from './Button';
6+
import { PollButtonProps } from './Button';
7+
import { PollInputDialog } from './PollInputDialog';
78

89
import {
910
PollContextProvider,
1011
PollContextValue,
12+
usePollContext,
1113
useTheme,
1214
useTranslationContext,
1315
} from '../../../contexts';
@@ -17,6 +19,60 @@ import { Avatar } from '../../Avatar/Avatar';
1719
import { usePollAnswersPagination } from '../hooks/usePollAnswersPagination';
1820
import { usePollState } from '../hooks/usePollState';
1921

22+
export const AnswerListAddCommentButton = (props: PollButtonProps) => {
23+
const { t } = useTranslationContext();
24+
const { message, poll } = usePollContext();
25+
const { addComment, ownAnswer } = usePollState();
26+
const [showAddCommentDialog, setShowAddCommentDialog] = useState(false);
27+
const { onPress } = props;
28+
29+
const onPressHandler = useCallback(() => {
30+
if (onPress) {
31+
onPress({ message, poll });
32+
return;
33+
}
34+
35+
setShowAddCommentDialog(true);
36+
}, [message, onPress, poll]);
37+
38+
const {
39+
theme: {
40+
colors: { accent_dark_blue, bg_user },
41+
poll: {
42+
answersList: { buttonContainer },
43+
button: { text },
44+
},
45+
},
46+
} = useTheme();
47+
48+
return (
49+
<>
50+
<Pressable
51+
onPress={onPressHandler}
52+
style={({ pressed }) => [
53+
{ opacity: pressed ? 0.5 : 1 },
54+
styles.addCommentButtonContainer,
55+
{ backgroundColor: bg_user },
56+
buttonContainer,
57+
]}
58+
>
59+
<Text style={[styles.addCommentButtonText, { color: accent_dark_blue }, text]}>
60+
{ownAnswer ? t<string>('Update your comment') : t<string>('Add a comment')}
61+
</Text>
62+
</Pressable>
63+
{showAddCommentDialog ? (
64+
<PollInputDialog
65+
closeDialog={() => setShowAddCommentDialog(false)}
66+
initialValue={ownAnswer?.answer_text ?? ''}
67+
onSubmit={addComment}
68+
title={t<string>('Add a comment')}
69+
visible={showAddCommentDialog}
70+
/>
71+
) : null}
72+
</>
73+
);
74+
};
75+
2076
export type PollAnswersListProps<
2177
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
2278
> = PollContextValue & {
@@ -120,6 +176,13 @@ export const PollAnswersList = ({
120176
);
121177

122178
const styles = StyleSheet.create({
179+
addCommentButtonContainer: {
180+
alignItems: 'center',
181+
borderRadius: 12,
182+
paddingHorizontal: 16,
183+
paddingVertical: 18,
184+
},
185+
addCommentButtonText: { fontSize: 16 },
123186
container: { flex: 1, margin: 16 },
124187
listItemAnswerText: { fontSize: 16, fontWeight: '500' },
125188
listItemContainer: {

0 commit comments

Comments
 (0)