mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Fixed #22
This commit is contained in:
@ -52,6 +52,7 @@ const Timeline: React.FC<Props> = ({
|
|||||||
...(toot && { toot }),
|
...(toot && { toot }),
|
||||||
...(account && { account })
|
...(account && { account })
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryKey: QueryKeyTimeline = ['Timeline', queryKeyParams]
|
const queryKey: QueryKeyTimeline = ['Timeline', queryKeyParams]
|
||||||
const {
|
const {
|
||||||
status,
|
status,
|
||||||
@ -73,8 +74,9 @@ const Timeline: React.FC<Props> = ({
|
|||||||
firstPage.links?.prev && {
|
firstPage.links?.prev && {
|
||||||
min_id: firstPage.links.prev,
|
min_id: firstPage.links.prev,
|
||||||
// https://github.com/facebook/react-native/issues/25239#issuecomment-731100372
|
// https://github.com/facebook/react-native/issues/25239#issuecomment-731100372
|
||||||
limit: '3'
|
limit: '8'
|
||||||
},
|
},
|
||||||
|
|
||||||
getNextPageParam: lastPage =>
|
getNextPageParam: lastPage =>
|
||||||
lastPage.links?.next && { max_id: lastPage.links.next }
|
lastPage.links?.next && { max_id: lastPage.links.next }
|
||||||
}
|
}
|
||||||
@ -82,6 +84,7 @@ const Timeline: React.FC<Props> = ({
|
|||||||
|
|
||||||
const flattenData = data?.pages ? data.pages.flatMap(d => [...d.body]) : []
|
const flattenData = data?.pages ? data.pages.flatMap(d => [...d.body]) : []
|
||||||
|
|
||||||
|
// Toot page auto scroll to selected toot
|
||||||
const flRef = useRef<FlatList<any>>(null)
|
const flRef = useRef<FlatList<any>>(null)
|
||||||
const scrolled = useRef(false)
|
const scrolled = useRef(false)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -96,6 +99,15 @@ const Timeline: React.FC<Props> = ({
|
|||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
}, [isSuccess, flattenData.length, scrolled])
|
}, [isSuccess, flattenData.length, scrolled])
|
||||||
|
const onScrollToIndexFailed = useCallback(error => {
|
||||||
|
const offset = error.averageItemLength * error.index
|
||||||
|
flRef.current?.scrollToOffset({ offset })
|
||||||
|
setTimeout(
|
||||||
|
() =>
|
||||||
|
flRef.current?.scrollToIndex({ index: error.index, viewOffset: 100 }),
|
||||||
|
350
|
||||||
|
)
|
||||||
|
}, [])
|
||||||
|
|
||||||
const keyExtractor = useCallback(({ id }) => id, [])
|
const keyExtractor = useCallback(({ id }) => id, [])
|
||||||
const renderItem = useCallback(
|
const renderItem = useCallback(
|
||||||
@ -115,6 +127,7 @@ const Timeline: React.FC<Props> = ({
|
|||||||
item={item}
|
item={item}
|
||||||
queryKey={queryKey}
|
queryKey={queryKey}
|
||||||
{...(toot === item.id && { highlighted: true })}
|
{...(toot === item.id && { highlighted: true })}
|
||||||
|
// @ts-ignore
|
||||||
{...(data?.pages[0].pinned && { pinned: data?.pages[0].pinned })}
|
{...(data?.pages[0].pinned && { pinned: data?.pages[0].pinned })}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@ -148,41 +161,51 @@ const Timeline: React.FC<Props> = ({
|
|||||||
[hasNextPage]
|
[hasNextPage]
|
||||||
)
|
)
|
||||||
|
|
||||||
const onScrollToIndexFailed = useCallback(error => {
|
|
||||||
const offset = error.averageItemLength * error.index
|
|
||||||
flRef.current?.scrollToOffset({ offset })
|
|
||||||
setTimeout(
|
|
||||||
() =>
|
|
||||||
flRef.current?.scrollToIndex({ index: error.index, viewOffset: 100 }),
|
|
||||||
350
|
|
||||||
)
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useScrollToTop(flRef)
|
useScrollToTop(flRef)
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const scrollY = useSharedValue(0)
|
const scrollY = useSharedValue(0)
|
||||||
const [isFetchingLatest, setIsFetchingLatest] = useState(false)
|
const [isFetchingLatest, setIsFetchingLatest] = useState(0)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// https://github.com/facebook/react-native/issues/25239#issuecomment-731100372
|
// https://github.com/facebook/react-native/issues/25239#issuecomment-731100372
|
||||||
if (isFetchingLatest) {
|
if (isFetchingLatest !== 0) {
|
||||||
if (!isFetchingPreviousPage) {
|
if (!isFetchingPreviousPage) {
|
||||||
fetchPreviousPage()
|
fetchPreviousPage()
|
||||||
|
setIsFetchingLatest(isFetchingLatest + 1)
|
||||||
} else {
|
} else {
|
||||||
if (data?.pages[0].body.length === 0) {
|
if (isFetchingLatest === 8) {
|
||||||
setIsFetchingLatest(false)
|
setIsFetchingLatest(0)
|
||||||
queryClient.setQueryData<InfiniteData<any> | undefined>(
|
if (data?.pages[0].body.length === 0) {
|
||||||
queryKey,
|
queryClient.setQueryData<InfiniteData<any> | undefined>(
|
||||||
data => {
|
queryKey,
|
||||||
if (data?.pages[0].body.length === 0) {
|
data => {
|
||||||
return {
|
if (data?.pages[0].body.length === 0) {
|
||||||
pages: data.pages.slice(1),
|
return {
|
||||||
pageParams: data.pageParams.slice(1)
|
pages: data.pages.slice(1),
|
||||||
|
pageParams: data.pageParams.slice(1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return data
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return data
|
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
}
|
||||||
|
} else {
|
||||||
|
if (data?.pages[0].body.length === 0) {
|
||||||
|
setIsFetchingLatest(0)
|
||||||
|
queryClient.setQueryData<InfiniteData<any> | undefined>(
|
||||||
|
queryKey,
|
||||||
|
data => {
|
||||||
|
if (data?.pages[0].body.length === 0) {
|
||||||
|
return {
|
||||||
|
pages: data.pages.slice(1),
|
||||||
|
pageParams: data.pageParams.slice(1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,11 +216,11 @@ const Timeline: React.FC<Props> = ({
|
|||||||
const onResponderRelease = useCallback(() => {
|
const onResponderRelease = useCallback(() => {
|
||||||
if (
|
if (
|
||||||
scrollY.value <= -StyleConstants.Spacing.XL &&
|
scrollY.value <= -StyleConstants.Spacing.XL &&
|
||||||
!isFetchingLatest &&
|
isFetchingLatest === 0 &&
|
||||||
!disableRefresh
|
!disableRefresh
|
||||||
) {
|
) {
|
||||||
haptics('Light')
|
haptics('Light')
|
||||||
setIsFetchingLatest(true)
|
setIsFetchingLatest(1)
|
||||||
flRef.current?.scrollToOffset({
|
flRef.current?.scrollToOffset({
|
||||||
animated: true,
|
animated: true,
|
||||||
offset: 1
|
offset: 1
|
||||||
@ -205,7 +228,7 @@ const Timeline: React.FC<Props> = ({
|
|||||||
}
|
}
|
||||||
}, [scrollY.value, isFetchingLatest, disableRefresh])
|
}, [scrollY.value, isFetchingLatest, disableRefresh])
|
||||||
const headerPadding = useAnimatedStyle(() => {
|
const headerPadding = useAnimatedStyle(() => {
|
||||||
if (isFetchingLatest) {
|
if (isFetchingLatest !== 0) {
|
||||||
return { paddingTop: withTiming(StyleConstants.Spacing.XL) }
|
return { paddingTop: withTiming(StyleConstants.Spacing.XL) }
|
||||||
} else {
|
} else {
|
||||||
return { paddingTop: withTiming(0) }
|
return { paddingTop: withTiming(0) }
|
||||||
|
@ -35,8 +35,8 @@ const ComposeEditAttachment: React.FC<ScreenComposeEditAttachmentProp> = ({
|
|||||||
theAttachment.description
|
theAttachment.description
|
||||||
)
|
)
|
||||||
const focus = useSharedValue({
|
const focus = useSharedValue({
|
||||||
x: theAttachment.meta.focus.x,
|
x: theAttachment.meta?.focus?.x,
|
||||||
y: theAttachment.meta.focus.y
|
y: theAttachment.meta?.focus?.y
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -379,7 +379,7 @@ const useTimelineMutation = ({
|
|||||||
? { onSuccess }
|
? { onSuccess }
|
||||||
: onSuccess
|
: onSuccess
|
||||||
? {
|
? {
|
||||||
onSuccess: (data, params) => {
|
onSuccess: ({ body }, params) => {
|
||||||
queryClient.cancelQueries(params.queryKey)
|
queryClient.cancelQueries(params.queryKey)
|
||||||
|
|
||||||
haptics('Success')
|
haptics('Success')
|
||||||
@ -387,7 +387,7 @@ const useTimelineMutation = ({
|
|||||||
case 'updateStatusProperty':
|
case 'updateStatusProperty':
|
||||||
switch (params.payload.property) {
|
switch (params.payload.property) {
|
||||||
case 'poll':
|
case 'poll':
|
||||||
params.payload.data = (data as unknown) as Mastodon.Poll
|
params.payload.data = (body as unknown) as Mastodon.Poll
|
||||||
updateStatusProperty({ queryClient, ...params })
|
updateStatusProperty({ queryClient, ...params })
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user