mattermost-mobile/app/components/common_post_options/save_option.tsx
Anurag Shivarathri 313fe9c469
In-Channel experience (#6141)
* User avatar stack

* In-Channel experience

* Misc Fixes

* Fixed fetchPostThread & added observer

* Reusing the user component

* Refactor fix

* Moved some post options to common post options

* Combined follow/unfollow functions

* Feedback fixes

* Feedback fixes

* teamId fix

* Fixed teamId again

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2022-04-19 11:42:20 -04:00

41 lines
1.3 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useCallback} from 'react';
import {deleteSavedPost, savePostPreference} from '@actions/remote/preference';
import {BaseOption} from '@components/common_post_options';
import {Screens} from '@constants';
import {useServerUrl} from '@context/server';
import {t} from '@i18n';
import {dismissBottomSheet} from '@screens/navigation';
type CopyTextProps = {
isSaved: boolean;
postId: string;
}
const SaveOption = ({isSaved, postId}: CopyTextProps) => {
const serverUrl = useServerUrl();
const onHandlePress = useCallback(async () => {
const remoteAction = isSaved ? deleteSavedPost : savePostPreference;
remoteAction(serverUrl, postId);
dismissBottomSheet(Screens.POST_OPTIONS);
}, [postId, serverUrl]);
const id = isSaved ? t('mobile.post_info.unsave') : t('mobile.post_info.save');
const defaultMessage = isSaved ? 'Unsave' : 'Save';
return (
<BaseOption
i18nId={id}
defaultMessage={defaultMessage}
iconName='bookmark-outline'
onPress={onHandlePress}
testID={`post_options.${defaultMessage.toLocaleLowerCase()}.channel.option`}
/>
);
};
export default SaveOption;