Skip to content

Commit bedb3ca

Browse files
committed
fix: preserve own answer in input dialog
1 parent 31240b3 commit bedb3ca

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export const EndVoteButton = () => {
105105
export const AddCommentButton = (props: PollButtonProps) => {
106106
const { t } = useTranslationContext();
107107
const { message, poll } = usePollContext();
108-
const { addComment, allow_answers, is_closed } = usePollState();
108+
const { addComment, allow_answers, is_closed, ownAnswer } = usePollState();
109109
const [showAddCommentDialog, setShowAddCommentDialog] = useState(false);
110110
const { onPress } = props;
111111

@@ -126,6 +126,7 @@ export const AddCommentButton = (props: PollButtonProps) => {
126126
{showAddCommentDialog ? (
127127
<PollInputDialog
128128
closeDialog={() => setShowAddCommentDialog(false)}
129+
initialValue={ownAnswer?.answer_text ?? ''}
129130
onSubmit={addComment}
130131
title={t<string>('Add a comment')}
131132
visible={showAddCommentDialog}
@@ -227,6 +228,7 @@ export const AnswerListAddCommentButton = (props: PollButtonProps) => {
227228
{showAddCommentDialog ? (
228229
<PollInputDialog
229230
closeDialog={() => setShowAddCommentDialog(false)}
231+
initialValue={ownAnswer?.answer_text ?? ''}
230232
onSubmit={addComment}
231233
title={t<string>('Add a comment')}
232234
visible={showAddCommentDialog}

package/src/components/Poll/components/PollInputDialog.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ export type PollInputDialogProps = {
88
onSubmit: (text: string) => void;
99
title: string;
1010
visible: boolean;
11+
initialValue?: string;
1112
};
1213

1314
export const PollInputDialog = ({
1415
closeDialog,
16+
initialValue = '',
1517
onSubmit,
1618
title,
1719
visible,
1820
}: PollInputDialogProps) => {
1921
const { t } = useTranslationContext();
20-
const [dialogInput, setDialogInput] = useState('');
22+
const [dialogInput, setDialogInput] = useState(initialValue);
2123

2224
const {
2325
theme: {

0 commit comments

Comments
 (0)