Conditionally render labels button when media exists in post (#5942)
* conditionally render button * update labels on remove * tweak
This commit is contained in:
@@ -896,13 +896,14 @@ function ComposerPills({
|
|||||||
style={bottomBarAnimatedStyle}
|
style={bottomBarAnimatedStyle}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{hasMedia || hasLink ? (
|
||||||
<LabelsBtn
|
<LabelsBtn
|
||||||
labels={draft.labels}
|
labels={draft.labels}
|
||||||
onChange={nextLabels => {
|
onChange={nextLabels => {
|
||||||
dispatch({type: 'update_labels', labels: nextLabels})
|
dispatch({type: 'update_labels', labels: nextLabels})
|
||||||
}}
|
}}
|
||||||
hasMedia={hasMedia || hasLink}
|
|
||||||
/>
|
/>
|
||||||
|
) : null}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,11 +21,9 @@ import {Text} from '#/components/Typography'
|
|||||||
|
|
||||||
export function LabelsBtn({
|
export function LabelsBtn({
|
||||||
labels,
|
labels,
|
||||||
hasMedia,
|
|
||||||
onChange,
|
onChange,
|
||||||
}: {
|
}: {
|
||||||
labels: SelfLabel[]
|
labels: SelfLabel[]
|
||||||
hasMedia: boolean
|
|
||||||
onChange: (v: SelfLabel[]) => void
|
onChange: (v: SelfLabel[]) => void
|
||||||
}) {
|
}) {
|
||||||
const control = Dialog.useDialogControl()
|
const control = Dialog.useDialogControl()
|
||||||
@@ -45,10 +43,6 @@ export function LabelsBtn({
|
|||||||
onChange([...filtered, newLabel].filter(Boolean) as SelfLabel[])
|
onChange([...filtered, newLabel].filter(Boolean) as SelfLabel[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasMedia && hasLabel) {
|
|
||||||
onChange([])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
@@ -65,7 +59,6 @@ export function LabelsBtn({
|
|||||||
msg`Opens a dialog to add a content warning to your post`,
|
msg`Opens a dialog to add a content warning to your post`,
|
||||||
)}
|
)}
|
||||||
style={[
|
style={[
|
||||||
!hasMedia && {opacity: 0.5},
|
|
||||||
native({
|
native({
|
||||||
paddingHorizontal: 8,
|
paddingHorizontal: 8,
|
||||||
paddingVertical: 6,
|
paddingVertical: 6,
|
||||||
@@ -85,7 +78,6 @@ export function LabelsBtn({
|
|||||||
<Dialog.Handle />
|
<Dialog.Handle />
|
||||||
<DialogInner
|
<DialogInner
|
||||||
labels={labels}
|
labels={labels}
|
||||||
hasMedia={hasMedia}
|
|
||||||
updateAdultLabels={updateAdultLabels}
|
updateAdultLabels={updateAdultLabels}
|
||||||
updateOtherLabels={updateOtherLabels}
|
updateOtherLabels={updateOtherLabels}
|
||||||
/>
|
/>
|
||||||
@@ -96,12 +88,10 @@ export function LabelsBtn({
|
|||||||
|
|
||||||
function DialogInner({
|
function DialogInner({
|
||||||
labels,
|
labels,
|
||||||
hasMedia,
|
|
||||||
updateAdultLabels,
|
updateAdultLabels,
|
||||||
updateOtherLabels,
|
updateOtherLabels,
|
||||||
}: {
|
}: {
|
||||||
labels: string[]
|
labels: string[]
|
||||||
hasMedia: boolean
|
|
||||||
updateAdultLabels: (labels: AdultSelfLabel[]) => void
|
updateAdultLabels: (labels: AdultSelfLabel[]) => void
|
||||||
updateOtherLabels: (labels: OtherSelfLabel[]) => void
|
updateOtherLabels: (labels: OtherSelfLabel[]) => void
|
||||||
}) {
|
}) {
|
||||||
@@ -119,32 +109,18 @@ function DialogInner({
|
|||||||
<Trans>Add a content warning</Trans>
|
<Trans>Add a content warning</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
<Text style={[t.atoms.text_contrast_medium, a.leading_snug]}>
|
<Text style={[t.atoms.text_contrast_medium, a.leading_snug]}>
|
||||||
{hasMedia ? (
|
|
||||||
<Trans>
|
<Trans>
|
||||||
Choose self-labels that are applicable for the media you are
|
Choose self-labels that are applicable for the media you are
|
||||||
posting. If none are selected, this post is suitable for all
|
posting. If none are selected, this post is suitable for all
|
||||||
audiences.
|
audiences.
|
||||||
</Trans>
|
</Trans>
|
||||||
) : (
|
|
||||||
<Trans>
|
|
||||||
No self-labels can be applied to this post because it contains
|
|
||||||
no media.
|
|
||||||
</Trans>
|
|
||||||
)}
|
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View style={[a.my_md, a.gap_lg]}>
|
<View style={[a.my_md, a.gap_lg]}>
|
||||||
{hasMedia ? (
|
|
||||||
<>
|
|
||||||
<View>
|
<View>
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[a.flex_row, a.align_center, a.justify_between, a.pb_sm]}>
|
||||||
a.flex_row,
|
|
||||||
a.align_center,
|
|
||||||
a.justify_between,
|
|
||||||
a.pb_sm,
|
|
||||||
]}>
|
|
||||||
<Text style={[a.font_bold, a.text_lg]}>
|
<Text style={[a.font_bold, a.text_lg]}>
|
||||||
<Trans>Adult Content</Trans>
|
<Trans>Adult Content</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
@@ -198,12 +174,7 @@ function DialogInner({
|
|||||||
</View>
|
</View>
|
||||||
<View>
|
<View>
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[a.flex_row, a.align_center, a.justify_between, a.pb_sm]}>
|
||||||
a.flex_row,
|
|
||||||
a.align_center,
|
|
||||||
a.justify_between,
|
|
||||||
a.pb_sm,
|
|
||||||
]}>
|
|
||||||
<Text style={[a.font_bold, a.text_lg]}>
|
<Text style={[a.font_bold, a.text_lg]}>
|
||||||
<Trans>Other</Trans>
|
<Trans>Other</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
@@ -221,9 +192,7 @@ function DialogInner({
|
|||||||
onChange={values => {
|
onChange={values => {
|
||||||
updateOtherLabels(values as OtherSelfLabel[])
|
updateOtherLabels(values as OtherSelfLabel[])
|
||||||
}}>
|
}}>
|
||||||
<Toggle.Item
|
<Toggle.Item name="graphic-media" label={_(msg`Graphic Media`)}>
|
||||||
name="graphic-media"
|
|
||||||
label={_(msg`Graphic Media`)}>
|
|
||||||
<Toggle.Checkbox />
|
<Toggle.Checkbox />
|
||||||
<Toggle.LabelText>
|
<Toggle.LabelText>
|
||||||
<Trans>Graphic Media</Trans>
|
<Trans>Graphic Media</Trans>
|
||||||
@@ -237,15 +206,11 @@ function DialogInner({
|
|||||||
audiences.
|
audiences.
|
||||||
</Trans>
|
</Trans>
|
||||||
) : (
|
) : (
|
||||||
<Trans>
|
<Trans>Does not contain graphic or disturbing content.</Trans>
|
||||||
Does not contain graphic or disturbing content.
|
|
||||||
</Trans>
|
|
||||||
)}
|
)}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</>
|
|
||||||
) : null}
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ export function composerReducer(
|
|||||||
}
|
}
|
||||||
case 'embed_remove_image': {
|
case 'embed_remove_image': {
|
||||||
const prevMedia = state.embed.media
|
const prevMedia = state.embed.media
|
||||||
|
let nextLabels = state.labels
|
||||||
if (prevMedia?.type === 'images') {
|
if (prevMedia?.type === 'images') {
|
||||||
const removedImage = action.image
|
const removedImage = action.image
|
||||||
let nextMedia: ImagesMedia | undefined = {
|
let nextMedia: ImagesMedia | undefined = {
|
||||||
@@ -168,9 +169,13 @@ export function composerReducer(
|
|||||||
}
|
}
|
||||||
if (nextMedia.images.length === 0) {
|
if (nextMedia.images.length === 0) {
|
||||||
nextMedia = undefined
|
nextMedia = undefined
|
||||||
|
if (!state.embed.link) {
|
||||||
|
nextLabels = []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
labels: nextLabels,
|
||||||
embed: {
|
embed: {
|
||||||
...state.embed,
|
...state.embed,
|
||||||
media: nextMedia,
|
media: nextMedia,
|
||||||
@@ -220,8 +225,13 @@ export function composerReducer(
|
|||||||
if (prevMedia?.type === 'video') {
|
if (prevMedia?.type === 'video') {
|
||||||
nextMedia = undefined
|
nextMedia = undefined
|
||||||
}
|
}
|
||||||
|
let nextLabels = state.labels
|
||||||
|
if (!state.embed.link) {
|
||||||
|
nextLabels = []
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
labels: nextLabels,
|
||||||
embed: {
|
embed: {
|
||||||
...state.embed,
|
...state.embed,
|
||||||
media: nextMedia,
|
media: nextMedia,
|
||||||
@@ -258,8 +268,13 @@ export function composerReducer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'embed_remove_link': {
|
case 'embed_remove_link': {
|
||||||
|
let nextLabels = state.labels
|
||||||
|
if (!state.embed.media) {
|
||||||
|
nextLabels = []
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
labels: nextLabels,
|
||||||
embed: {
|
embed: {
|
||||||
...state.embed,
|
...state.embed,
|
||||||
link: undefined,
|
link: undefined,
|
||||||
|
|||||||
Reference in New Issue
Block a user