From 5b670f5d130e4b976309f9f9bf9bb645046c5252 Mon Sep 17 00:00:00 2001 From: xmflsct Date: Tue, 18 Apr 2023 22:23:39 +0200 Subject: [PATCH 1/3] Fixed why toot page is not interactable --- src/screens/Tabs/Shared/Toot.tsx | 95 ++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 36 deletions(-) diff --git a/src/screens/Tabs/Shared/Toot.tsx b/src/screens/Tabs/Shared/Toot.tsx index 7876e6fc6..b8566d477 100644 --- a/src/screens/Tabs/Shared/Toot.tsx +++ b/src/screens/Tabs/Shared/Toot.tsx @@ -135,7 +135,9 @@ const TabSharedToot: React.FC> = ({ const remoteQueryEnabled = ['public', 'unlisted'].includes(toot.visibility) && match?.domain !== getAccountStorage.string('auth.domain') - const query = useQuery( + const query = useQuery<{ + pages: { body: (Mastodon.Status & { _level?: number })[] }[] + }>( queryKey.local, async () => { const context = await apiInstance<{ @@ -149,24 +151,30 @@ const TabSharedToot: React.FC> = ({ ancestorsCache.current = [...context.ancestors] const statuses = [{ ...toot }, ...context.descendants] - return statuses.map((status, index) => { - if (index === 0) { - status._level = 0 - return status - } else { - const repliedLevel: number = - statuses.find(s => s.id === status.in_reply_to_id)?._level || 0 - status._level = repliedLevel + 1 - return status - } - }) + return { + pages: [ + { + body: statuses.map((status, index) => { + if (index === 0) { + status._level = 0 + return status + } else { + const repliedLevel: number = + statuses.find(s => s.id === status.in_reply_to_id)?._level || 0 + status._level = repliedLevel + 1 + return status + } + }) + } + ] + } }, { enabled: !toot._remote, staleTime: 0, refetchOnMount: true, onSuccess: async data => { - if (data.length < 1) { + if (data.pages[0].body.length < 1) { navigation.goBack() return } @@ -239,37 +247,52 @@ const TabSharedToot: React.FC> = ({ refetchOnMount: true, retry: false, onSuccess: async data => { - if ((query.data?.length || 0) < 1 && data.length < 1) { + if ((query.data?.pages[0].body.length || 0) < 1 && data.length < 1) { navigation.goBack() return } - if ((query.data?.length || 0) < data.length) { + if ((query.data?.pages[0].body.length || 0) < data.length) { setHasRemoteContent(true) queryClient.cancelQueries(queryKey.local) - queryClient.setQueryData(queryKey.local, old => { - return data.map(remote => { - const localMatch = old?.find(local => local.uri === remote.uri) - if (localMatch) { - return { ...localMatch, _level: remote._level, ...updateCounts(remote) } - } else { - return appendRemote.status(remote, match!.domain) - } + queryClient.setQueryData<{ pages: { body: Mastodon.Status[] }[] }>( + queryKey.local, + old => ({ + pages: [ + { + body: data.map(remote => { + const localMatch = old?.pages[0].body.find(local => local.uri === remote.uri) + if (localMatch) { + return { ...localMatch, _level: remote._level, ...updateCounts(remote) } + } else { + return appendRemote.status(remote, match!.domain) + } + }) + } + ] }) - }) + ) } else { queryClient.cancelQueries(queryKey.local) - queryClient.setQueryData(queryKey.local, old => { - return old?.map(local => { - const remoteMatch = data.find(remote => remote.uri === local.uri) - if (remoteMatch) { - return { ...local, ...updateCounts(remoteMatch) } - } else { - return local - } + queryClient.setQueryData<{ pages: { body: Mastodon.Status[] }[] }>( + queryKey.local, + old => ({ + pages: [ + { + body: + old?.pages[0].body.map(local => { + const remoteMatch = data.find(remote => remote.uri === local.uri) + if (remoteMatch) { + return { ...local, ...updateCounts(remoteMatch) } + } else { + return local + } + }) || [] + } + ] }) - }) + ) } }, onSettled: async () => { @@ -285,12 +308,12 @@ const TabSharedToot: React.FC> = ({ return ( `${item.id}_${index}`} renderItem={({ item, index }) => { - const prev = query.data?.[index - 1]?._level || 0 + const prev = query.data?.pages[0].body[index - 1]?._level || 0 const curr = item._level || 0 - const next = query.data?.[index + 1]?._level || 0 + const next = query.data?.pages[0].body[index + 1]?._level || 0 const height = heights[index] || 300 let path = '' From 21200a77583a39c066d41d6cdeb4300f7f8718a5 Mon Sep 17 00:00:00 2001 From: xmflsct Date: Tue, 18 Apr 2023 22:29:05 +0200 Subject: [PATCH 2/3] Delay prepending to make sure it works --- src/screens/Tabs/Shared/Toot.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/screens/Tabs/Shared/Toot.tsx b/src/screens/Tabs/Shared/Toot.tsx index b8566d477..b2ae75358 100644 --- a/src/screens/Tabs/Shared/Toot.tsx +++ b/src/screens/Tabs/Shared/Toot.tsx @@ -77,6 +77,8 @@ const TabSharedToot: React.FC> = ({ const ancestorsCache = useRef<(Mastodon.Status & { _level?: number })[]>() const loaded = useRef(false) const prependContent = async () => { + await new Promise(promise => setTimeout(promise, 128)) + loaded.current = true if (ancestorsCache.current?.length) { @@ -173,14 +175,14 @@ const TabSharedToot: React.FC> = ({ enabled: !toot._remote, staleTime: 0, refetchOnMount: true, - onSuccess: async data => { + onSuccess: data => { if (data.pages[0].body.length < 1) { navigation.goBack() return } if (!remoteQueryEnabled) { - await prependContent() + prependContent() } } } @@ -295,9 +297,7 @@ const TabSharedToot: React.FC> = ({ ) } }, - onSettled: async () => { - await prependContent() - } + onSettled: () => prependContent() } ) From 40274ef28c5f16ed8b87905e5204e39225786eeb Mon Sep 17 00:00:00 2001 From: xmflsct Date: Tue, 18 Apr 2023 22:53:50 +0200 Subject: [PATCH 3/3] Add new neodb cards --- fastlane/metadata/zh-Hans/release_notes.txt | 3 +- src/components/Timeline/Shared/Card/Neodb.tsx | 67 +++++++++++++------ 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/fastlane/metadata/zh-Hans/release_notes.txt b/fastlane/metadata/zh-Hans/release_notes.txt index 2fa814ec4..e358eec0d 100644 --- a/fastlane/metadata/zh-Hans/release_notes.txt +++ b/fastlane/metadata/zh-Hans/release_notes.txt @@ -1,2 +1,3 @@ toooting愉快!此版本包括以下改进和修复: -- 新增希腊语 \ No newline at end of file +- 新增希腊语 +- 新增neodb专辑、播客及剧集卡片 \ No newline at end of file diff --git a/src/components/Timeline/Shared/Card/Neodb.tsx b/src/components/Timeline/Shared/Card/Neodb.tsx index 0e8c453e6..2e02f28a8 100644 --- a/src/components/Timeline/Shared/Card/Neodb.tsx +++ b/src/components/Timeline/Shared/Card/Neodb.tsx @@ -17,20 +17,17 @@ export const CardNeodb: React.FC = ({ card }) => { const { colors } = useTheme() const segments = Linking.parse(card.url).path?.split('/') - if ( - !segments || - !( - segments[0] === 'movie' || - segments[0] === 'book' || - (segments[0] === 'tv' && segments[1] !== 'season') || - segments[0] === 'game' - ) - ) + if (!segments || !['movie', 'book', 'tv', 'game', 'album', 'podcast'].includes(segments[0])) return null const [headingLines, setHeadingLines] = useState(3) - const { data } = useNeodbQuery({ path: `${segments[0]}/${segments[1]}` }) + const { data } = useNeodbQuery({ + path: + segments[0] === 'tv' && segments[1] === 'season' + ? `${segments[0]}${segments[1]}/${segments[2]}` + : `${segments[0]}/${segments[1]}` + }) if (!data) return null @@ -110,29 +107,61 @@ export const CardNeodb: React.FC = ({ card }) => { /> ) case 'tv': + if (segments[1] === 'season') { + return ( + + ) + } else { + return ( + + ) + } + case 'game': return ( ) - case 'game': + case 'album': return ( ) + case 'podcast': + return ( + + ) default: return null }