mirror of https://github.com/tooot-app/app
parent
49a0e6d63e
commit
b677c4b7ce
4
index.js
4
index.js
|
@ -1,8 +1,4 @@
|
||||||
import { registerRootComponent } from 'expo'
|
import { registerRootComponent } from 'expo'
|
||||||
|
|
||||||
import App from './src/App'
|
import App from './src/App'
|
||||||
|
|
||||||
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
|
|
||||||
// It also ensures that whether you load the app in the Expo client or in a native build,
|
|
||||||
// the environment is set up appropriately
|
|
||||||
registerRootComponent(App)
|
registerRootComponent(App)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'
|
import { StyleProp, View, ViewStyle } from 'react-native'
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
extraMarginLeft?: number
|
extraMarginLeft?: number
|
||||||
|
@ -23,7 +23,7 @@ const ComponentSeparator: React.FC<Props> = ({
|
||||||
{
|
{
|
||||||
backgroundColor: colors.backgroundDefault,
|
backgroundColor: colors.backgroundDefault,
|
||||||
borderTopColor: colors.border,
|
borderTopColor: colors.border,
|
||||||
borderTopWidth: StyleSheet.hairlineWidth,
|
borderTopWidth: 1,
|
||||||
marginLeft: StyleConstants.Spacing.Global.PagePadding + extraMarginLeft,
|
marginLeft: StyleConstants.Spacing.Global.PagePadding + extraMarginLeft,
|
||||||
marginRight: StyleConstants.Spacing.Global.PagePadding + extraMarginRight
|
marginRight: StyleConstants.Spacing.Global.PagePadding + extraMarginRight
|
||||||
}
|
}
|
||||||
|
|
|
@ -329,8 +329,7 @@ const styles = StyleSheet.create({
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
minHeight: StyleConstants.Font.Size.L + StyleConstants.Spacing.S * 3,
|
paddingVertical: StyleConstants.Spacing.S * 1.5
|
||||||
marginHorizontal: StyleConstants.Spacing.S
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { useStatusQuery } from '@utils/queryHooks/status'
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import React, { useContext, useEffect, useState } from 'react'
|
import React, { useContext, useEffect, useState } from 'react'
|
||||||
import { Pressable, StyleSheet, View } from 'react-native'
|
import { Pressable, View } from 'react-native'
|
||||||
import { Circle } from 'react-native-animated-spinkit'
|
import { Circle } from 'react-native-animated-spinkit'
|
||||||
import TimelineDefault from '../Default'
|
import TimelineDefault from '../Default'
|
||||||
import StatusContext from './Context'
|
import StatusContext from './Context'
|
||||||
|
@ -192,7 +192,7 @@ const TimelineCard: React.FC = () => {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
marginTop: StyleConstants.Spacing.M,
|
marginTop: StyleConstants.Spacing.M,
|
||||||
borderWidth: StyleSheet.hairlineWidth,
|
borderWidth: 1,
|
||||||
borderRadius: StyleConstants.Spacing.S,
|
borderRadius: StyleConstants.Spacing.S,
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
borderColor: colors.border
|
borderColor: colors.border
|
||||||
|
|
|
@ -2,6 +2,7 @@ import ComponentSeparator from '@components/Separator'
|
||||||
import { useScrollToTop } from '@react-navigation/native'
|
import { useScrollToTop } from '@react-navigation/native'
|
||||||
import { UseInfiniteQueryOptions } from '@tanstack/react-query'
|
import { UseInfiniteQueryOptions } from '@tanstack/react-query'
|
||||||
import { QueryKeyTimeline, useTimelineQuery } from '@utils/queryHooks/timeline'
|
import { QueryKeyTimeline, useTimelineQuery } from '@utils/queryHooks/timeline'
|
||||||
|
import { flattenPages } from '@utils/queryHooks/utils'
|
||||||
import { useGlobalStorageListener } from '@utils/storage/actions'
|
import { useGlobalStorageListener } from '@utils/storage/actions'
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
|
@ -54,8 +55,6 @@ const Timeline: React.FC<Props> = ({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const flattenData = data?.pages ? data.pages?.flatMap(page => [...page.body]) : []
|
|
||||||
|
|
||||||
const flRef = useRef<FlatList>(null)
|
const flRef = useRef<FlatList>(null)
|
||||||
|
|
||||||
const scrollY = useSharedValue(0)
|
const scrollY = useSharedValue(0)
|
||||||
|
@ -112,7 +111,7 @@ const Timeline: React.FC<Props> = ({
|
||||||
scrollEventThrottle={16}
|
scrollEventThrottle={16}
|
||||||
onScroll={onScroll}
|
onScroll={onScroll}
|
||||||
windowSize={7}
|
windowSize={7}
|
||||||
data={flattenData}
|
data={flattenPages(data)}
|
||||||
initialNumToRender={6}
|
initialNumToRender={6}
|
||||||
maxToRenderPerBatch={3}
|
maxToRenderPerBatch={3}
|
||||||
onEndReached={() => !disableInfinity && !isFetchingNextPage && fetchNextPage()}
|
onEndReached={() => !disableInfinity && !isFetchingNextPage && fetchNextPage()}
|
||||||
|
|
|
@ -203,7 +203,7 @@ const menuStatus = ({
|
||||||
}),
|
}),
|
||||||
disabled: false,
|
disabled: false,
|
||||||
destructive: false,
|
destructive: false,
|
||||||
hidden: !ownAccount && !status.mentions.filter(mention => mention.id === accountId).length
|
hidden: !ownAccount && !status.mentions?.filter(mention => mention.id === accountId).length
|
||||||
},
|
},
|
||||||
title: t('componentContextMenu:status.mute.action', {
|
title: t('componentContextMenu:status.mute.action', {
|
||||||
defaultValue: 'false',
|
defaultValue: 'false',
|
||||||
|
|
|
@ -2,7 +2,7 @@ import TimelineDefault from '@components/Timeline/Default'
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import React, { useContext } from 'react'
|
import React, { useContext } from 'react'
|
||||||
import { StyleSheet, View } from 'react-native'
|
import { View } from 'react-native'
|
||||||
import ComposeContext from '../../utils/createContext'
|
import ComposeContext from '../../utils/createContext'
|
||||||
|
|
||||||
const ComposeReply: React.FC = () => {
|
const ComposeReply: React.FC = () => {
|
||||||
|
@ -16,7 +16,7 @@ const ComposeReply: React.FC = () => {
|
||||||
style={{
|
style={{
|
||||||
flex: 1,
|
flex: 1,
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
borderWidth: StyleSheet.hairlineWidth,
|
borderWidth: 1,
|
||||||
borderRadius: StyleConstants.Spacing.S,
|
borderRadius: StyleConstants.Spacing.S,
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
borderColor: colors.border,
|
borderColor: colors.border,
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { displayMessage } from '@components/Message'
|
||||||
import ComponentSeparator from '@components/Separator'
|
import ComponentSeparator from '@components/Separator'
|
||||||
import { TabMeStackScreenProps } from '@utils/navigation/navigators'
|
import { TabMeStackScreenProps } from '@utils/navigation/navigators'
|
||||||
import { useFollowedTagsQuery, useTagsMutation } from '@utils/queryHooks/tags'
|
import { useFollowedTagsQuery, useTagsMutation } from '@utils/queryHooks/tags'
|
||||||
|
import { flattenPages } from '@utils/queryHooks/utils'
|
||||||
import React, { useEffect } from 'react'
|
import React, { useEffect } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { FlatList } from 'react-native-gesture-handler'
|
import { FlatList } from 'react-native-gesture-handler'
|
||||||
|
@ -15,7 +16,8 @@ const TabMeFollowedTags: React.FC<TabMeStackScreenProps<'Tab-Me-FollowedTags'>>
|
||||||
const { t } = useTranslation(['common', 'screenTabs'])
|
const { t } = useTranslation(['common', 'screenTabs'])
|
||||||
|
|
||||||
const { data, fetchNextPage, refetch } = useFollowedTagsQuery()
|
const { data, fetchNextPage, refetch } = useFollowedTagsQuery()
|
||||||
const flattenData = data?.pages ? data.pages.flatMap(page => [...page.body]) : []
|
const flattenData = flattenPages(data)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (flattenData.length === 0) {
|
if (flattenData.length === 0) {
|
||||||
navigation.goBack()
|
navigation.goBack()
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
useListAccountsMutation,
|
useListAccountsMutation,
|
||||||
useListAccountsQuery
|
useListAccountsQuery
|
||||||
} from '@utils/queryHooks/lists'
|
} from '@utils/queryHooks/lists'
|
||||||
|
import { flattenPages } from '@utils/queryHooks/utils'
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
@ -18,7 +19,7 @@ import { FlatList, View } from 'react-native'
|
||||||
const TabMeListAccounts: React.FC<TabMeStackScreenProps<'Tab-Me-List-Accounts'>> = ({
|
const TabMeListAccounts: React.FC<TabMeStackScreenProps<'Tab-Me-List-Accounts'>> = ({
|
||||||
route: { params }
|
route: { params }
|
||||||
}) => {
|
}) => {
|
||||||
const { colors, theme } = useTheme()
|
const { colors } = useTheme()
|
||||||
const { t } = useTranslation(['common', 'screenTabs'])
|
const { t } = useTranslation(['common', 'screenTabs'])
|
||||||
|
|
||||||
const queryKey: QueryKeyListAccounts = ['ListAccounts', { id: params.id }]
|
const queryKey: QueryKeyListAccounts = ['ListAccounts', { id: params.id }]
|
||||||
|
@ -34,8 +35,6 @@ const TabMeListAccounts: React.FC<TabMeStackScreenProps<'Tab-Me-List-Accounts'>>
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const flattenData = data?.pages ? data.pages?.flatMap(page => [...page.body]) : []
|
|
||||||
|
|
||||||
const mutation = useListAccountsMutation({
|
const mutation = useListAccountsMutation({
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
haptics('Light')
|
haptics('Light')
|
||||||
|
@ -53,7 +52,7 @@ const TabMeListAccounts: React.FC<TabMeStackScreenProps<'Tab-Me-List-Accounts'>>
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FlatList
|
<FlatList
|
||||||
data={flattenData}
|
data={flattenPages(data)}
|
||||||
renderItem={({ item, index }) => (
|
renderItem={({ item, index }) => (
|
||||||
<ComponentAccount
|
<ComponentAccount
|
||||||
key={index}
|
key={index}
|
||||||
|
|
|
@ -89,7 +89,7 @@ const TabMeSettingsFontsize: React.FC<TabMeStackScreenProps<'Tab-Me-Settings-Fon
|
||||||
fontSize: adaptiveScale(StyleConstants.Font.Size.M, size),
|
fontSize: adaptiveScale(StyleConstants.Font.Size.M, size),
|
||||||
lineHeight: adaptiveScale(StyleConstants.Font.LineHeight.M, size),
|
lineHeight: adaptiveScale(StyleConstants.Font.LineHeight.M, size),
|
||||||
color: (fontSize || 0) === size ? colors.primaryDefault : colors.secondary,
|
color: (fontSize || 0) === size ? colors.primaryDefault : colors.secondary,
|
||||||
borderWidth: StyleSheet.hairlineWidth,
|
borderWidth: 1,
|
||||||
borderColor: colors.border
|
borderColor: colors.border
|
||||||
}}
|
}}
|
||||||
fontWeight={(fontSize || 0) === size ? 'Bold' : undefined}
|
fontWeight={(fontSize || 0) === size ? 'Bold' : undefined}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { StyleConstants } from '@utils/styles/constants'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import React, { useEffect, useRef } from 'react'
|
import React, { useEffect, useRef } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { KeyboardAvoidingView, Platform, StyleSheet, View } from 'react-native'
|
import { KeyboardAvoidingView, Platform, View } from 'react-native'
|
||||||
import { ScrollView } from 'react-native-gesture-handler'
|
import { ScrollView } from 'react-native-gesture-handler'
|
||||||
|
|
||||||
const TabMeSwitch: React.FC = () => {
|
const TabMeSwitch: React.FC = () => {
|
||||||
|
@ -49,7 +49,7 @@ const TabMeSwitch: React.FC = () => {
|
||||||
marginTop: StyleConstants.Spacing.S,
|
marginTop: StyleConstants.Spacing.S,
|
||||||
paddingTop: StyleConstants.Spacing.M,
|
paddingTop: StyleConstants.Spacing.M,
|
||||||
marginHorizontal: StyleConstants.Spacing.Global.PagePadding,
|
marginHorizontal: StyleConstants.Spacing.Global.PagePadding,
|
||||||
borderTopWidth: StyleSheet.hairlineWidth,
|
borderTopWidth: 1,
|
||||||
borderTopColor: colors.border
|
borderTopColor: colors.border
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { useNavigation } from '@react-navigation/native'
|
||||||
import { StackNavigationProp } from '@react-navigation/stack'
|
import { StackNavigationProp } from '@react-navigation/stack'
|
||||||
import { TabLocalStackParamList } from '@utils/navigation/navigators'
|
import { TabLocalStackParamList } from '@utils/navigation/navigators'
|
||||||
import { useTimelineQuery } from '@utils/queryHooks/timeline'
|
import { useTimelineQuery } from '@utils/queryHooks/timeline'
|
||||||
|
import { flattenPages } from '@utils/queryHooks/utils'
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
@ -32,12 +33,9 @@ const AccountAttachments: React.FC<Props> = ({ account }) => {
|
||||||
only_media: true
|
only_media: true
|
||||||
})
|
})
|
||||||
|
|
||||||
const flattenData = data?.pages
|
const flattenData = flattenPages(data)
|
||||||
? data.pages
|
.filter(status => !(status as Mastodon.Status).sensitive)
|
||||||
.flatMap(d => [...d.body])
|
.splice(0, DISPLAY_AMOUNT)
|
||||||
.filter(status => !(status as Mastodon.Status).sensitive)
|
|
||||||
.splice(0, DISPLAY_AMOUNT)
|
|
||||||
: []
|
|
||||||
|
|
||||||
const styleContainer = useAnimatedStyle(() => {
|
const styleContainer = useAnimatedStyle(() => {
|
||||||
if (flattenData.length) {
|
if (flattenData.length) {
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
import { HeaderLeft } from '@components/Header'
|
import { HeaderLeft } from '@components/Header'
|
||||||
import ComponentSeparator from '@components/Separator'
|
import ComponentSeparator from '@components/Separator'
|
||||||
import Timeline from '@components/Timeline'
|
import CustomText from '@components/Text'
|
||||||
import TimelineDefault from '@components/Timeline/Default'
|
import TimelineDefault from '@components/Timeline/Default'
|
||||||
import { InfiniteQueryObserver, useQueryClient } from '@tanstack/react-query'
|
|
||||||
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
||||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
import { QueryKeyTimeline, useTootQuery } from '@utils/queryHooks/timeline'
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
import React, { useEffect, useRef, useState } from 'react'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
|
import React, { useEffect, useRef } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { FlatList, View } from 'react-native'
|
import { FlatList, View } from 'react-native'
|
||||||
|
import { Path, Svg } from 'react-native-svg'
|
||||||
|
|
||||||
const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
||||||
navigation,
|
navigation,
|
||||||
|
@ -16,6 +17,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
||||||
params: { toot, rootQueryKey }
|
params: { toot, rootQueryKey }
|
||||||
}
|
}
|
||||||
}) => {
|
}) => {
|
||||||
|
const { colors } = useTheme()
|
||||||
const { t } = useTranslation('screenTabs')
|
const { t } = useTranslation('screenTabs')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -25,55 +27,23 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const queryKey: QueryKeyTimeline = ['Timeline', { page: 'Toot', toot: toot.id }]
|
|
||||||
|
|
||||||
const flRef = useRef<FlatList>(null)
|
const flRef = useRef<FlatList>(null)
|
||||||
|
|
||||||
const [itemsLength, setItemsLength] = useState(0)
|
|
||||||
const scrolled = useRef(false)
|
const scrolled = useRef(false)
|
||||||
const queryClient = useQueryClient()
|
|
||||||
const observer = new InfiniteQueryObserver(queryClient, {
|
|
||||||
queryKey,
|
|
||||||
enabled: false
|
|
||||||
})
|
|
||||||
|
|
||||||
const replyLevels = useRef<{ id: string; level: number }[]>([])
|
const queryKey: QueryKeyTimeline = ['Timeline', { page: 'Toot', toot: toot.id }]
|
||||||
const data = useRef<Mastodon.Status[]>()
|
const { data } = useTootQuery({
|
||||||
const highlightIndex = useRef<number>(0)
|
...queryKey[1],
|
||||||
useEffect(() => {
|
options: {
|
||||||
return observer.subscribe(result => {
|
meta: { toot },
|
||||||
if (result.isSuccess) {
|
onSuccess: data => {
|
||||||
const flattenData = result.data?.pages
|
if (data.body.length < 1) {
|
||||||
? // @ts-ignore
|
|
||||||
result.data.pages.flatMap(d => [...d.body])
|
|
||||||
: []
|
|
||||||
// Auto go back when toot page is empty
|
|
||||||
if (flattenData.length < 1) {
|
|
||||||
navigation.goBack()
|
navigation.goBack()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data.current = flattenData
|
|
||||||
highlightIndex.current = flattenData.findIndex(({ id }) => id === toot.id)
|
|
||||||
|
|
||||||
for (const [index, status] of flattenData.entries()) {
|
|
||||||
if (status.id === toot.id) continue
|
|
||||||
if (status.in_reply_to_id === toot.id) continue
|
|
||||||
|
|
||||||
if (!replyLevels.current.find(reply => reply.id === status.in_reply_to_id)) {
|
|
||||||
const prevLevel =
|
|
||||||
replyLevels.current.find(reply => reply.id === flattenData[index - 1].in_reply_to_id)
|
|
||||||
?.level || 0
|
|
||||||
replyLevels.current.push({
|
|
||||||
id: status.in_reply_to_id,
|
|
||||||
level: prevLevel + 1
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setItemsLength(flattenData.length)
|
|
||||||
if (!scrolled.current) {
|
if (!scrolled.current) {
|
||||||
scrolled.current = true
|
scrolled.current = true
|
||||||
const pointer = flattenData.findIndex(({ id }) => id === toot.id)
|
const pointer = data.body.findIndex(({ id }) => id === toot.id)
|
||||||
if (pointer < 1) return
|
if (pointer < 1) return
|
||||||
const length = flRef.current?.props.data?.length
|
const length = flRef.current?.props.data?.length
|
||||||
if (!length) return
|
if (!length) return
|
||||||
|
@ -91,78 +61,188 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}, [scrolled.current, replyLevels.current])
|
})
|
||||||
|
|
||||||
|
const heights = useRef<(number | undefined)[]>([])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Timeline
|
<FlatList
|
||||||
flRef={flRef}
|
ref={flRef}
|
||||||
queryKey={queryKey}
|
scrollEventThrottle={16}
|
||||||
queryOptions={{ staleTime: 0, refetchOnMount: true }}
|
windowSize={7}
|
||||||
customProps={{
|
data={data?.body}
|
||||||
ItemSeparatorComponent: ({ leadingItem }) => {
|
renderItem={({ item, index }) => {
|
||||||
const levels = {
|
const MAX_LEVEL = 10
|
||||||
current:
|
const ARC = StyleConstants.Avatar.XS / 4
|
||||||
replyLevels.current.find(reply => reply.id === leadingItem.in_reply_to_id)?.level || 0
|
|
||||||
}
|
const prev = data?.body[index - 1]?._level || 0
|
||||||
return (
|
const curr = item._level
|
||||||
|
const next = data?.body[index + 1]?._level || 0
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
paddingLeft:
|
||||||
|
index > (data?.highlightIndex || 0)
|
||||||
|
? Math.min(item._level, MAX_LEVEL) * StyleConstants.Spacing.S
|
||||||
|
: undefined
|
||||||
|
}}
|
||||||
|
onLayout={({
|
||||||
|
nativeEvent: {
|
||||||
|
layout: { height }
|
||||||
|
}
|
||||||
|
}) => (heights.current[index] = height)}
|
||||||
|
>
|
||||||
|
<TimelineDefault
|
||||||
|
item={item}
|
||||||
|
queryKey={queryKey}
|
||||||
|
rootQueryKey={rootQueryKey}
|
||||||
|
highlighted={toot.id === item.id}
|
||||||
|
isConversation={toot.id !== item.id}
|
||||||
|
/>
|
||||||
|
{curr > 1 || next > 1
|
||||||
|
? [...new Array(curr)].map((_, i) => {
|
||||||
|
if (i > MAX_LEVEL) return null
|
||||||
|
|
||||||
|
const lastLine = curr === i + 1
|
||||||
|
if (lastLine) {
|
||||||
|
if (curr === prev + 1 || curr === next - 1) {
|
||||||
|
if (curr > next) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Svg key={i} style={{ position: 'absolute' }}>
|
||||||
|
<Path
|
||||||
|
d={
|
||||||
|
`M ${curr * StyleConstants.Spacing.S + ARC} ${
|
||||||
|
StyleConstants.Spacing.M + StyleConstants.Avatar.XS / 2
|
||||||
|
} ` +
|
||||||
|
`a ${ARC} ${ARC} 0 0 0 -${ARC} ${ARC} ` +
|
||||||
|
`v 999`
|
||||||
|
}
|
||||||
|
strokeWidth={1}
|
||||||
|
stroke={colors.border}
|
||||||
|
strokeOpacity={0.6}
|
||||||
|
/>
|
||||||
|
</Svg>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
if (i >= curr - 2) return null
|
||||||
|
return (
|
||||||
|
<Svg key={i} style={{ position: 'absolute' }}>
|
||||||
|
<Path
|
||||||
|
d={
|
||||||
|
`M ${(i + 1) * StyleConstants.Spacing.S} 0 ` +
|
||||||
|
`v ${
|
||||||
|
(heights.current[index] || 999) -
|
||||||
|
(StyleConstants.Spacing.S * 1.5 + StyleConstants.Font.Size.L) / 2 -
|
||||||
|
StyleConstants.Avatar.XS / 2
|
||||||
|
} ` +
|
||||||
|
`a ${ARC} ${ARC} 0 0 0 ${ARC} ${ARC}`
|
||||||
|
}
|
||||||
|
strokeWidth={1}
|
||||||
|
stroke={colors.border}
|
||||||
|
strokeOpacity={0.6}
|
||||||
|
/>
|
||||||
|
</Svg>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (i >= next - 1) {
|
||||||
|
return (
|
||||||
|
<Svg key={i} style={{ position: 'absolute' }}>
|
||||||
|
<Path
|
||||||
|
d={
|
||||||
|
`M ${(i + 1) * StyleConstants.Spacing.S} 0 ` +
|
||||||
|
`v ${
|
||||||
|
(heights.current[index] || 999) -
|
||||||
|
(StyleConstants.Spacing.S * 1.5 +
|
||||||
|
StyleConstants.Font.Size.L * 1.35) /
|
||||||
|
2
|
||||||
|
} ` +
|
||||||
|
`h ${ARC}`
|
||||||
|
}
|
||||||
|
strokeWidth={1}
|
||||||
|
stroke={colors.border}
|
||||||
|
strokeOpacity={0.6}
|
||||||
|
/>
|
||||||
|
</Svg>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<Svg key={i} style={{ position: 'absolute' }}>
|
||||||
|
<Path
|
||||||
|
d={`M ${(i + 1) * StyleConstants.Spacing.S} 0 ` + `v 999`}
|
||||||
|
strokeWidth={1}
|
||||||
|
stroke={colors.border}
|
||||||
|
strokeOpacity={0.6}
|
||||||
|
/>
|
||||||
|
</Svg>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
: null}
|
||||||
|
{/* <CustomText
|
||||||
|
children={data?.body[index - 1]?._level}
|
||||||
|
style={{ position: 'absolute', top: 4, left: 4, color: colors.red }}
|
||||||
|
/>
|
||||||
|
<CustomText
|
||||||
|
children={item._level}
|
||||||
|
style={{ position: 'absolute', top: 20, left: 4, color: colors.yellow }}
|
||||||
|
/>
|
||||||
|
<CustomText
|
||||||
|
children={data?.body[index + 1]?._level}
|
||||||
|
style={{ position: 'absolute', top: 36, left: 4, color: colors.green }}
|
||||||
|
/> */}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
initialNumToRender={6}
|
||||||
|
maxToRenderPerBatch={3}
|
||||||
|
ItemSeparatorComponent={({ leadingItem }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
<ComponentSeparator
|
<ComponentSeparator
|
||||||
extraMarginLeft={
|
extraMarginLeft={
|
||||||
toot.id === leadingItem.id
|
toot.id === leadingItem.id
|
||||||
? 0
|
? 0
|
||||||
: StyleConstants.Avatar.XS +
|
: StyleConstants.Avatar.XS +
|
||||||
StyleConstants.Spacing.S +
|
StyleConstants.Spacing.S +
|
||||||
Math.max(0, levels.current - 1) * 8
|
Math.max(0, leadingItem._level - 1) * 8
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)
|
{leadingItem._level > 1
|
||||||
},
|
? [...new Array(leadingItem._level - 1)].map((_, i) => (
|
||||||
renderItem: ({ item, index }) => {
|
<Svg key={i} style={{ position: 'absolute', top: -1 }}>
|
||||||
const levels = {
|
<Path
|
||||||
previous:
|
d={`M ${(i + 1) * StyleConstants.Spacing.S} 0 ` + `v 1`}
|
||||||
replyLevels.current.find(
|
strokeWidth={1}
|
||||||
reply => reply.id === data.current?.[index - 1]?.in_reply_to_id
|
stroke={colors.border}
|
||||||
)?.level || 0,
|
strokeOpacity={0.6}
|
||||||
current:
|
/>
|
||||||
replyLevels.current.find(reply => reply.id === item.in_reply_to_id)?.level || 0,
|
</Svg>
|
||||||
next:
|
))
|
||||||
replyLevels.current.find(
|
: null}
|
||||||
reply => reply.id === data.current?.[index + 1]?.in_reply_to_id
|
</>
|
||||||
)?.level || 0
|
)
|
||||||
}
|
}}
|
||||||
|
onScrollToIndexFailed={error => {
|
||||||
return (
|
const offset = error.averageItemLength * error.index
|
||||||
<View
|
flRef.current?.scrollToOffset({ offset })
|
||||||
style={{ marginLeft: Math.max(0, levels.current - 1) * StyleConstants.Spacing.S }}
|
try {
|
||||||
>
|
error.index < (data?.body.length || 0) &&
|
||||||
<TimelineDefault
|
setTimeout(
|
||||||
item={item}
|
() =>
|
||||||
queryKey={queryKey}
|
flRef.current?.scrollToIndex({
|
||||||
rootQueryKey={rootQueryKey}
|
index: error.index,
|
||||||
highlighted={toot.id === item.id}
|
viewOffset: 100
|
||||||
isConversation={toot.id !== item.id}
|
}),
|
||||||
/>
|
500
|
||||||
</View>
|
)
|
||||||
)
|
} catch {}
|
||||||
},
|
|
||||||
onScrollToIndexFailed: error => {
|
|
||||||
const offset = error.averageItemLength * error.index
|
|
||||||
flRef.current?.scrollToOffset({ offset })
|
|
||||||
try {
|
|
||||||
error.index < itemsLength &&
|
|
||||||
setTimeout(
|
|
||||||
() =>
|
|
||||||
flRef.current?.scrollToIndex({
|
|
||||||
index: error.index,
|
|
||||||
viewOffset: 100
|
|
||||||
}),
|
|
||||||
500
|
|
||||||
)
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
disableRefresh
|
|
||||||
disableInfinity
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import apiInstance from '@utils/api/instance'
|
||||||
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
||||||
import { SearchResult } from '@utils/queryHooks/search'
|
import { SearchResult } from '@utils/queryHooks/search'
|
||||||
import { QueryKeyUsers, useUsersQuery } from '@utils/queryHooks/users'
|
import { QueryKeyUsers, useUsersQuery } from '@utils/queryHooks/users'
|
||||||
|
import { flattenPages } from '@utils/queryHooks/utils'
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
|
@ -39,14 +40,13 @@ const TabSharedUsers: React.FC<TabSharedStackScreenProps<'Tab-Shared-Users'>> =
|
||||||
getNextPageParam: lastPage => lastPage.links?.next?.id && { max_id: lastPage.links.next.id }
|
getNextPageParam: lastPage => lastPage.links?.next?.id && { max_id: lastPage.links.next.id }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const flattenData = data?.pages ? data.pages.flatMap(page => [...page.body]) : []
|
|
||||||
|
|
||||||
const [isSearching, setIsSearching] = useState(false)
|
const [isSearching, setIsSearching] = useState(false)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FlatList
|
<FlatList
|
||||||
windowSize={7}
|
windowSize={7}
|
||||||
data={flattenData}
|
data={flattenPages(data)}
|
||||||
style={{
|
style={{
|
||||||
minHeight: '100%',
|
minHeight: '100%',
|
||||||
paddingVertical: StyleConstants.Spacing.Global.PagePadding
|
paddingVertical: StyleConstants.Spacing.Global.PagePadding
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import haptics from '@components/haptics'
|
import haptics from '@components/haptics'
|
||||||
import {
|
import {
|
||||||
MutationOptions,
|
MutationOptions,
|
||||||
QueryFunctionContext,
|
QueryFunctionContext,
|
||||||
useInfiniteQuery,
|
useInfiniteQuery,
|
||||||
UseInfiniteQueryOptions,
|
UseInfiniteQueryOptions,
|
||||||
useMutation
|
useMutation,
|
||||||
|
useQuery,
|
||||||
|
UseQueryOptions
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
import { PagedResponse } from '@utils/api/helpers'
|
import { PagedResponse } from '@utils/api/helpers'
|
||||||
import apiInstance from '@utils/api/instance'
|
import apiInstance from '@utils/api/instance'
|
||||||
|
@ -17,6 +19,67 @@ import deleteItem from './timeline/deleteItem'
|
||||||
import editItem from './timeline/editItem'
|
import editItem from './timeline/editItem'
|
||||||
import updateStatusProperty from './timeline/updateStatusProperty'
|
import updateStatusProperty from './timeline/updateStatusProperty'
|
||||||
|
|
||||||
|
const queryFunctionToot = async ({ queryKey, meta }: QueryFunctionContext<QueryKeyTimeline>) => {
|
||||||
|
// @ts-ignore
|
||||||
|
const id = queryKey[1].toot
|
||||||
|
const target =
|
||||||
|
(meta?.toot as Mastodon.Status) ||
|
||||||
|
undefined ||
|
||||||
|
(await apiInstance<Mastodon.Status>({
|
||||||
|
method: 'get',
|
||||||
|
url: `statuses/${id}`
|
||||||
|
}).then(res => res.body))
|
||||||
|
const context = await apiInstance<{
|
||||||
|
ancestors: Mastodon.Status[]
|
||||||
|
descendants: Mastodon.Status[]
|
||||||
|
}>({
|
||||||
|
method: 'get',
|
||||||
|
url: `statuses/${id}/context`
|
||||||
|
})
|
||||||
|
|
||||||
|
const statuses: (Mastodon.Status & { _level?: number })[] = [
|
||||||
|
...context.body.ancestors,
|
||||||
|
target,
|
||||||
|
...context.body.descendants
|
||||||
|
]
|
||||||
|
|
||||||
|
const highlightIndex = context.body.ancestors.length
|
||||||
|
|
||||||
|
for (const [index, status] of statuses.entries()) {
|
||||||
|
if (index < highlightIndex || status.id === id) {
|
||||||
|
statuses[index]._level = 0
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
const repliedLevel = statuses.find(s => s.id === status.in_reply_to_id)?._level
|
||||||
|
statuses[index]._level = (repliedLevel || 0) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return { body: statuses, highlightIndex }
|
||||||
|
}
|
||||||
|
|
||||||
|
const useTootQuery = ({
|
||||||
|
options,
|
||||||
|
...queryKeyParams
|
||||||
|
}: QueryKeyTimeline[1] & {
|
||||||
|
options?: UseQueryOptions<
|
||||||
|
{
|
||||||
|
body: (Mastodon.Status & { _level: number })[]
|
||||||
|
highlightIndex: number
|
||||||
|
},
|
||||||
|
AxiosError
|
||||||
|
>
|
||||||
|
}) => {
|
||||||
|
const queryKey: QueryKeyTimeline = ['Timeline', { ...queryKeyParams }]
|
||||||
|
return useQuery(queryKey, queryFunctionToot, {
|
||||||
|
staleTime: 0,
|
||||||
|
refetchOnMount: true,
|
||||||
|
...options
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----- */
|
||||||
|
|
||||||
export type QueryKeyTimeline = [
|
export type QueryKeyTimeline = [
|
||||||
'Timeline',
|
'Timeline',
|
||||||
(
|
(
|
||||||
|
@ -36,16 +99,16 @@ export type QueryKeyTimeline = [
|
||||||
page: 'List'
|
page: 'List'
|
||||||
list: Mastodon.List['id']
|
list: Mastodon.List['id']
|
||||||
}
|
}
|
||||||
| {
|
|
||||||
page: 'Toot'
|
|
||||||
toot: Mastodon.Status['id']
|
|
||||||
}
|
|
||||||
| {
|
| {
|
||||||
page: 'Account'
|
page: 'Account'
|
||||||
account: Mastodon.Account['id']
|
account: Mastodon.Account['id']
|
||||||
exclude_reblogs: boolean
|
exclude_reblogs: boolean
|
||||||
only_media: boolean
|
only_media: boolean
|
||||||
}
|
}
|
||||||
|
| {
|
||||||
|
page: 'Toot'
|
||||||
|
toot: Mastodon.Status['id']
|
||||||
|
}
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -209,22 +272,6 @@ const queryFunction = async ({ queryKey, pageParam }: QueryFunctionContext<Query
|
||||||
url: `timelines/list/${page.list}`,
|
url: `timelines/list/${page.list}`,
|
||||||
params
|
params
|
||||||
})
|
})
|
||||||
|
|
||||||
case 'Toot':
|
|
||||||
const res1_1 = await apiInstance<Mastodon.Status>({
|
|
||||||
method: 'get',
|
|
||||||
url: `statuses/${page.toot}`
|
|
||||||
})
|
|
||||||
const res2_1 = await apiInstance<{
|
|
||||||
ancestors: Mastodon.Status[]
|
|
||||||
descendants: Mastodon.Status[]
|
|
||||||
}>({
|
|
||||||
method: 'get',
|
|
||||||
url: `statuses/${page.toot}/context`
|
|
||||||
})
|
|
||||||
return {
|
|
||||||
body: [...res2_1.body.ancestors, res1_1.body, ...res2_1.body.descendants]
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return Promise.reject()
|
return Promise.reject()
|
||||||
}
|
}
|
||||||
|
@ -454,4 +501,4 @@ const useTimelineMutation = ({
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export { useTimelineQuery, useTimelineMutation }
|
export { useTootQuery, useTimelineQuery, useTimelineMutation }
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { InfiniteData } from '@tanstack/react-query'
|
||||||
import { PagedResponse } from '@utils/api/helpers'
|
import { PagedResponse } from '@utils/api/helpers'
|
||||||
|
|
||||||
export const infinitePageParams = {
|
export const infinitePageParams = {
|
||||||
|
@ -6,3 +7,6 @@ export const infinitePageParams = {
|
||||||
getNextPageParam: (lastPage: PagedResponse<any>) =>
|
getNextPageParam: (lastPage: PagedResponse<any>) =>
|
||||||
lastPage.links?.next && { max_id: lastPage.links.next }
|
lastPage.links?.next && { max_id: lastPage.links.next }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const flattenPages = <T>(data: InfiniteData<PagedResponse<T[]>> | undefined): T[] | [] =>
|
||||||
|
data?.pages.map(page => page.body).flat() || []
|
||||||
|
|
|
@ -89,9 +89,9 @@ const themeColors: {
|
||||||
},
|
},
|
||||||
|
|
||||||
border: {
|
border: {
|
||||||
light: 'rgba(25, 25, 25, 0.3)',
|
light: 'rgb(180, 180, 180)',
|
||||||
dark_lighter: 'rgba(255, 255, 255, 0.3)',
|
dark_lighter: 'rgb(90, 90, 90)',
|
||||||
dark_darker: 'rgba(255, 255, 255, 0.3)'
|
dark_darker: 'rgb(90, 90, 90)'
|
||||||
},
|
},
|
||||||
|
|
||||||
shimmerDefault: {
|
shimmerDefault: {
|
||||||
|
|
Loading…
Reference in New Issue