1- import React , { useCallback , useState } from 'react' ;
2- import { Modal } from 'react-native' ;
1+ import React , { useCallback , useMemo , useState } from 'react' ;
2+ import { Modal , StyleSheet , View } from 'react-native' ;
33
4- import { GenericPollButton , PollButtonProps } from './Button' ;
4+ import { PollButtonProps } from './Button' ;
55import { PollAnswersList } from './PollAnswersList' ;
66import { PollInputDialog } from './PollInputDialog' ;
77import { PollModalHeader } from './PollModalHeader' ;
88import { PollAllOptions } from './PollOption' ;
99import { PollResults } from './PollResults' ;
1010
1111import { useChatContext , usePollContext , useTheme , useTranslationContext } from '../../../contexts' ;
12+ import { primitives } from '../../../theme' ;
13+ import { Button } from '../../ui' ;
1214import { SafeAreaViewWrapper } from '../../UIComponents/SafeAreaViewWrapper' ;
15+ import { useIsPollCreatedByClient } from '../hook/useIsPollCreatedByClient' ;
1316import { usePollState } from '../hooks/usePollState' ;
1417
1518export const ViewResultsButton = ( props : PollButtonProps ) => {
@@ -32,14 +35,22 @@ export const ViewResultsButton = (props: PollButtonProps) => {
3235 colors : { white } ,
3336 } ,
3437 } = useTheme ( ) ;
38+ const styles = useStyles ( ) ;
3539
3640 const onRequestClose = useCallback ( ( ) => {
3741 setShowResults ( false ) ;
3842 } , [ ] ) ;
3943
4044 return (
4145 < >
42- < GenericPollButton onPress = { onPressHandler } title = { t ( 'View Results' ) } />
46+ < Button
47+ variant = 'secondary'
48+ type = 'outline'
49+ label = { t ( 'View Results' ) }
50+ onPress = { onPressHandler }
51+ size = 'sm'
52+ style = { styles . viewResultsButton }
53+ />
4354 { showResults ? (
4455 < Modal animationType = 'slide' onRequestClose = { onRequestClose } visible = { showResults } >
4556 < SafeAreaViewWrapper style = { { backgroundColor : white , flex : 1 } } >
@@ -81,9 +92,12 @@ export const ShowAllOptionsButton = (props: PollButtonProps) => {
8192 return (
8293 < >
8394 { options && options . length > 10 ? (
84- < GenericPollButton
95+ < Button
96+ variant = 'secondary'
97+ type = 'ghost'
8598 onPress = { onPressHandler }
86- title = { t ( 'See all {{count}} options' , { count : options . length } ) }
99+ label = { t ( 'See all {{count}} options' , { count : options . length } ) }
100+ size = 'sm'
87101 />
88102 ) : null }
89103 { showAllOptions ? (
@@ -127,9 +141,12 @@ export const ShowAllCommentsButton = (props: PollButtonProps) => {
127141 return (
128142 < >
129143 { answersCount && answersCount > 0 ? (
130- < GenericPollButton
144+ < Button
145+ variant = 'secondary'
146+ type = 'ghost'
131147 onPress = { onPressHandler }
132- title = { t ( 'View {{count}} comments' , { count : answersCount } ) }
148+ label = { t ( 'View {{count}} comments' , { count : answersCount } ) }
149+ size = 'sm'
133150 />
134151 ) : null }
135152 { showAnswers ? (
@@ -167,7 +184,13 @@ export const SuggestOptionButton = (props: PollButtonProps) => {
167184 return (
168185 < >
169186 { ! isClosed && allowUserSuggestedOptions ? (
170- < GenericPollButton onPress = { onPressHandler } title = { t ( 'Suggest an option' ) } />
187+ < Button
188+ variant = 'secondary'
189+ type = 'ghost'
190+ onPress = { onPressHandler }
191+ label = { t ( 'Suggest an option' ) }
192+ size = 'sm'
193+ />
171194 ) : null }
172195 { showAddOptionDialog ? (
173196 < PollInputDialog
@@ -204,7 +227,13 @@ export const AddCommentButton = (props: PollButtonProps) => {
204227 return (
205228 < >
206229 { ! isClosed && allowAnswers ? (
207- < GenericPollButton onPress = { onPressHandler } title = { t ( 'Add a comment' ) } />
230+ < Button
231+ variant = 'secondary'
232+ type = 'ghost'
233+ onPress = { onPressHandler }
234+ label = { t ( 'Add a comment' ) }
235+ size = 'sm'
236+ />
208237 ) : null }
209238 { showAddCommentDialog ? (
210239 < PollInputDialog
@@ -223,19 +252,52 @@ export const EndVoteButton = () => {
223252 const { t } = useTranslationContext ( ) ;
224253 const { createdBy, endVote, isClosed } = usePollState ( ) ;
225254 const { client } = useChatContext ( ) ;
255+ const styles = useStyles ( ) ;
226256
227257 return ! isClosed && createdBy ?. id === client . userID ? (
228- < GenericPollButton onPress = { endVote } title = { t ( 'End Vote' ) } />
258+ < Button
259+ variant = 'secondary'
260+ type = 'outline'
261+ label = { t ( 'End Vote' ) }
262+ onPress = { endVote }
263+ size = 'sm'
264+ style = { styles . endVoteButton }
265+ />
229266 ) : null ;
230267} ;
231268
232- export const PollButtons = ( ) => (
233- < >
234- < ShowAllOptionsButton />
235- < ShowAllCommentsButton />
236- < SuggestOptionButton />
237- < AddCommentButton />
238- < ViewResultsButton />
239- < EndVoteButton />
240- </ >
241- ) ;
269+ export const PollButtons = ( ) => {
270+ const styles = useStyles ( ) ;
271+ return (
272+ < View style = { styles . buttonsContainer } >
273+ < ViewResultsButton />
274+ < EndVoteButton />
275+ < ShowAllOptionsButton />
276+ < SuggestOptionButton />
277+ < AddCommentButton />
278+ < ShowAllCommentsButton />
279+ </ View >
280+ ) ;
281+ } ;
282+
283+ const useStyles = ( ) => {
284+ const {
285+ theme : { semantics } ,
286+ } = useTheme ( ) ;
287+ const isPollCreatedByClient = useIsPollCreatedByClient ( ) ;
288+ return useMemo ( ( ) => {
289+ return StyleSheet . create ( {
290+ buttonsContainer : { gap : primitives . spacingXs } ,
291+ endVoteButton : {
292+ borderColor : isPollCreatedByClient
293+ ? semantics . chatBorderOnChatOutgoing
294+ : semantics . chatBorderOnChatIncoming ,
295+ } ,
296+ viewResultsButton : {
297+ borderColor : isPollCreatedByClient
298+ ? semantics . chatBorderOnChatOutgoing
299+ : semantics . chatBorderOnChatIncoming ,
300+ } ,
301+ } ) ;
302+ } , [ semantics , isPollCreatedByClient ] ) ;
303+ } ;
0 commit comments