From 79a488c84a5dd63d8654111735c2b6a0e29099a8 Mon Sep 17 00:00:00 2001 From: xmflsct Date: Tue, 13 Sep 2022 21:53:44 +0200 Subject: [PATCH] Fix poll input --- package.json | 2 +- src/screens/Compose/Root.tsx | 42 ++++------ src/screens/Compose/utils/types.d.ts | 115 +++++++++++++-------------- 3 files changed, 74 insertions(+), 85 deletions(-) diff --git a/package.json b/package.json index bc4a51a2..7f88d524 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "versions": { "major": 4, "minor": 3, - "patch": 0 + "patch": 1 }, "description": "tooot app for Mastodon", "author": "xmflsct ", diff --git a/src/screens/Compose/Root.tsx b/src/screens/Compose/Root.tsx index 5afeaf54..9aeb08f9 100644 --- a/src/screens/Compose/Root.tsx +++ b/src/screens/Compose/Root.tsx @@ -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[][] }[] = [] - 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 ( - + ) } }, [isFetching]) + const Footer = useMemo( + () => ( + + ), + [accessibleRefAttachments.current, accessibleRefEmojis.current] + ) + return ( ( - - )} + ListFooterComponent={Footer} ItemSeparatorComponent={ComponentSeparator} // @ts-ignore data={data ? data[composeState.tag?.type] : undefined} diff --git a/src/screens/Compose/utils/types.d.ts b/src/screens/Compose/utils/types.d.ts index 3b89b956..7f4102d8 100644 --- a/src/screens/Compose/utils/types.d.ts +++ b/src/screens/Compose/utils/types.d.ts @@ -43,20 +43,17 @@ export type ComposeState = { emoji: { active: boolean emojis: - | { - title: string - data: Pick[][] - }[] - | undefined + | { + title: string + data: Pick[][] + }[] + | 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 - } + type: 'spoiler' + payload: Partial + } | { - type: 'text' - payload: Partial - } + type: 'text' + payload: Partial + } | { - type: 'tag' - payload: ComposeState['tag'] - } + type: 'tag' + payload: ComposeState['tag'] + } | { - type: 'emoji' - payload: ComposeState['emoji'] - } + type: 'emoji' + payload: ComposeState['emoji'] + } | { - type: 'poll' - payload: Partial - } + type: 'poll' + payload: Partial + } | { - type: 'attachments/sensitive' - payload: Pick - } + type: 'attachments/sensitive' + payload: Pick + } | { - type: 'attachment/upload/start' - payload: Pick - } + type: 'attachment/upload/start' + payload: Pick + } | { - 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['id'] - } + type: 'attachment/delete' + payload: NonNullable['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 - } + type: 'textInputFocus' + payload: Partial + } | { - type: 'removeReply' - } + type: 'removeReply' + }