Skip to content

Commit 9a6f38f

Browse files
committed
fix: added option reordering fix
1 parent 1c45b51 commit 9a6f38f

File tree

3 files changed

+17
-39
lines changed

3 files changed

+17
-39
lines changed

package/src/components/Poll/CreatePollContent.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ export const CreatePollContent = () => {
7777

7878
useEffect(() => {
7979
if (!createPollOptionHeight) return;
80-
const newID = options.find((option) => option.text === '')?.id;
81-
const newIndex = options.findIndex((option) => option.id === newID);
80+
const newIndex = options.length;
8281
currentOptionPositions.value = {
8382
inverseIndexCache: {
8483
...currentOptionPositions.value.inverseIndexCache,
@@ -93,7 +92,7 @@ export const CreatePollContent = () => {
9392
},
9493
};
9594
// eslint-disable-next-line react-hooks/exhaustive-deps
96-
}, [createPollOptionHeight, options]);
95+
}, [createPollOptionHeight, options.length]);
9796

9897
useEffect(() => {
9998
const seenTexts = new Set<string>();
@@ -134,7 +133,7 @@ export const CreatePollContent = () => {
134133
reorderedPollOptions.push(currentOption);
135134
}
136135
}
137-
pollComposer.updateFields({
136+
await pollComposer.updateFields({
138137
options: reorderedPollOptions,
139138
});
140139
await createAndSendPoll();

package/src/components/Poll/components/CreatePollOptions.tsx

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback, useMemo } from 'react';
2-
import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native';
2+
import { StyleSheet, Text, TextInput, View } from 'react-native';
33
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
44
import Animated, {
55
interpolate,
@@ -224,7 +224,7 @@ export const CreatePollOption = ({
224224
) : null}
225225
<TextInput
226226
onChangeText={(newText) => handleChangeText(newText, index)}
227-
placeholder={t<string>('Option')}
227+
placeholder={'Add an option'}
228228
style={[styles.optionInput, { color: black }, optionStyle.input]}
229229
value={option.text}
230230
/>
@@ -274,10 +274,10 @@ export const CreatePollOptions = (props: {
274274

275275
const {
276276
theme: {
277-
colors: { black, bg_user },
277+
colors: { black },
278278
poll: {
279279
createContent: {
280-
pollOptions: { addOption, container, title },
280+
pollOptions: { container, title },
281281
},
282282
},
283283
},
@@ -301,34 +301,6 @@ export const CreatePollOptions = (props: {
301301
/>
302302
))}
303303
</View>
304-
<Pressable
305-
onPress={() => {
306-
const newIndex = options.length;
307-
currentOptionPositions.value = {
308-
inverseIndexCache: {
309-
...currentOptionPositions.value.inverseIndexCache,
310-
[newIndex]: newIndex,
311-
},
312-
positionCache: {
313-
...currentOptionPositions.value.positionCache,
314-
[newIndex]: {
315-
updatedIndex: newIndex,
316-
updatedTop: newIndex * createPollOptionHeight,
317-
},
318-
},
319-
};
320-
}}
321-
style={({ pressed }) => [
322-
{ opacity: pressed ? 0.5 : 1 },
323-
styles.addOptionWrapper,
324-
{ backgroundColor: bg_user },
325-
addOption.wrapper,
326-
]}
327-
>
328-
<Text style={[styles.text, { color: black }, addOption.text]}>
329-
{t<string>('Add an option')}
330-
</Text>
331-
</Pressable>
332304
</View>
333305
);
334306
};

package/src/components/Poll/components/NameField.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { useMessageComposer } from '../../../contexts/messageInputContext/hooks/
88
import { useStateStore } from '../../../hooks/useStateStore';
99

1010
const pollComposerStateSelector = (state: PollComposerState) => ({
11-
error: state.errors.name,
1211
name: state.data.name,
1312
});
1413

@@ -27,12 +26,20 @@ export const NameField = () => {
2726
},
2827
} = useTheme();
2928

29+
const onChangeText = async (text: string) => {
30+
await pollComposer.updateFields({ name: text });
31+
};
32+
33+
const onBlur = async () => {
34+
await pollComposer.handleFieldBlur('name');
35+
};
36+
3037
return (
3138
<View>
3239
<Text style={[styles.text, { color: black }, name.title]}>{t<string>('Questions')}</Text>
3340
<TextInput
34-
onBlur={() => pollComposer.handleFieldBlur('name')}
35-
onChangeText={(text) => pollComposer.updateFields({ name: text })}
41+
onBlur={onBlur}
42+
onChangeText={onChangeText}
3643
placeholder={t('Ask a question')}
3744
style={[
3845
styles.textInputWrapper,

0 commit comments

Comments
 (0)