MM-41886 Gekidou Long Press Menu - Copy text and Copy Permalink options (#5977)

This commit is contained in:
Avinash Lingaloo 2022-02-16 17:40:14 +04:00 committed by GitHub
parent 03d5ac083c
commit b256f7fcce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 99 additions and 33 deletions

View file

@ -1,25 +0,0 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {t} from '@i18n';
import BaseOption from './base_option';
const CopyPermalinkOption = () => {
const handleCopyLink = () => {
//todo:
};
return (
<BaseOption
i18nId={t('get_post_link_modal.title')}
defaultMessage='Copy Link'
onPress={handleCopyLink}
iconName='link-variant'
testID='post.options.copy.permalink'
/>
);
};
export default CopyPermalinkOption;

View file

@ -0,0 +1,40 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import Clipboard from '@react-native-community/clipboard';
import React, {useCallback} from 'react';
import {Screens} from '@constants';
import {useServerUrl} from '@context/server';
import {t} from '@i18n';
import {dismissBottomSheet} from '@screens/navigation';
import BaseOption from '../base_option';
import type PostModel from '@typings/database/models/servers/post';
type Props = {
teamName: string;
post: PostModel;
}
const CopyPermalinkOption = ({teamName, post}: Props) => {
const serverUrl = useServerUrl();
const handleCopyLink = useCallback(() => {
const permalink = `${serverUrl}/${teamName}/pl/${post.id}`;
Clipboard.setString(permalink);
dismissBottomSheet(Screens.POST_OPTIONS);
}, [teamName, post.id]);
return (
<BaseOption
i18nId={t('get_post_link_modal.title')}
defaultMessage='Copy Link'
onPress={handleCopyLink}
iconName='link-variant'
testID='post.options.copy.permalink'
/>
);
};
export default CopyPermalinkOption;

View file

@ -0,0 +1,43 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {withDatabase} from '@nozbe/watermelondb/DatabaseProvider';
import withObservables from '@nozbe/with-observables';
import {combineLatest, of as of$} from 'rxjs';
import {switchMap} from 'rxjs/dist/types/operators';
import {MM_TABLES, SYSTEM_IDENTIFIERS} from '@constants/database';
import CopyPermalinkOption from './copy_permalink_option';
import type {WithDatabaseArgs} from '@typings/database/database';
import type PostModel from '@typings/database/models/servers/post';
import type SystemModel from '@typings/database/models/servers/system';
import type TeamModel from '@typings/database/models/servers/team';
const {SERVER: {SYSTEM, TEAM}} = MM_TABLES;
const {CURRENT_TEAM_ID} = SYSTEM_IDENTIFIERS;
const enhanced = withObservables(['post'], ({post, database}: WithDatabaseArgs & { post: PostModel }) => {
const currentTeamId = database.get<SystemModel>(SYSTEM).findAndObserve(CURRENT_TEAM_ID);
const channel = post.channel.observe();
const teamName = combineLatest([channel, currentTeamId]).pipe(
switchMap(([c, tid]) => {
const teamId = c.teamId || tid;
return database.
get<TeamModel>(TEAM).
findAndObserve(teamId).
pipe(
// eslint-disable-next-line max-nested-callbacks
switchMap((team: TeamModel) => of$(team.name)),
);
}),
);
return {
teamName,
};
});
export default withDatabase(enhanced(CopyPermalinkOption));

View file

@ -1,16 +1,24 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import Clipboard from '@react-native-community/clipboard';
import React, {useCallback} from 'react';
import {Screens} from '@constants';
import {t} from '@i18n';
import {dismissBottomSheet} from '@screens/navigation';
import BaseOption from './base_option';
const CopyTextOption = () => {
const handleCopyText = () => {
//todo:
};
type Props = {
postMessage: string;
}
const CopyTextOption = ({postMessage}: Props) => {
const handleCopyText = useCallback(() => {
Clipboard.setString(postMessage);
dismissBottomSheet(Screens.POST_OPTIONS);
}, [postMessage]);
return (
<BaseOption
i18nId={t('mobile.post_info.copy_text')}

View file

@ -9,7 +9,7 @@ import {Screens} from '@constants';
import BottomSheet from '@screens/bottom_sheet';
import {isSystemMessage} from '@utils/post';
import CopyLinkOption from './components/options/copy_link_option';
import CopyLinkOption from './components/options/copy_permalink_option';
import CopyTextOption from './components/options/copy_text_option';
import DeletePostOption from './components/options/delete_post_option';
import EditOption from './components/options/edit_option';
@ -75,9 +75,9 @@ const PostOptions = ({
/>
}
{canMarkAsUnread && !isSystemPost && (<MarkAsUnreadOption/>)}
{canCopyPermalink && <CopyLinkOption/>}
{canCopyPermalink && <CopyLinkOption post={post}/>}
{!isSystemPost && <SaveOption isSaved={isSaved}/>}
{canCopyText && <CopyTextOption/>}
{canCopyText && <CopyTextOption postMessage={post.message}/>}
{canPin && <PinChannelOption isPostPinned={post.isPinned}/>}
{canEdit && <EditOption/>}
{canDelete && <DeletePostOption/>}