POC: +n labels
This commit is contained in:
@@ -151,6 +151,83 @@ export function Label({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type LabelBaseProps = {
|
||||||
|
label: string
|
||||||
|
onPress: () => void
|
||||||
|
noBg?: boolean
|
||||||
|
} & CommonProps
|
||||||
|
|
||||||
|
export function LabelBase({label, onPress, size = 'sm', noBg}: LabelBaseProps) {
|
||||||
|
const t = useTheme()
|
||||||
|
|
||||||
|
const {outer, text} = useMemo(() => {
|
||||||
|
switch (size) {
|
||||||
|
case 'lg': {
|
||||||
|
return {
|
||||||
|
outer: [
|
||||||
|
t.atoms.bg_contrast_25,
|
||||||
|
{
|
||||||
|
gap: 5,
|
||||||
|
paddingHorizontal: 5,
|
||||||
|
paddingVertical: 5,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
text: [a.text_sm],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'sm':
|
||||||
|
default: {
|
||||||
|
return {
|
||||||
|
outer: [
|
||||||
|
!noBg && t.atoms.bg_contrast_25,
|
||||||
|
{
|
||||||
|
gap: 3,
|
||||||
|
paddingHorizontal: 3,
|
||||||
|
paddingVertical: 3,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
text: [a.text_xs],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [t, size, noBg])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
label={label}
|
||||||
|
onPress={e => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
onPress()
|
||||||
|
}}>
|
||||||
|
{({hovered, pressed}) => (
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
a.flex_row,
|
||||||
|
a.align_center,
|
||||||
|
a.rounded_full,
|
||||||
|
outer,
|
||||||
|
(hovered || pressed) && t.atoms.bg_contrast_50,
|
||||||
|
]}>
|
||||||
|
<Text
|
||||||
|
emoji
|
||||||
|
style={[
|
||||||
|
text,
|
||||||
|
a.font_semi_bold,
|
||||||
|
a.leading_tight,
|
||||||
|
t.atoms.text_contrast_medium,
|
||||||
|
{paddingRight: 3},
|
||||||
|
]}>
|
||||||
|
{label}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export function FollowsYou({size = 'sm'}: CommonProps) {
|
export function FollowsYou({size = 'sm'}: CommonProps) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,30 @@
|
|||||||
import {type StyleProp, type ViewStyle} from 'react-native'
|
import {type StyleProp, View, type ViewStyle} from 'react-native'
|
||||||
import {type ModerationCause, type ModerationUI} from '@atproto/api'
|
import {
|
||||||
|
type AppBskyFeedDefs,
|
||||||
|
type ComAtprotoLabelDefs,
|
||||||
|
type ModerationCause,
|
||||||
|
type ModerationUI,
|
||||||
|
} from '@atproto/api'
|
||||||
|
import {plural} from '@lingui/core/macro'
|
||||||
|
import {useLingui} from '@lingui/react/macro'
|
||||||
|
|
||||||
import {getModerationCauseKey, unique} from '#/lib/moderation'
|
import {getModerationCauseKey, unique} from '#/lib/moderation'
|
||||||
|
import {useSession} from '#/state/session'
|
||||||
|
import {atoms as a} from '#/alf'
|
||||||
|
import {
|
||||||
|
LabelsOnMeDialog,
|
||||||
|
useLabelsOnMeDialogControl,
|
||||||
|
} from '#/components/moderation/LabelsOnMeDialog'
|
||||||
import * as Pills from '#/components/Pills'
|
import * as Pills from '#/components/Pills'
|
||||||
|
|
||||||
export function PostAlerts({
|
export function PostAlerts({
|
||||||
|
post,
|
||||||
modui,
|
modui,
|
||||||
size = 'sm',
|
size = 'sm',
|
||||||
style,
|
style,
|
||||||
additionalCauses,
|
additionalCauses,
|
||||||
}: {
|
}: {
|
||||||
|
post?: AppBskyFeedDefs.PostView
|
||||||
modui: ModerationUI
|
modui: ModerationUI
|
||||||
size?: Pills.CommonProps['size']
|
size?: Pills.CommonProps['size']
|
||||||
includeMute?: boolean
|
includeMute?: boolean
|
||||||
@@ -46,6 +61,48 @@ export function PostAlerts({
|
|||||||
noBg={size === 'sm'}
|
noBg={size === 'sm'}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
{post?.labels?.length ? (
|
||||||
|
<AdditionalLabels labels={post.labels} size={size} />
|
||||||
|
) : null}
|
||||||
</Pills.Row>
|
</Pills.Row>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function AdditionalLabels({
|
||||||
|
labels,
|
||||||
|
size,
|
||||||
|
}: {
|
||||||
|
labels: ComAtprotoLabelDefs.Label[] | undefined
|
||||||
|
size?: Pills.CommonProps['size']
|
||||||
|
}) {
|
||||||
|
const {t: l} = useLingui()
|
||||||
|
const {currentAccount} = useSession()
|
||||||
|
const control = useLabelsOnMeDialogControl()
|
||||||
|
|
||||||
|
if (!labels || !currentAccount) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
labels = labels.filter(
|
||||||
|
l =>
|
||||||
|
!l.val.startsWith('!') &&
|
||||||
|
!(l.val === 'bot' && l.src === currentAccount.did),
|
||||||
|
)
|
||||||
|
if (!labels.length) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={[a.flex_row]}>
|
||||||
|
<LabelsOnMeDialog control={control} labels={labels} type="content" />
|
||||||
|
|
||||||
|
<Pills.LabelBase
|
||||||
|
label={l`+${plural(labels.length, {one: '# label', other: '# labels'})}`}
|
||||||
|
size={size}
|
||||||
|
noBg={size === 'sm'}
|
||||||
|
onPress={() => {
|
||||||
|
control.open()
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -388,6 +388,7 @@ const ThreadItemAnchorInner = memo(function ThreadItemAnchorInner({
|
|||||||
ignoreMute
|
ignoreMute
|
||||||
childContainerStyle={[a.pt_sm]}>
|
childContainerStyle={[a.pt_sm]}>
|
||||||
<PostAlerts
|
<PostAlerts
|
||||||
|
post={post}
|
||||||
modui={moderation.ui('contentView')}
|
modui={moderation.ui('contentView')}
|
||||||
size="lg"
|
size="lg"
|
||||||
includeMute
|
includeMute
|
||||||
|
|||||||
Reference in New Issue
Block a user