Update types and onCancelSearchPress

This commit is contained in:
Gerzon Z 2021-10-13 17:09:50 -04:00
parent 086d13b4ef
commit 35d869df85
2 changed files with 14 additions and 14 deletions

View File

@ -12,7 +12,7 @@ interface IThemeContextProps {
export const ThemeContext = React.createContext<Partial<IThemeContextProps>>({ theme: 'light' }); export const ThemeContext = React.createContext<Partial<IThemeContextProps>>({ theme: 'light' });
export function withTheme(Component: any) { export function withTheme(Component: React.ComponentType<any>): (props: any) => JSX.Element {
const ThemedComponent = (props: any) => ( const ThemedComponent = (props: any) => (
<ThemeContext.Consumer>{contexts => <Component {...props} {...contexts} />}</ThemeContext.Consumer> <ThemeContext.Consumer>{contexts => <Component {...props} {...contexts} />}</ThemeContext.Consumer>
); );
@ -20,4 +20,4 @@ export function withTheme(Component: any) {
return ThemedComponent; return ThemedComponent;
} }
export const useTheme = () => React.useContext(ThemeContext); export const useTheme = (): Partial<IThemeContextProps> => React.useContext(ThemeContext);

View File

@ -2,7 +2,8 @@ import React, { useEffect, useState } from 'react';
import { FlatList } from 'react-native'; import { FlatList } from 'react-native';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { HeaderBackButton } from '@react-navigation/stack'; import { HeaderBackButton, StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack';
import { RouteProp } from '@react-navigation/core';
import ActivityIndicator from '../../containers/ActivityIndicator'; import ActivityIndicator from '../../containers/ActivityIndicator';
import I18n from '../../i18n'; import I18n from '../../i18n';
@ -25,12 +26,8 @@ import styles from './styles';
const API_FETCH_COUNT = 50; const API_FETCH_COUNT = 50;
interface IDiscussionsViewProps { interface IDiscussionsViewProps {
navigation: any; navigation: StackNavigationProp<any, 'DiscussionsView'>;
route: { route: RouteProp<any, 'DiscussionsView'>;
params?: {
rid: string;
};
};
item: { item: {
msg: string; msg: string;
}; };
@ -108,7 +105,8 @@ const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Elem
const onCancelSearchPress = () => { const onCancelSearchPress = () => {
setIsSearching(false); setIsSearching(false);
load(); setSearch([]);
setSearchTotal(0);
}; };
const onSearchPress = () => { const onSearchPress = () => {
@ -116,9 +114,10 @@ const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Elem
}; };
const setHeader = () => { const setHeader = () => {
let options: Partial<StackNavigationOptions>;
if (isSearching) { if (isSearching) {
const headerTitlePosition = getHeaderTitlePosition({ insets, numIconsRight: 1 }); const headerTitlePosition = getHeaderTitlePosition({ insets, numIconsRight: 1 });
return { options = {
headerTitleAlign: 'left', headerTitleAlign: 'left',
headerLeft: () => ( headerLeft: () => (
<HeaderButton.Container left> <HeaderButton.Container left>
@ -139,11 +138,12 @@ const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Elem
}, },
headerRight: () => null headerRight: () => null
}; };
return options;
} }
const options = { options = {
headerLeft: () => ( headerLeft: () => (
<HeaderBackButton labelVisible={false} onPress={() => navigation.pop()} tintColor={themes[theme!].headerTintColor} /> <HeaderBackButton labelVisible={false} onPress={() => navigation.pop()} tintColor={themes[theme].headerTintColor} />
), ),
headerTitleAlign: 'center', headerTitleAlign: 'center',
headerTitle: I18n.t('Discussions'), headerTitle: I18n.t('Discussions'),
@ -211,7 +211,7 @@ const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Elem
data={isSearching ? search : discussions} data={isSearching ? search : discussions}
renderItem={renderItem} renderItem={renderItem}
keyExtractor={(item: any) => item.msg} keyExtractor={(item: any) => item.msg}
style={{ backgroundColor: themes[theme!].backgroundColor }} style={{ backgroundColor: themes[theme].backgroundColor }}
contentContainerStyle={styles.contentContainer} contentContainerStyle={styles.contentContainer}
onEndReachedThreshold={0.5} onEndReachedThreshold={0.5}
maxToRenderPerBatch={5} maxToRenderPerBatch={5}