Skip to content

Commit

Permalink
Merge branch 'main' into candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
xmflsct committed Apr 18, 2023
2 parents 7405718 + 40274ef commit 73f61b1
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 61 deletions.
3 changes: 2 additions & 1 deletion fastlane/metadata/zh-Hans/release_notes.txt
@@ -1,2 +1,3 @@
toooting愉快!此版本包括以下改进和修复:
- 新增希腊语
- 新增希腊语
- 新增neodb专辑、播客及剧集卡片
67 changes: 48 additions & 19 deletions src/components/Timeline/Shared/Card/Neodb.tsx
Expand Up @@ -17,20 +17,17 @@ export const CardNeodb: React.FC<Props> = ({ 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

Expand Down Expand Up @@ -110,29 +107,61 @@ export const CardNeodb: React.FC<Props> = ({ card }) => {
/>
)
case 'tv':
if (segments[1] === 'season') {
return (
<Content
heading={[data.title, data.orig_title, data.year ? `(${data.year})` : null]}
details={[
data.season_number ? `第${data.season_number}季` : null,
data.episode_count ? `共${data.episode_count}集` : null,
data.area?.join(' '),
data.genre?.join(' '),
data.director?.join(' ')
]}
/>
)
} else {
return (
<Content
heading={[data.title, data.orig_title, data.year ? `(${data.year})` : null]}
details={[
data.season_count ? `共${data.season_count}季` : null,
data.area?.join(' '),
data.genre?.join(' '),
data.director?.join(' ')
]}
/>
)
}
case 'game':
return (
<Content
heading={[data.title, data.orig_title, data.year ? `(${data.year})` : null]}
heading={[data.title]}
details={[
data.season_count ? `共${data.season_count}季` : null,
data.area?.join(' '),
data.genre?.join(' '),
data.director?.join(' ')
data.developer?.join(' '),
data.platform?.join(' '),
data.release_date
]}
/>
)
case 'game':
case 'album':
return (
<Content
heading={[data.title]}
details={[
data.genre?.join(' '),
data.developer?.join(' '),
data.platform?.join(' '),
data.release_date
data.artist.join(' '),
data.release_date,
data.duration,
data.genre.join(' '),
data.company.join(' ')
]}
/>
)
case 'podcast':
return (
<Content heading={[data.title]} details={[data.hosts.join(' '), data.genre.join(' ')]} />
)
default:
return null
}
Expand Down
105 changes: 64 additions & 41 deletions src/screens/Tabs/Shared/Toot.tsx
Expand Up @@ -77,6 +77,8 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
const ancestorsCache = useRef<(Mastodon.Status & { _level?: number })[]>()
const loaded = useRef<boolean>(false)
const prependContent = async () => {
await new Promise<void>(promise => setTimeout(promise, 128))

loaded.current = true

if (ancestorsCache.current?.length) {
Expand Down Expand Up @@ -135,7 +137,9 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
const remoteQueryEnabled =
['public', 'unlisted'].includes(toot.visibility) &&
match?.domain !== getAccountStorage.string('auth.domain')
const query = useQuery<Mastodon.Status[]>(
const query = useQuery<{
pages: { body: (Mastodon.Status & { _level?: number })[] }[]
}>(
queryKey.local,
async () => {
const context = await apiInstance<{
Expand All @@ -149,30 +153,36 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
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) {
onSuccess: data => {
if (data.pages[0].body.length < 1) {
navigation.goBack()
return
}

if (!remoteQueryEnabled) {
await prependContent()
prependContent()
}
}
}
Expand Down Expand Up @@ -239,42 +249,55 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
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<Mastodon.Status[]>(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<Mastodon.Status[]>(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 () => {
await prependContent()
}
onSettled: () => prependContent()
}
)

Expand All @@ -285,12 +308,12 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
return (
<FlatList
ref={flRef}
data={query.data}
data={query.data?.pages?.[0].body}
keyExtractor={(item, index) => `${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 = ''
Expand Down

0 comments on commit 73f61b1

Please sign in to comment.