import Button from '@components/Button' import haptics from '@components/haptics' import Icon from '@components/Icon' import RelativeTime from '@components/RelativeTime' import { ParseEmojis } from '@root/components/Parse' import { toast } from '@root/components/toast' import { QueryKeyTimeline, useTimelineMutation } from '@utils/queryHooks/timeline' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import { maxBy } from 'lodash' import React, { useCallback, useMemo, useState } from 'react' import { Trans, useTranslation } from 'react-i18next' import { Pressable, StyleSheet, Text, View } from 'react-native' import { useQueryClient } from 'react-query' export interface Props { queryKey: QueryKeyTimeline statusId: Mastodon.Status['id'] poll: NonNullable reblog: boolean sameAccount: boolean } const TimelinePoll: React.FC = ({ queryKey, statusId, poll, reblog, sameAccount }) => { const { mode, theme } = useTheme() const { t, i18n } = useTranslation('timeline') const [allOptions, setAllOptions] = useState( new Array(poll.options.length).fill(false) ) const queryClient = useQueryClient() const mutation = useTimelineMutation({ queryClient, onSuccess: true, onError: (err: any) => { haptics('Error') toast({ type: 'error', message: '投票错误', ...(err.status && typeof err.status === 'number' && err.data && err.data.error && typeof err.data.error === 'string' && { description: err.data.error }), autoHide: false }) queryClient.invalidateQueries(queryKey) } }) const pollButton = useMemo(() => { if (!poll.expired) { if (!sameAccount && !poll.voted) { return (