mirror of https://github.com/tooot-app/app
Attachments sensitive done
This commit is contained in:
parent
662fd08c3a
commit
69289e8d40
|
@ -67,7 +67,7 @@ export type PostState = {
|
||||||
| '604800'
|
| '604800'
|
||||||
| string
|
| string
|
||||||
}
|
}
|
||||||
attachments: Mastodon.Attachment[]
|
attachments: { sensitive: boolean; uploads: Mastodon.Attachment[] }
|
||||||
attachmentUploadProgress: { progress: number; aspect?: number } | undefined
|
attachmentUploadProgress: { progress: number; aspect?: number } | undefined
|
||||||
visibility: 'public' | 'unlisted' | 'private' | 'direct'
|
visibility: 'public' | 'unlisted' | 'private' | 'direct'
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ export type PostAction =
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'attachments'
|
type: 'attachments'
|
||||||
payload: PostState['attachments']
|
payload: Partial<PostState['attachments']>
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'attachmentUploadProgress'
|
type: 'attachmentUploadProgress'
|
||||||
|
@ -138,7 +138,7 @@ const postInitialState: PostState = {
|
||||||
multiple: false,
|
multiple: false,
|
||||||
expire: '86400'
|
expire: '86400'
|
||||||
},
|
},
|
||||||
attachments: [],
|
attachments: { sensitive: false, uploads: [] },
|
||||||
attachmentUploadProgress: undefined,
|
attachmentUploadProgress: undefined,
|
||||||
visibility:
|
visibility:
|
||||||
getLocalAccountPreferences(store.getState())[
|
getLocalAccountPreferences(store.getState())[
|
||||||
|
@ -158,16 +158,22 @@ const postReducer = (state: PostState, action: PostAction): PostState => {
|
||||||
case 'poll':
|
case 'poll':
|
||||||
return { ...state, poll: action.payload }
|
return { ...state, poll: action.payload }
|
||||||
case 'attachments':
|
case 'attachments':
|
||||||
return { ...state, attachments: action.payload }
|
return {
|
||||||
|
...state,
|
||||||
|
attachments: { ...state.attachments, ...action.payload }
|
||||||
|
}
|
||||||
case 'attachmentUploadProgress':
|
case 'attachmentUploadProgress':
|
||||||
return { ...state, attachmentUploadProgress: action.payload }
|
return { ...state, attachmentUploadProgress: action.payload }
|
||||||
case 'attachmentEdit':
|
case 'attachmentEdit':
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
attachments: state.attachments.map(attachment =>
|
attachments: {
|
||||||
attachment.id === action.payload.id ? action.payload : attachment
|
...state.attachments,
|
||||||
|
uploads: state.attachments.uploads.map(upload =>
|
||||||
|
upload.id === action.payload.id ? action.payload : upload
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case 'visibility':
|
case 'visibility':
|
||||||
return { ...state, visibility: action.payload }
|
return { ...state, visibility: action.payload }
|
||||||
default:
|
default:
|
||||||
|
@ -226,8 +232,9 @@ const Compose: React.FC = () => {
|
||||||
formData.append('poll[multiple]', postState.poll.multiple.toString())
|
formData.append('poll[multiple]', postState.poll.multiple.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (postState.attachments.length) {
|
if (postState.attachments.uploads.length) {
|
||||||
postState.attachments.forEach(e =>
|
formData.append('sensitive', postState.attachments.sensitive.toString())
|
||||||
|
postState.attachments.uploads.forEach(e =>
|
||||||
formData.append('media_ids[]', e!.id)
|
formData.append('media_ids[]', e!.id)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -248,7 +255,8 @@ const Compose: React.FC = () => {
|
||||||
postState.poll.options['3'] +
|
postState.poll.options['3'] +
|
||||||
postState.poll.multiple +
|
postState.poll.multiple +
|
||||||
postState.poll.expire +
|
postState.poll.expire +
|
||||||
postState.attachments.map(attachment => attachment.id) +
|
postState.attachments.sensitive +
|
||||||
|
postState.attachments.uploads.map(upload => upload.id) +
|
||||||
postState.visibility
|
postState.visibility
|
||||||
).toString()
|
).toString()
|
||||||
},
|
},
|
||||||
|
|
|
@ -43,31 +43,31 @@ const ComposeActions: React.FC<Props> = ({
|
||||||
if (postState.poll.active) return theme.disabled
|
if (postState.poll.active) return theme.disabled
|
||||||
if (postState.attachmentUploadProgress) return theme.primary
|
if (postState.attachmentUploadProgress) return theme.primary
|
||||||
|
|
||||||
if (postState.attachments.length) {
|
if (postState.attachments.uploads.length) {
|
||||||
return theme.primary
|
return theme.primary
|
||||||
} else {
|
} else {
|
||||||
return theme.secondary
|
return theme.secondary
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
postState.poll.active,
|
postState.poll.active,
|
||||||
postState.attachments,
|
postState.attachments.uploads,
|
||||||
postState.attachmentUploadProgress
|
postState.attachmentUploadProgress
|
||||||
])
|
])
|
||||||
const attachmentOnPress = useCallback(async () => {
|
const attachmentOnPress = useCallback(async () => {
|
||||||
if (postState.poll.active) return
|
if (postState.poll.active) return
|
||||||
if (postState.attachmentUploadProgress) return
|
if (postState.attachmentUploadProgress) return
|
||||||
|
|
||||||
if (!postState.attachments.length) {
|
if (!postState.attachments.uploads.length) {
|
||||||
return await addAttachments({ postState, postDispatch })
|
return await addAttachments({ postState, postDispatch })
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
postState.poll.active,
|
postState.poll.active,
|
||||||
postState.attachments,
|
postState.attachments.uploads,
|
||||||
postState.attachmentUploadProgress
|
postState.attachmentUploadProgress
|
||||||
])
|
])
|
||||||
|
|
||||||
const pollColor = useMemo(() => {
|
const pollColor = useMemo(() => {
|
||||||
if (postState.attachments.length) return theme.disabled
|
if (postState.attachments.uploads.length) return theme.disabled
|
||||||
if (postState.attachmentUploadProgress) return theme.disabled
|
if (postState.attachmentUploadProgress) return theme.disabled
|
||||||
|
|
||||||
if (postState.poll.active) {
|
if (postState.poll.active) {
|
||||||
|
@ -77,11 +77,14 @@ const ComposeActions: React.FC<Props> = ({
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
postState.poll.active,
|
postState.poll.active,
|
||||||
postState.attachments,
|
postState.attachments.uploads,
|
||||||
postState.attachmentUploadProgress
|
postState.attachmentUploadProgress
|
||||||
])
|
])
|
||||||
const pollOnPress = useCallback(() => {
|
const pollOnPress = useCallback(() => {
|
||||||
if (!postState.attachments.length && !postState.attachmentUploadProgress) {
|
if (
|
||||||
|
!postState.attachments.uploads.length &&
|
||||||
|
!postState.attachmentUploadProgress
|
||||||
|
) {
|
||||||
postDispatch({
|
postDispatch({
|
||||||
type: 'poll',
|
type: 'poll',
|
||||||
payload: { ...postState.poll, active: !postState.poll.active }
|
payload: { ...postState.poll, active: !postState.poll.active }
|
||||||
|
@ -92,7 +95,7 @@ const ComposeActions: React.FC<Props> = ({
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
postState.poll.active,
|
postState.poll.active,
|
||||||
postState.attachments,
|
postState.attachments.uploads,
|
||||||
postState.attachmentUploadProgress
|
postState.attachmentUploadProgress
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { useNavigation } from '@react-navigation/native'
|
||||||
import ShimmerPlaceholder from 'react-native-shimmer-placeholder'
|
import ShimmerPlaceholder from 'react-native-shimmer-placeholder'
|
||||||
import { ButtonRound } from 'src/components/Button'
|
import { ButtonRound } from 'src/components/Button'
|
||||||
import addAttachments from './addAttachments'
|
import addAttachments from './addAttachments'
|
||||||
|
import { Feather } from '@expo/vector-icons'
|
||||||
|
|
||||||
const DEFAULT_HEIGHT = 200
|
const DEFAULT_HEIGHT = 200
|
||||||
|
|
||||||
|
@ -74,7 +75,11 @@ const ComposeAttachments: React.FC<Props> = ({ postState, postDispatch }) => {
|
||||||
onPress={() =>
|
onPress={() =>
|
||||||
postDispatch({
|
postDispatch({
|
||||||
type: 'attachments',
|
type: 'attachments',
|
||||||
payload: postState.attachments.filter(e => e.id !== item.id)
|
payload: {
|
||||||
|
uploads: postState.attachments.uploads.filter(
|
||||||
|
e => e.id !== item.id
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
styles={styles.delete}
|
styles={styles.delete}
|
||||||
|
@ -105,9 +110,9 @@ const ComposeAttachments: React.FC<Props> = ({ postState, postDispatch }) => {
|
||||||
}
|
}
|
||||||
height={200}
|
height={200}
|
||||||
>
|
>
|
||||||
{postState.attachments.length > 0 &&
|
{postState.attachments.uploads.length > 0 &&
|
||||||
postState.attachments[0].type === 'image' &&
|
postState.attachments.uploads[0].type === 'image' &&
|
||||||
postState.attachments.length < 4 && (
|
postState.attachments.uploads.length < 4 && (
|
||||||
<Pressable
|
<Pressable
|
||||||
style={{
|
style={{
|
||||||
width: DEFAULT_HEIGHT,
|
width: DEFAULT_HEIGHT,
|
||||||
|
@ -139,28 +144,60 @@ const ComposeAttachments: React.FC<Props> = ({ postState, postDispatch }) => {
|
||||||
)}
|
)}
|
||||||
</ShimmerPlaceholder>
|
</ShimmerPlaceholder>
|
||||||
)
|
)
|
||||||
}, [postState.attachmentUploadProgress])
|
}, [postState.attachmentUploadProgress, postState.attachments.uploads])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.base}>
|
<View style={styles.base}>
|
||||||
|
<Pressable
|
||||||
|
style={styles.sensitive}
|
||||||
|
onPress={() =>
|
||||||
|
postDispatch({
|
||||||
|
type: 'attachments',
|
||||||
|
payload: { sensitive: !postState.attachments.sensitive }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Feather
|
||||||
|
name={postState.attachments.sensitive ? 'check-circle' : 'circle'}
|
||||||
|
size={StyleConstants.Font.Size.L}
|
||||||
|
color={theme.primary}
|
||||||
|
/>
|
||||||
|
<Text style={[styles.sensitiveText, { color: theme.primary }]}>
|
||||||
|
标记媒体为敏感内容
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
<View style={styles.imageContainer}>
|
||||||
<FlatList
|
<FlatList
|
||||||
horizontal
|
horizontal
|
||||||
extraData={postState.attachmentUploadProgress}
|
extraData={postState.attachments.uploads.length}
|
||||||
data={postState.attachments}
|
data={postState.attachments.uploads}
|
||||||
renderItem={renderAttachment}
|
renderItem={renderAttachment}
|
||||||
ListFooterComponent={listFooter}
|
ListFooterComponent={listFooter}
|
||||||
showsHorizontalScrollIndicator={false}
|
showsHorizontalScrollIndicator={false}
|
||||||
keyboardShouldPersistTaps='handled'
|
keyboardShouldPersistTaps='handled'
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
base: {
|
base: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
flexDirection: 'row',
|
|
||||||
marginRight: StyleConstants.Spacing.Global.PagePadding,
|
marginRight: StyleConstants.Spacing.Global.PagePadding,
|
||||||
|
marginTop: StyleConstants.Spacing.M
|
||||||
|
},
|
||||||
|
sensitive: {
|
||||||
|
flex: 1,
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
marginLeft: StyleConstants.Spacing.Global.PagePadding
|
||||||
|
},
|
||||||
|
sensitiveText: {
|
||||||
|
fontSize: StyleConstants.Font.Size.M,
|
||||||
|
marginLeft: StyleConstants.Spacing.S
|
||||||
|
},
|
||||||
|
imageContainer: {
|
||||||
height: DEFAULT_HEIGHT
|
height: DEFAULT_HEIGHT
|
||||||
},
|
},
|
||||||
image: {
|
image: {
|
||||||
|
@ -200,4 +237,4 @@ const styles = StyleSheet.create({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
export default React.memo(ComposeAttachments, () => true)
|
export default ComposeAttachments
|
||||||
|
|
|
@ -121,7 +121,7 @@ const ComposeRoot: React.FC<Props> = ({ postState, postDispatch }) => {
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(postState.attachments.length > 0 ||
|
{(postState.attachments.uploads.length > 0 ||
|
||||||
postState.attachmentUploadProgress) && (
|
postState.attachmentUploadProgress) && (
|
||||||
<View style={styles.attachments}>
|
<View style={styles.attachments}>
|
||||||
<ComposeAttachments
|
<ComposeAttachments
|
||||||
|
|
|
@ -48,7 +48,7 @@ const uploadAttachment = async ({
|
||||||
body.local_url = result.uri
|
body.local_url = result.uri
|
||||||
postDispatch({
|
postDispatch({
|
||||||
type: 'attachments',
|
type: 'attachments',
|
||||||
payload: postState.attachments.concat([body])
|
payload: { uploads: postState.attachments.uploads.concat([body]) }
|
||||||
})
|
})
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
} else {
|
} else {
|
||||||
|
@ -99,7 +99,6 @@ const addAttachments = async ({
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!result.cancelled) {
|
if (!result.cancelled) {
|
||||||
console.log(result)
|
|
||||||
await uploadAttachment({ result, ...params })
|
await uploadAttachment({ result, ...params })
|
||||||
}
|
}
|
||||||
} else if (buttonIndex === 1) {
|
} else if (buttonIndex === 1) {
|
||||||
|
|
Loading…
Reference in New Issue