Skip to content

Commit

Permalink
[native] Remove ChatThreadList class component
Browse files Browse the repository at this point in the history
Summary:
This diff finally removes the `ChatThreadList` class component altogether.

That said, this functional component is still cluttered and hasn't been optimized. I will work to declutter `ChatThreadList` and improve performance in subsequent diffs.

---

Depends on D9190

Test Plan: Everything continues to work as expected/before!

Reviewers: ginsu, tomek, rohan

Reviewed By: ginsu

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D9191
  • Loading branch information
atulsmadhugiri committed Sep 13, 2023
1 parent 069f7d7 commit abee4be
Showing 1 changed file with 7 additions and 40 deletions.
47 changes: 7 additions & 40 deletions native/chat/chat-thread-list.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,8 @@ type BaseProps = {
+emptyItem?: React.ComponentType<{}>,
};
type SearchStatus = 'inactive' | 'activating' | 'active';
type Props = {
...BaseProps,
// Redux state
+searchText: string,
+searchStatus: SearchStatus,
+searchCancelButtonOpen: Value,
+chatThreadList: React.Node,
};

class ChatThreadList extends React.PureComponent<Props> {
flatList: ?FlatList<Item>;

constructor(props: Props) {
super(props);
}

render() {
return this.props.chatThreadList;
}

flatListRef = (flatList: ?FlatList<Item>) => {
this.flatList = flatList;
};
}

function ConnectedChatThreadList(props: BaseProps): React.Node {
function ChatThreadList(props: BaseProps): React.Node {
const boundChatListData = useFlattenedChatListData();
const loggedInUserInfo = useLoggedInUserInfo();
const threadSearchIndex = useGlobalThreadSearchIndex();
Expand Down Expand Up @@ -177,6 +153,7 @@ function ConnectedChatThreadList(props: BaseProps): React.Node {
);

const scrollPos = React.useRef(0);
const flatListRef = React.useRef();

const onScroll = React.useCallback(
(event: ScrollEvent) => {
Expand Down Expand Up @@ -221,7 +198,9 @@ function ConnectedChatThreadList(props: BaseProps): React.Node {
}, [searchStatus]);

const clearSearch = React.useCallback(() => {
// TODO (atul): Scroll to top of flatList (animated: false)
if (scrollPos.current > 0 && flatListRef.current) {
flatListRef.current.scrollToOffset({ offset: 0, animated: false });
}
setSearchStatus('inactive');
}, []);

Expand Down Expand Up @@ -441,7 +420,6 @@ function ConnectedChatThreadList(props: BaseProps): React.Node {
const viewerID = loggedInUserInfo?.id;
const extraData = `${viewerID || ''} ${openedSwipeableID}`;

const flatListRef = React.useRef();
const chatThreadList = React.useMemo(
() => (
<View style={styles.container}>
Expand Down Expand Up @@ -548,18 +526,7 @@ function ConnectedChatThreadList(props: BaseProps): React.Node {
}
}, [isSearchActivating]);
return (
<ChatThreadList
navigation={navigation}
route={route}
filterThreads={filterThreads}
emptyItem={emptyItem}
searchText={searchText}
searchStatus={searchStatus}
searchCancelButtonOpen={searchCancelButtonOpen}
chatThreadList={chatThreadList}
/>
);
return chatThreadList;
}
const unboundStyles = {
Expand Down Expand Up @@ -603,4 +570,4 @@ const unboundStyles = {
},
};

export default ConnectedChatThreadList;
export default ChatThreadList;

0 comments on commit abee4be

Please sign in to comment.