MM-49219: fixes post priority (#6880)
We have changed how priority gets saved in the server, so now instead of post.props we are using post.metadata.priority. This commit adds the relevant changes for posts' priority to work in the mobile app.
This commit is contained in:
parent
4206764881
commit
bf5783252e
9 changed files with 49 additions and 45 deletions
|
|
@ -24,8 +24,8 @@ type Props = {
|
|||
canShowPostPriority?: boolean;
|
||||
|
||||
// Post Props
|
||||
postProps: Post['props'];
|
||||
updatePostProps: (postProps: Post['props']) => void;
|
||||
postPriority: PostPriorityData;
|
||||
updatePostPriority: (postPriority: PostPriorityData) => void;
|
||||
|
||||
// Cursor Position Handler
|
||||
updateCursorPosition: React.Dispatch<React.SetStateAction<number>>;
|
||||
|
|
@ -110,8 +110,8 @@ export default function DraftInput({
|
|||
updateCursorPosition,
|
||||
cursorPosition,
|
||||
updatePostInputTop,
|
||||
postProps,
|
||||
updatePostProps,
|
||||
postPriority,
|
||||
updatePostPriority,
|
||||
setIsFocused,
|
||||
}: Props) {
|
||||
const theme = useTheme();
|
||||
|
|
@ -155,9 +155,9 @@ export default function DraftInput({
|
|||
overScrollMode={'never'}
|
||||
disableScrollViewPanResponder={true}
|
||||
>
|
||||
{Boolean(postProps.priority) && (
|
||||
{Boolean(postPriority?.priority) && (
|
||||
<View style={style.postPriorityLabel}>
|
||||
<PostPriorityLabel label={postProps.priority}/>
|
||||
<PostPriorityLabel label={postPriority!.priority}/>
|
||||
</View>
|
||||
)}
|
||||
<PostInput
|
||||
|
|
@ -188,8 +188,8 @@ export default function DraftInput({
|
|||
addFiles={addFiles}
|
||||
updateValue={updateValue}
|
||||
value={value}
|
||||
postProps={postProps}
|
||||
updatePostProps={updatePostProps}
|
||||
postPriority={postPriority}
|
||||
updatePostPriority={updatePostPriority}
|
||||
canShowPostPriority={canShowPostPriority}
|
||||
focus={focus}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import {useIntl} from 'react-intl';
|
|||
import {StyleSheet} from 'react-native';
|
||||
|
||||
import CompassIcon from '@components/compass_icon';
|
||||
import PostPriorityPicker, {PostPriorityData} from '@components/post_priority/post_priority_picker';
|
||||
import PostPriorityPicker from '@components/post_priority/post_priority_picker';
|
||||
import TouchableWithFeedback from '@components/touchable_with_feedback';
|
||||
import {ICON_SIZE} from '@constants/post_draft';
|
||||
import {useTheme} from '@context/theme';
|
||||
|
|
@ -15,8 +15,8 @@ import {changeOpacity} from '@utils/theme';
|
|||
|
||||
type Props = {
|
||||
testID?: string;
|
||||
postProps: Post['props'];
|
||||
updatePostProps: (postProps: Post['props']) => void;
|
||||
postPriority: PostPriorityData;
|
||||
updatePostPriority: (postPriority: PostPriorityData) => void;
|
||||
}
|
||||
|
||||
const style = StyleSheet.create({
|
||||
|
|
@ -29,30 +29,27 @@ const style = StyleSheet.create({
|
|||
|
||||
export default function PostPriorityAction({
|
||||
testID,
|
||||
postProps,
|
||||
updatePostProps,
|
||||
postPriority,
|
||||
updatePostPriority,
|
||||
}: Props) {
|
||||
const intl = useIntl();
|
||||
const theme = useTheme();
|
||||
|
||||
const handlePostPriorityPicker = useCallback((postPriorityData: PostPriorityData) => {
|
||||
updatePostProps((oldPostProps: Post['props']) => ({
|
||||
...oldPostProps,
|
||||
...postPriorityData,
|
||||
}));
|
||||
updatePostPriority(postPriorityData);
|
||||
dismissBottomSheet();
|
||||
}, [updatePostProps]);
|
||||
}, [updatePostPriority]);
|
||||
|
||||
const renderContent = useCallback(() => {
|
||||
return (
|
||||
<PostPriorityPicker
|
||||
data={{
|
||||
priority: postProps?.priority || '',
|
||||
priority: postPriority?.priority || '',
|
||||
}}
|
||||
onSubmit={handlePostPriorityPicker}
|
||||
/>
|
||||
);
|
||||
}, [handlePostPriorityPicker, postProps]);
|
||||
}, [handlePostPriorityPicker, postPriority]);
|
||||
|
||||
const onPress = useCallback(() => {
|
||||
bottomSheet({
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ type Props = {
|
|||
value: string;
|
||||
updateValue: (value: string) => void;
|
||||
addFiles: (file: FileInfo[]) => void;
|
||||
postProps: Post['props'];
|
||||
updatePostProps: (postProps: Post['props']) => void;
|
||||
postPriority: PostPriorityData;
|
||||
updatePostPriority: (postPriority: PostPriorityData) => void;
|
||||
focus: () => void;
|
||||
}
|
||||
|
||||
|
|
@ -45,8 +45,8 @@ export default function QuickActions({
|
|||
maxFileCount,
|
||||
updateValue,
|
||||
addFiles,
|
||||
postProps,
|
||||
updatePostProps,
|
||||
postPriority,
|
||||
updatePostPriority,
|
||||
focus,
|
||||
}: Props) {
|
||||
const atDisabled = value[value.length - 1] === '@';
|
||||
|
|
@ -101,8 +101,8 @@ export default function QuickActions({
|
|||
{isPostPriorityEnabled && canShowPostPriority && (
|
||||
<PostPriorityAction
|
||||
testID={postPriorityActionTestID}
|
||||
postProps={postProps}
|
||||
updatePostProps={updatePostProps}
|
||||
postPriority={postPriority}
|
||||
updatePostPriority={updatePostPriority}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import {setStatus} from '@actions/remote/user';
|
|||
import {canEndCall, endCall, getEndCallMessage} from '@calls/actions/calls';
|
||||
import ClientError from '@client/rest/error';
|
||||
import {Events, Screens} from '@constants';
|
||||
import {PostPriorityType} from '@constants/post';
|
||||
import {NOTIFY_ALL_MEMBERS} from '@constants/post_draft';
|
||||
import {useServerUrl} from '@context/server';
|
||||
import DraftUploadManager from '@managers/draft_upload_manager';
|
||||
|
|
@ -54,6 +55,10 @@ type Props = {
|
|||
uploadFileError: React.ReactNode;
|
||||
}
|
||||
|
||||
const INITIAL_PRIORITY = {
|
||||
priority: PostPriorityType.STANDARD,
|
||||
};
|
||||
|
||||
export default function SendHandler({
|
||||
testID,
|
||||
channelId,
|
||||
|
|
@ -83,8 +88,7 @@ export default function SendHandler({
|
|||
|
||||
const [channelTimezoneCount, setChannelTimezoneCount] = useState(0);
|
||||
const [sendingMessage, setSendingMessage] = useState(false);
|
||||
|
||||
const [postProps, setPostProps] = useState<Post['props']>({});
|
||||
const [postPriority, setPostPriority] = useState<PostPriorityData>(INITIAL_PRIORITY);
|
||||
|
||||
const canSend = useCallback(() => {
|
||||
if (sendingMessage) {
|
||||
|
|
@ -120,17 +124,19 @@ export default function SendHandler({
|
|||
message: value,
|
||||
} as Post;
|
||||
|
||||
if (Object.keys(postProps).length) {
|
||||
post.props = postProps;
|
||||
if (Object.keys(postPriority).length) {
|
||||
post.metadata = {
|
||||
priority: postPriority,
|
||||
};
|
||||
}
|
||||
|
||||
createPost(serverUrl, post, postFiles);
|
||||
|
||||
clearDraft();
|
||||
setSendingMessage(false);
|
||||
setPostProps({});
|
||||
setPostPriority(INITIAL_PRIORITY);
|
||||
DeviceEventEmitter.emit(Events.POST_LIST_SCROLL_TO_BOTTOM, rootId ? Screens.THREAD : Screens.CHANNEL);
|
||||
}, [files, currentUserId, channelId, rootId, value, clearDraft, postProps]);
|
||||
}, [files, currentUserId, channelId, rootId, value, clearDraft, postPriority]);
|
||||
|
||||
const showSendToAllOrChannelOrHereAlert = useCallback((calculatedMembersCount: number, atHere: boolean) => {
|
||||
const notifyAllMessage = DraftUtils.buildChannelWideMentionMessage(intl, calculatedMembersCount, Boolean(isTimezoneEnabled), channelTimezoneCount, atHere);
|
||||
|
|
@ -297,8 +303,8 @@ export default function SendHandler({
|
|||
canSend={canSend()}
|
||||
maxMessageLength={maxMessageLength}
|
||||
updatePostInputTop={updatePostInputTop}
|
||||
postProps={postProps}
|
||||
updatePostProps={setPostProps}
|
||||
postPriority={postPriority}
|
||||
updatePostPriority={setPostPriority}
|
||||
setIsFocused={setIsFocused}
|
||||
/>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -132,10 +132,10 @@ const Header = (props: HeaderProps) => {
|
|||
style={style.time}
|
||||
testID='post_header.date_time'
|
||||
/>
|
||||
{showPostPriority && (
|
||||
{showPostPriority && post.metadata?.priority?.priority && (
|
||||
<View style={style.postPriority}>
|
||||
<PostPriorityLabel
|
||||
label={post.props?.priority}
|
||||
label={post.metadata.priority.priority}
|
||||
/>
|
||||
</View>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -226,7 +226,7 @@ const Post = ({
|
|||
// If the post is a priority post:
|
||||
// 1. Show the priority label in channel screen
|
||||
// 2. Show the priority label in thread screen for the root post
|
||||
const showPostPriority = Boolean(isPostPriorityEnabled && post.props?.priority) && (location !== Screens.THREAD || !post.rootId);
|
||||
const showPostPriority = Boolean(isPostPriorityEnabled && post.metadata?.priority?.priority) && (location !== Screens.THREAD || !post.rootId);
|
||||
|
||||
const sameSequence = hasReplies ? (hasReplies && post.rootId) : !post.rootId;
|
||||
if (!showPostPriority && hasSameRoot && isConsecutivePost && sameSequence) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ const style = StyleSheet.create({
|
|||
});
|
||||
|
||||
type Props = {
|
||||
label: PostPriorityType;
|
||||
label: PostPriorityData['priority'];
|
||||
};
|
||||
|
||||
const PostPriorityLabel = ({label}: Props) => {
|
||||
|
|
@ -48,7 +48,7 @@ const PostPriorityLabel = ({label}: Props) => {
|
|||
containerStyle.push(style.urgent);
|
||||
iconName = 'alert-outline';
|
||||
labelText = intl.formatMessage({id: 'post_priority.label.urgent', defaultMessage: 'URGENT'});
|
||||
} else {
|
||||
} else if (label === PostPriorityType.IMPORTANT) {
|
||||
containerStyle.push(style.important);
|
||||
iconName = 'alert-circle-outline';
|
||||
labelText = intl.formatMessage({id: 'post_priority.label.important', defaultMessage: 'IMPORTANT'});
|
||||
|
|
|
|||
|
|
@ -14,10 +14,6 @@ import {typography} from '@utils/typography';
|
|||
|
||||
import PostPriorityPickerItem from './post_priority_picker_item';
|
||||
|
||||
export type PostPriorityData = {
|
||||
priority: PostPriorityType;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
data: PostPriorityData;
|
||||
onSubmit: (data: PostPriorityData) => void;
|
||||
|
|
@ -61,8 +57,8 @@ const PostPriorityPicker = ({data, onSubmit}: Props) => {
|
|||
// For now, we just have one option but the spec suggest we have more in the next phase
|
||||
// const [data, setData] = React.useState<PostPriorityData>(defaultData);
|
||||
|
||||
const handleUpdatePriority = React.useCallback((priority: PostPriorityType) => {
|
||||
onSubmit({priority});
|
||||
const handleUpdatePriority = React.useCallback((priority: PostPriorityData['priority']) => {
|
||||
onSubmit({priority: priority || ''});
|
||||
}, [onSubmit]);
|
||||
|
||||
return (
|
||||
|
|
|
|||
5
types/api/posts.d.ts
vendored
5
types/api/posts.d.ts
vendored
|
|
@ -20,6 +20,10 @@ type PostType =
|
|||
|
||||
type PostEmbedType = 'image' | 'message_attachment' | 'opengraph';
|
||||
|
||||
type PostPriorityData = {
|
||||
priority: ''|'urgent'|'important';
|
||||
};
|
||||
|
||||
type PostEmbed = {
|
||||
type: PostEmbedType;
|
||||
url: string;
|
||||
|
|
@ -39,6 +43,7 @@ type PostMetadata = {
|
|||
files?: FileInfo[];
|
||||
images?: Dictionary<PostImage>;
|
||||
reactions?: Reaction[];
|
||||
priority?: PostPriorityData;
|
||||
};
|
||||
|
||||
type Post = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue