Fix pinned statuses on account page

This commit is contained in:
Zhiyuan Zheng 2021-03-09 10:35:53 +01:00
parent 4afdaf84c1
commit fa3c298b8a
No known key found for this signature in database
GPG Key ID: 078A93AB607D85E0
3 changed files with 9 additions and 11 deletions

View File

@ -19,14 +19,13 @@ import { Pressable, StyleSheet, View } from 'react-native'
import { useSelector } from 'react-redux'
export interface Props {
item: Mastodon.Status & { isPinned?: boolean }
item: Mastodon.Status & { _pinned?: boolean } // For account page, internal property
queryKey?: QueryKeyTimeline
rootQueryKey?: QueryKeyTimeline
origin?: string
highlighted?: boolean
disableDetails?: boolean
disableOnPress?: boolean
pinned?: Mastodon.Status['id'][]
}
// When the poll is long
@ -37,8 +36,7 @@ const TimelineDefault: React.FC<Props> = ({
origin,
highlighted = false,
disableDetails = false,
disableOnPress = false,
pinned
disableOnPress = false
}) => {
const { theme } = useTheme()
const instanceAccount = useSelector(getInstanceAccount, () => true)
@ -76,7 +74,7 @@ const TimelineDefault: React.FC<Props> = ({
>
{item.reblog ? (
<TimelineActioned action='reblog' account={item.account} />
) : pinned && pinned.includes(item.id) ? (
) : item._pinned ? (
<TimelineActioned action='pinned' account={item.account} />
) : null}

View File

@ -88,7 +88,6 @@ const TabSharedAccount: React.FC<SharedAccountProp> = ({
customProps={{
renderItem,
onScroll,
scrollEventThrottle: 16,
ListHeaderComponent
}}
/>

View File

@ -76,15 +76,17 @@ const queryFunction = ({
}
})
} else {
return apiInstance<(Mastodon.Status & { isPinned: boolean })[]>({
return apiInstance<(Mastodon.Status & { _pinned: boolean })[]>({
method: 'get',
url: `accounts/${account}/statuses`,
params: {
pinned: 'true'
}
}).then(async res1 => {
let pinned: Mastodon.Status['id'][] = []
res1.body.forEach(status => pinned.push(status.id))
res1.body = res1.body.map(status => {
status._pinned = true
return status
})
const res2 = await apiInstance<Mastodon.Status[]>({
method: 'get',
url: `accounts/${account}/statuses`,
@ -94,8 +96,7 @@ const queryFunction = ({
})
return {
body: uniqBy([...res1.body, ...res2.body], 'id'),
...(res2.links.next && { links: { next: res2.links.next } }),
pinned
...(res2.links.next && { links: { next: res2.links.next } })
}
})
}