mattermost-mobile/app/screens/thread/thread.tsx
Anurag Shivarathri 5b44676985
[MM-39708] Gekidou Thread Screen (#6015)
* Thread screen

* misc

* Added snapshot for ThreadOverview

* Updated snapshot

* Misc

* Updated snapshot and ts fixes

* Made thread as a modal, fixes post list not closing on tablet

* Removed unsued variables

* Putting back the empty space before the root post (inverse list footer)

* Changed input text

* Removed empty footer space

* Misc fixes

* Disables new messages line for thread

* Loading threads before opening modal & BottomSheet componentId fix

* Moved merge navigation options to switchToThread

* Moved LeftButton to switch to thread

* Removed Q.and

* Misc fixes

* Added task id for pagination

* Removed useMemo, Q.and

* move thread close button as a prop

* Remove title font styles to use default

* Misc changes

* Misc fix

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2022-03-10 10:45:30 -03:00

94 lines
2.8 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useCallback, useEffect} from 'react';
import {BackHandler, StyleSheet, View} from 'react-native';
import {Navigation} from 'react-native-navigation';
import {Edge, SafeAreaView} from 'react-native-safe-area-context';
import PostDraft from '@components/post_draft';
import {THREAD_ACCESSORIES_CONTAINER_NATIVE_ID} from '@constants/post_draft';
import {useAppState} from '@hooks/device';
import {dismissModal} from '@screens/navigation';
import ThreadPostList from './thread_post_list';
import type PostModel from '@typings/database/models/servers/post';
type ThreadProps = {
closeButtonId: string;
componentId: string;
rootPost?: PostModel;
};
const edges: Edge[] = ['left', 'right'];
const getStyleSheet = StyleSheet.create(() => ({
flex: {
flex: 1,
},
}));
const Thread = ({closeButtonId, componentId, rootPost}: ThreadProps) => {
const appState = useAppState();
const styles = getStyleSheet();
const close = useCallback(() => {
dismissModal({componentId});
return true;
}, []);
useEffect(() => {
const unsubscribe = Navigation.events().registerComponentListener({
navigationButtonPressed: ({buttonId}: { buttonId: string }) => {
switch (buttonId) {
case closeButtonId:
close();
break;
}
},
}, componentId);
return () => {
unsubscribe.remove();
};
}, []);
useEffect(() => {
const backHandler = BackHandler.addEventListener('hardwareBackPress', close);
return () => {
backHandler.remove();
};
}, []);
return (
<>
<SafeAreaView
style={styles.flex}
mode='margin'
edges={edges}
>
{Boolean(rootPost?.id) &&
<>
<View style={styles.flex}>
<ThreadPostList
channelId={rootPost!.channelId}
forceQueryAfterAppState={appState}
nativeID={rootPost!.id}
rootPost={rootPost!}
/>
</View>
<PostDraft
channelId={rootPost!.channelId}
scrollViewNativeID={rootPost!.id}
accessoriesContainerID={THREAD_ACCESSORIES_CONTAINER_NATIVE_ID}
rootId={rootPost!.id}
/>
</>
}
</SafeAreaView>
</>
);
};
export default Thread;