Fix poll input

This commit is contained in:
xmflsct 2022-09-13 21:53:44 +02:00
parent 471f3f3391
commit 79a488c84a
3 changed files with 74 additions and 85 deletions

View File

@ -3,7 +3,7 @@
"versions": {
"major": 4,
"minor": 3,
"patch": 0
"patch": 1
},
"description": "tooot app for Mastodon",
"author": "xmflsct <me@xmflsct.com>",

View File

@ -5,13 +5,7 @@ import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
import { chunk, forEach, groupBy, sortBy } from 'lodash'
import React, { useContext, useEffect, useMemo, useRef } from 'react'
import {
AccessibilityInfo,
findNodeHandle,
FlatList,
StyleSheet,
View
} from 'react-native'
import { AccessibilityInfo, findNodeHandle, FlatList, StyleSheet, View } from 'react-native'
import { Circle } from 'react-native-animated-spinkit'
import ComposeActions from './Root/Actions'
import ComposePosting from './Posting'
@ -79,8 +73,7 @@ const ComposeRoot = React.memo(
const { isFetching, data, refetch } = useSearchQuery({
type:
composeState.tag?.type === 'accounts' ||
composeState.tag?.type === 'hashtags'
composeState.tag?.type === 'accounts' || composeState.tag?.type === 'hashtags'
? composeState.tag.type
: undefined,
term: composeState.tag?.text.substring(1),
@ -89,8 +82,7 @@ const ComposeRoot = React.memo(
useEffect(() => {
if (
(composeState.tag?.type === 'accounts' ||
composeState.tag?.type === 'hashtags') &&
(composeState.tag?.type === 'accounts' || composeState.tag?.type === 'hashtags') &&
composeState.tag?.text
) {
refetch()
@ -106,10 +98,8 @@ const ComposeRoot = React.memo(
title: string
data: Pick<Mastodon.Emoji, 'shortcode' | 'url' | 'static_url'>[][]
}[] = []
forEach(
groupBy(sortBy(emojisData, ['category', 'shortcode']), 'category'),
(value, key) =>
sortedEmojis.push({ title: key, data: chunk(value, 5) })
forEach(groupBy(sortBy(emojisData, ['category', 'shortcode']), 'category'), (value, key) =>
sortedEmojis.push({ title: key, data: chunk(value, 5) })
)
if (frequentEmojis.length) {
sortedEmojis.unshift({
@ -132,15 +122,22 @@ const ComposeRoot = React.memo(
if (isFetching) {
return (
<View key='listEmpty' style={styles.loading}>
<Circle
size={StyleConstants.Font.Size.M * 1.25}
color={colors.secondary}
/>
<Circle size={StyleConstants.Font.Size.M * 1.25} color={colors.secondary} />
</View>
)
}
}, [isFetching])
const Footer = useMemo(
() => (
<ComposeRootFooter
accessibleRefAttachments={accessibleRefAttachments}
accessibleRefEmojis={accessibleRefEmojis}
/>
),
[accessibleRefAttachments.current, accessibleRefEmojis.current]
)
return (
<View style={styles.base}>
<FlatList
@ -154,12 +151,7 @@ const ComposeRoot = React.memo(
ListEmptyComponent={listEmpty}
keyboardShouldPersistTaps='always'
ListHeaderComponent={ComposeRootHeader}
ListFooterComponent={() => (
<ComposeRootFooter
accessibleRefAttachments={accessibleRefAttachments}
accessibleRefEmojis={accessibleRefEmojis}
/>
)}
ListFooterComponent={Footer}
ItemSeparatorComponent={ComponentSeparator}
// @ts-ignore
data={data ? data[composeState.tag?.type] : undefined}

View File

@ -43,20 +43,17 @@ export type ComposeState = {
emoji: {
active: boolean
emojis:
| {
title: string
data: Pick<Mastodon.Emoji, 'shortcode' | 'url' | 'static_url'>[][]
}[]
| undefined
| {
title: string
data: Pick<Mastodon.Emoji, 'shortcode' | 'url' | 'static_url'>[][]
}[]
| undefined
}
poll: {
active: boolean
total: number
options: {
'0': string | undefined
'1': string | undefined
'2': string | undefined
'3': string | undefined
[key: string]: string | undefined
}
multiple: boolean
expire: '300' | '1800' | '3600' | '21600' | '86400' | '259200' | '604800'
@ -76,69 +73,69 @@ export type ComposeState = {
export type ComposeAction =
| {
type: 'loadDraft'
payload: ComposeStateDraft
}
type: 'loadDraft'
payload: ComposeStateDraft
}
| {
type: 'dirty'
payload: ComposeState['dirty']
}
type: 'dirty'
payload: ComposeState['dirty']
}
| {
type: 'posting'
payload: ComposeState['posting']
}
type: 'posting'
payload: ComposeState['posting']
}
| {
type: 'spoiler'
payload: Partial<ComposeState['spoiler']>
}
type: 'spoiler'
payload: Partial<ComposeState['spoiler']>
}
| {
type: 'text'
payload: Partial<ComposeState['text']>
}
type: 'text'
payload: Partial<ComposeState['text']>
}
| {
type: 'tag'
payload: ComposeState['tag']
}
type: 'tag'
payload: ComposeState['tag']
}
| {
type: 'emoji'
payload: ComposeState['emoji']
}
type: 'emoji'
payload: ComposeState['emoji']
}
| {
type: 'poll'
payload: Partial<ComposeState['poll']>
}
type: 'poll'
payload: Partial<ComposeState['poll']>
}
| {
type: 'attachments/sensitive'
payload: Pick<ComposeState['attachments'], 'sensitive'>
}
type: 'attachments/sensitive'
payload: Pick<ComposeState['attachments'], 'sensitive'>
}
| {
type: 'attachment/upload/start'
payload: Pick<ExtendedAttachment, 'local' | 'uploading'>
}
type: 'attachment/upload/start'
payload: Pick<ExtendedAttachment, 'local' | 'uploading'>
}
| {
type: 'attachment/upload/end'
payload: { remote: Mastodon.Attachment; local: Asset }
}
type: 'attachment/upload/end'
payload: { remote: Mastodon.Attachment; local: Asset }
}
| {
type: 'attachment/upload/fail'
payload: ExtendedAttachment['local']['hash']
}
type: 'attachment/upload/fail'
payload: ExtendedAttachment['local']['hash']
}
| {
type: 'attachment/delete'
payload: NonNullable<ExtendedAttachment['remote']>['id']
}
type: 'attachment/delete'
payload: NonNullable<ExtendedAttachment['remote']>['id']
}
| {
type: 'attachment/edit'
payload: ExtendedAttachment['remote']
}
type: 'attachment/edit'
payload: ExtendedAttachment['remote']
}
| {
type: 'visibility'
payload: ComposeState['visibility']
}
type: 'visibility'
payload: ComposeState['visibility']
}
| {
type: 'textInputFocus'
payload: Partial<ComposeState['textInputFocus']>
}
type: 'textInputFocus'
payload: Partial<ComposeState['textInputFocus']>
}
| {
type: 'removeReply'
}
type: 'removeReply'
}