1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

Removed autolinker

This commit is contained in:
xmflsct
2022-09-20 22:23:01 +02:00
parent fb3cfa0db1
commit 7ec7f85893
70 changed files with 253 additions and 7171 deletions

View File

@ -5,13 +5,20 @@ import { useAccessibility } from '@utils/accessibility/AccessibilityManager'
import { useEmojisQuery } from '@utils/queryHooks/emojis'
import { getInstanceFrequentEmojis } from '@utils/slices/instancesSlice'
import { chunk, forEach, groupBy, sortBy } from 'lodash'
import React, { PropsWithChildren, RefObject, useEffect, useReducer, useState } from 'react'
import React, {
createRef,
PropsWithChildren,
RefObject,
useEffect,
useReducer,
useState
} from 'react'
import { useTranslation } from 'react-i18next'
import { Keyboard, KeyboardAvoidingView, TextInput, View } from 'react-native'
import FastImage from 'react-native-fast-image'
import { Edge, SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context'
import { useSelector } from 'react-redux'
import EmojisContext, { emojisReducer, EmojisState } from './Emojis/helpers/EmojisContext'
import EmojisContext, { Emojis, emojisReducer, EmojisState } from './Emojis/helpers/EmojisContext'
const prefetchEmojis = (
sortedEmojis: {
@ -48,6 +55,8 @@ export type Props = {
customBehavior?: 'height' | 'padding' | 'position'
}
export const emojis: Emojis = createRef()
const ComponentEmojis: React.FC<Props & PropsWithChildren> = ({
children,
inputProps,
@ -58,11 +67,7 @@ const ComponentEmojis: React.FC<Props & PropsWithChildren> = ({
}) => {
const { reduceMotionEnabled } = useAccessibility()
const [emojisState, emojisDispatch] = useReducer(emojisReducer, {
emojis: [],
inputProps,
targetIndex: -1
})
const [emojisState, emojisDispatch] = useReducer(emojisReducer, { inputProps, targetIndex: -1 })
useEffect(() => {
emojisDispatch({ type: 'input', payload: inputProps })
}, [inputProps])
@ -72,7 +77,7 @@ const ComponentEmojis: React.FC<Props & PropsWithChildren> = ({
const frequentEmojis = useSelector(getInstanceFrequentEmojis, () => true)
useEffect(() => {
if (data && data.length) {
let sortedEmojis: EmojisState['emojis'] = []
let sortedEmojis: NonNullable<Emojis['current']> = []
forEach(groupBy(sortBy(data, ['category', 'shortcode']), 'category'), (value, key) =>
sortedEmojis.push({ title: key, data: chunk(value, 4) })
)
@ -86,7 +91,7 @@ const ComponentEmojis: React.FC<Props & PropsWithChildren> = ({
type: 'frequent'
})
}
emojisDispatch({ type: 'load', payload: sortedEmojis })
emojis.current = sortedEmojis
prefetchEmojis(sortedEmojis, reduceMotionEnabled)
}
}, [data, reduceMotionEnabled])

View File

@ -1,3 +1,4 @@
import { emojis } from '@components/Emojis'
import Icon from '@components/Icon'
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
@ -16,7 +17,7 @@ const EmojisButton: React.FC = () => {
return (
<Pressable
disabled={!emojisState.emojis || !emojisState.emojis.length}
disabled={!emojis.current || !emojis.current.length}
onPress={() => {
if (emojisState.targetIndex === -1) {
Keyboard.dismiss()
@ -38,12 +39,10 @@ const EmojisButton: React.FC = () => {
}}
>
<Icon
name={emojisState.emojis && emojisState.emojis.length ? 'Smile' : 'Meh'}
name={emojis.current && emojis.current.length ? 'Smile' : 'Meh'}
size={24}
color={
emojisState.emojis && emojisState.emojis.length
? colors.primaryDefault
: colors.disabled
emojis.current && emojis.current.length ? colors.primaryDefault : colors.disabled
}
/>
</View>

View File

@ -1,3 +1,4 @@
import { emojis } from '@components/Emojis'
import Icon from '@components/Icon'
import CustomText from '@components/Text'
import { useAppDispatch } from '@root/store'
@ -175,17 +176,19 @@ const EmojisList = () => {
? [
{
title: 'Search result',
data: chunk(
emojisState.emojis
.filter(e => e.type !== 'frequent')
.flatMap(e =>
e.data.flatMap(e => e).filter(emoji => emoji.shortcode.includes(search))
),
2
)
data: emojis.current
? chunk(
emojis.current
.filter(e => e.type !== 'frequent')
.flatMap(e =>
e.data.flatMap(e => e).filter(emoji => emoji.shortcode.includes(search))
),
2
)
: []
}
]
: emojisState.emojis
: emojis.current || []
}
keyExtractor={item => item[0]?.shortcode}
renderSectionHeader={({ section: { title } }) => (

View File

@ -10,18 +10,21 @@ type inputProps = {
addFunc?: (add: string) => void // For none default state update
}
export type Emojis = MutableRefObject<
| {
title: string
data: Pick<Mastodon.Emoji, 'shortcode' | 'url' | 'static_url'>[][]
type?: 'frequent'
}[]
| null
>
export type EmojisState = {
emojis: {
title: string
data: Pick<Mastodon.Emoji, 'shortcode' | 'url' | 'static_url'>[][]
type?: 'frequent'
}[]
inputProps: inputProps[]
targetIndex: number
}
export type EmojisAction =
| { type: 'load'; payload: NonNullable<EmojisState['emojis']> }
| { type: 'input'; payload: EmojisState['inputProps'] }
| { type: 'target'; payload: EmojisState['targetIndex'] }
@ -33,8 +36,6 @@ const EmojisContext = createContext<ContextType>({} as ContextType)
export const emojisReducer = (state: EmojisState, action: EmojisAction) => {
switch (action.type) {
case 'load':
return { ...state, emojis: action.payload }
case 'input':
return { ...state, inputProps: action.payload }
case 'target':