Rename Slice to ThreadItem

This commit is contained in:
Eric Bailey
2025-05-30 09:53:42 -05:00
parent a7a9da03d0
commit d0170c59ea
9 changed files with 32 additions and 29 deletions
@@ -2,7 +2,10 @@ import {View} from 'react-native'
import {msg, Plural, Trans} from '@lingui/macro' import {msg, Plural, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {type PostThreadParams, type Slice} from '#/state/queries/usePostThread' import {
type PostThreadParams,
type ThreadItem,
} from '#/state/queries/usePostThread'
import { import {
LINEAR_AVI_WIDTH, LINEAR_AVI_WIDTH,
REPLY_LINE_WIDTH, REPLY_LINE_WIDTH,
@@ -18,7 +21,7 @@ export function ReadMore({
item, item,
view, view,
}: { }: {
item: Extract<Slice, {type: 'readMore'}> item: Extract<ThreadItem, {type: 'readMore'}>
view: PostThreadParams['view'] view: PostThreadParams['view']
}) { }) {
const t = useTheme() const t = useTheme()
@@ -28,7 +28,7 @@ import {
} from '#/state/cache/post-shadow' } from '#/state/cache/post-shadow'
import {useProfileShadow} from '#/state/cache/profile-shadow' import {useProfileShadow} from '#/state/cache/profile-shadow'
import {useLanguagePrefs} from '#/state/preferences' import {useLanguagePrefs} from '#/state/preferences'
import {type Slice} from '#/state/queries/usePostThread/types' import {type ThreadItem} from '#/state/queries/usePostThread/types'
import {useSession} from '#/state/session' import {useSession} from '#/state/session'
import {type OnPostSuccessData} from '#/state/shell/composer' import {type OnPostSuccessData} from '#/state/shell/composer'
import {useMergedThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies' import {useMergedThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies'
@@ -60,7 +60,7 @@ export function ThreadAnchor({
onPostSuccess, onPostSuccess,
threadgateRecord, threadgateRecord,
}: { }: {
item: Extract<Slice, {type: 'threadPost'}> item: Extract<ThreadItem, {type: 'threadPost'}>
onPostSuccess?: (data: OnPostSuccessData) => void onPostSuccess?: (data: OnPostSuccessData) => void
threadgateRecord?: AppBskyFeedThreadgate.Record threadgateRecord?: AppBskyFeedThreadgate.Record
}) { }) {
@@ -109,7 +109,7 @@ let PostThreadItemLoaded = ({
onPostSuccess, onPostSuccess,
threadgateRecord, threadgateRecord,
}: { }: {
item: Extract<Slice, {type: 'threadPost'}> item: Extract<ThreadItem, {type: 'threadPost'}>
postShadow: Shadow<AppBskyFeedDefs.PostView> postShadow: Shadow<AppBskyFeedDefs.PostView>
onPostSuccess?: (data: OnPostSuccessData) => void onPostSuccess?: (data: OnPostSuccessData) => void
threadgateRecord?: AppBskyFeedThreadgate.Record threadgateRecord?: AppBskyFeedThreadgate.Record
@@ -396,7 +396,7 @@ function ExpandedPostDetails({
post, post,
isThreadAuthor, isThreadAuthor,
}: { }: {
post: Extract<Slice, {type: 'threadPost'}>['value']['post'] post: Extract<ThreadItem, {type: 'threadPost'}>['value']['post']
isThreadAuthor: boolean isThreadAuthor: boolean
}) { }) {
const t = useTheme() const t = useTheme()
@@ -20,7 +20,7 @@ import {
type Shadow, type Shadow,
usePostShadow, usePostShadow,
} from '#/state/cache/post-shadow' } from '#/state/cache/post-shadow'
import {type Slice} from '#/state/queries/usePostThread/types' import {type ThreadItem} from '#/state/queries/usePostThread/types'
import {useSession} from '#/state/session' import {useSession} from '#/state/session'
import {type OnPostSuccessData} from '#/state/shell/composer' import {type OnPostSuccessData} from '#/state/shell/composer'
import {useMergedThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies' import {useMergedThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies'
@@ -51,7 +51,7 @@ export function ThreadPost({
onPostSuccess, onPostSuccess,
threadgateRecord, threadgateRecord,
}: { }: {
item: Extract<Slice, {type: 'threadPost'}> item: Extract<ThreadItem, {type: 'threadPost'}>
overrides?: { overrides?: {
moderation?: boolean moderation?: boolean
topBorder?: boolean topBorder?: boolean
@@ -106,7 +106,7 @@ const ThreadPostInner = memo(function ThreadPostInner({
onPostSuccess, onPostSuccess,
threadgateRecord, threadgateRecord,
}: { }: {
item: Extract<Slice, {type: 'threadPost'}> item: Extract<ThreadItem, {type: 'threadPost'}>
postShadow: Shadow<AppBskyFeedDefs.PostView> postShadow: Shadow<AppBskyFeedDefs.PostView>
overrides?: { overrides?: {
moderation?: boolean moderation?: boolean
@@ -19,7 +19,7 @@ import {
type Shadow, type Shadow,
usePostShadow, usePostShadow,
} from '#/state/cache/post-shadow' } from '#/state/cache/post-shadow'
import {type Slice} from '#/state/queries/usePostThread/types' import {type ThreadItem} from '#/state/queries/usePostThread/types'
import {useSession} from '#/state/session' import {useSession} from '#/state/session'
import {type OnPostSuccessData} from '#/state/shell/composer' import {type OnPostSuccessData} from '#/state/shell/composer'
import {useMergedThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies' import {useMergedThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies'
@@ -55,7 +55,7 @@ export function ThreadReply({
onPostSuccess, onPostSuccess,
threadgateRecord, threadgateRecord,
}: { }: {
item: Extract<Slice, {type: 'threadPost'}> item: Extract<ThreadItem, {type: 'threadPost'}>
overrides?: { overrides?: {
moderation?: boolean moderation?: boolean
topBorder?: boolean topBorder?: boolean
@@ -110,7 +110,7 @@ const ThreadReplyInner = memo(function ThreadReplyInner({
onPostSuccess, onPostSuccess,
threadgateRecord, threadgateRecord,
}: { }: {
item: Extract<Slice, {type: 'threadPost'}> item: Extract<ThreadItem, {type: 'threadPost'}>
postShadow: Shadow<AppBskyFeedDefs.PostView> postShadow: Shadow<AppBskyFeedDefs.PostView>
overrides?: { overrides?: {
moderation?: boolean moderation?: boolean
+4 -4
View File
@@ -11,7 +11,7 @@ import {isNative} from '#/platform/detection'
import {useThreadPreferences} from '#/state/queries/preferences/useThreadPreferences' import {useThreadPreferences} from '#/state/queries/preferences/useThreadPreferences'
import { import {
HiddenReplyKind, HiddenReplyKind,
type Slice, type ThreadItem,
usePostThread, usePostThread,
} from '#/state/queries/usePostThread' } from '#/state/queries/usePostThread'
import {type OnPostSuccessData} from '#/state/shell/composer' import {type OnPostSuccessData} from '#/state/shell/composer'
@@ -162,7 +162,7 @@ export function Inner({uri}: {uri: string | undefined}) {
} }
const items = useMemo(() => { const items = useMemo(() => {
const results: Slice[] = [] const results: ThreadItem[] = []
if (!data?.items) return results if (!data?.items) return results
@@ -203,7 +203,7 @@ export function Inner({uri}: {uri: string | undefined}) {
return results return results
}, [data, deferParents, maxParentCount, maxRepliesCount]) }, [data, deferParents, maxParentCount, maxRepliesCount])
const renderItem = ({item, index}: {item: Slice; index: number}) => { const renderItem = ({item, index}: {item: ThreadItem; index: number}) => {
if (item.type === 'threadPost') { if (item.type === 'threadPost') {
if (item.depth < 0) { if (item.depth < 0) {
if (deferParents) return null if (deferParents) return null
@@ -397,6 +397,6 @@ function PostThreadError({error}: {error: Error}) {
return <View /> return <View />
} }
const keyExtractor = (item: Slice) => { const keyExtractor = (item: ThreadItem) => {
return item.key return item.key
} }
+4 -4
View File
@@ -7,7 +7,7 @@ import {
import { import {
HiddenReplyKind, HiddenReplyKind,
type PostThreadParams, type PostThreadParams,
type Slice, type ThreadItem,
type TraversalMetadata, type TraversalMetadata,
} from '#/state/queries/usePostThread/types' } from '#/state/queries/usePostThread/types'
import { import {
@@ -36,9 +36,9 @@ export function traverse(
view: PostThreadParams['view'] view: PostThreadParams['view']
}, },
) { ) {
const items: Slice[] = [] const items: ThreadItem[] = []
const hidden: Slice[] = [] const hidden: ThreadItem[] = []
const muted: Slice[] = [] const muted: ThreadItem[] = []
const metadatas = new Map<string, TraversalMetadata>() const metadatas = new Map<string, TraversalMetadata>()
traversal: for (let i = 0; i < thread.length; i++) { traversal: for (let i = 0; i < thread.length; i++) {
+1 -1
View File
@@ -32,7 +32,7 @@ export enum HiddenReplyKind {
Muted = 'muted', Muted = 'muted',
} }
export type Slice = export type ThreadItem =
| { | {
type: 'threadPost' type: 'threadPost'
key: string key: string
+2 -2
View File
@@ -7,7 +7,7 @@ import {
} from '@atproto/api' } from '@atproto/api'
import { import {
type Slice, type ThreadItem,
type TraversalMetadata, type TraversalMetadata,
} from '#/state/queries/usePostThread/types' } from '#/state/queries/usePostThread/types'
import * as bsky from '#/types/bsky' import * as bsky from '#/types/bsky'
@@ -122,7 +122,7 @@ export function getThreadPostUI({
repliesSeenCount, repliesSeenCount,
repliesUnhydrated, repliesUnhydrated,
precedesChildReadMore, precedesChildReadMore,
}: TraversalMetadata): Extract<Slice, {type: 'threadPost'}>['ui'] { }: TraversalMetadata): Extract<ThreadItem, {type: 'threadPost'}>['ui'] {
// TODO might be able to simplify this // TODO might be able to simplify this
const isReplyAndHasReplies = const isReplyAndHasReplies =
depth > 0 && depth > 0 &&
+6 -6
View File
@@ -10,7 +10,7 @@ import {
import {makeProfileLink} from '#/lib/routes/links' import {makeProfileLink} from '#/lib/routes/links'
import { import {
type Slice, type ThreadItem,
type TraversalMetadata, type TraversalMetadata,
} from '#/state/queries/usePostThread/types' } from '#/state/queries/usePostThread/types'
@@ -19,7 +19,7 @@ export function threadPostNoUnauthenticated({
depth, depth,
value, value,
}: AppBskyUnspeccedGetPostThreadV2.ThreadItem): Extract< }: AppBskyUnspeccedGetPostThreadV2.ThreadItem): Extract<
Slice, ThreadItem,
{type: 'threadPostNoUnauthenticated'} {type: 'threadPostNoUnauthenticated'}
> { > {
return { return {
@@ -36,7 +36,7 @@ export function threadPostNotFound({
depth, depth,
value, value,
}: AppBskyUnspeccedGetPostThreadV2.ThreadItem): Extract< }: AppBskyUnspeccedGetPostThreadV2.ThreadItem): Extract<
Slice, ThreadItem,
{type: 'threadPostNotFound'} {type: 'threadPostNotFound'}
> { > {
return { return {
@@ -53,7 +53,7 @@ export function threadPostBlocked({
depth, depth,
value, value,
}: AppBskyUnspeccedGetPostThreadV2.ThreadItem): Extract< }: AppBskyUnspeccedGetPostThreadV2.ThreadItem): Extract<
Slice, ThreadItem,
{type: 'threadPostBlocked'} {type: 'threadPostBlocked'}
> { > {
return { return {
@@ -75,7 +75,7 @@ export function threadPost({
depth: number depth: number
value: $Typed<AppBskyUnspeccedGetPostThreadV2.ThreadItemPost> value: $Typed<AppBskyUnspeccedGetPostThreadV2.ThreadItemPost>
moderationOpts: ModerationOpts moderationOpts: ModerationOpts
}): Extract<Slice, {type: 'threadPost'}> { }): Extract<ThreadItem, {type: 'threadPost'}> {
return { return {
type: 'threadPost', type: 'threadPost',
key: uri, key: uri,
@@ -102,7 +102,7 @@ export function readMore({
repliesUnhydrated, repliesUnhydrated,
skippedIndentIndices, skippedIndentIndices,
postData, postData,
}: TraversalMetadata): Extract<Slice, {type: 'readMore'}> { }: TraversalMetadata): Extract<ThreadItem, {type: 'readMore'}> {
const urip = new AtUri(postData.uri) const urip = new AtUri(postData.uri)
const href = makeProfileLink( const href = makeProfileLink(
{ {