simplify managing crossteams (#8879)
This commit is contained in:
parent
22b4616f72
commit
975495eb92
2 changed files with 19 additions and 22 deletions
|
|
@ -1,12 +1,10 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import React, {useCallback, useMemo} from 'react';
|
||||
import {useIntl} from 'react-intl';
|
||||
import React, {useCallback} from 'react';
|
||||
import {StyleSheet, View} from 'react-native';
|
||||
|
||||
import TeamList from '@components/team_list';
|
||||
import {ALL_TEAMS_ID} from '@constants/team';
|
||||
import {useIsTablet} from '@hooks/device';
|
||||
import BottomSheetContent from '@screens/bottom_sheet/content';
|
||||
import {dismissBottomSheet} from '@screens/navigation';
|
||||
|
|
@ -28,7 +26,6 @@ const styles = StyleSheet.create({
|
|||
});
|
||||
|
||||
export default function BottomSheetTeamList({teams, title, setTeamId, teamId, crossTeamSearchEnabled}: Props) {
|
||||
const intl = useIntl();
|
||||
const isTablet = useIsTablet();
|
||||
const showTitle = !isTablet && Boolean(teams.length);
|
||||
|
||||
|
|
@ -37,14 +34,6 @@ export default function BottomSheetTeamList({teams, title, setTeamId, teamId, cr
|
|||
dismissBottomSheet();
|
||||
}, [setTeamId]);
|
||||
|
||||
const teamList = useMemo(() => {
|
||||
const list = [...teams];
|
||||
if (crossTeamSearchEnabled) {
|
||||
list.unshift({id: ALL_TEAMS_ID, displayName: intl.formatMessage({id: 'mobile.search.team.all_teams', defaultMessage: 'All teams'})} as TeamModel);
|
||||
}
|
||||
return list;
|
||||
}, [teams, crossTeamSearchEnabled, intl]);
|
||||
|
||||
return (
|
||||
<BottomSheetContent
|
||||
showButton={false}
|
||||
|
|
@ -55,7 +44,7 @@ export default function BottomSheetTeamList({teams, title, setTeamId, teamId, cr
|
|||
<View style={styles.container} >
|
||||
<TeamList
|
||||
selectedTeamId={teamId}
|
||||
teams={teamList}
|
||||
teams={teams}
|
||||
onPress={onPress}
|
||||
testID='search.select_team_slide_up.team_list'
|
||||
type={isTablet ? 'FlatList' : 'BottomSheetFlatList'}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import React, {useCallback} from 'react';
|
||||
import React, {useCallback, useMemo} from 'react';
|
||||
import {useIntl} from 'react-intl';
|
||||
import {Text, View} from 'react-native';
|
||||
|
||||
|
|
@ -52,11 +52,17 @@ const TeamPicker = ({setTeamId, teams, teamId, crossTeamSearchEnabled}: Props) =
|
|||
const intl = useIntl();
|
||||
const theme = useTheme();
|
||||
const styles = getStyleFromTheme(theme);
|
||||
const AllTeams: TeamModel = useMemo(() => ({id: ALL_TEAMS_ID, displayName: intl.formatMessage({id: 'mobile.search.team.all_teams', defaultMessage: 'All teams'})} as TeamModel), [intl]);
|
||||
|
||||
let selectedTeam = teams.find((t) => t.id === teamId);
|
||||
if (teamId === ALL_TEAMS_ID) {
|
||||
selectedTeam = {id: ALL_TEAMS_ID, displayName: intl.formatMessage({id: 'mobile.search.team.all_teams', defaultMessage: 'All teams'})} as TeamModel;
|
||||
}
|
||||
const teamList = useMemo(() => {
|
||||
const list = [...teams];
|
||||
if (crossTeamSearchEnabled) {
|
||||
list.unshift(AllTeams);
|
||||
}
|
||||
return list;
|
||||
}, [teams, crossTeamSearchEnabled, AllTeams]);
|
||||
|
||||
const selectedTeam = teamList.find((t) => t.id === teamId);
|
||||
|
||||
const title = intl.formatMessage({id: 'mobile.search.team.select', defaultMessage: 'Select a team to search'});
|
||||
|
||||
|
|
@ -65,7 +71,7 @@ const TeamPicker = ({setTeamId, teams, teamId, crossTeamSearchEnabled}: Props) =
|
|||
return (
|
||||
<BottomSheetTeamList
|
||||
setTeamId={setTeamId}
|
||||
teams={teams}
|
||||
teams={teamList}
|
||||
teamId={teamId}
|
||||
title={title}
|
||||
crossTeamSearchEnabled={crossTeamSearchEnabled}
|
||||
|
|
@ -75,10 +81,12 @@ const TeamPicker = ({setTeamId, teams, teamId, crossTeamSearchEnabled}: Props) =
|
|||
|
||||
const snapPoints: Array<string | number> = [
|
||||
1,
|
||||
teams.length ? bottomSheetSnapPoint(Math.min(3, teams.length), ITEM_HEIGHT) + (2 * TITLE_HEIGHT) : NO_TEAMS_HEIGHT,
|
||||
|
||||
// use teams to check if teams is empty
|
||||
teams.length ? bottomSheetSnapPoint(Math.min(3, teamList.length), ITEM_HEIGHT) + (2 * TITLE_HEIGHT) : NO_TEAMS_HEIGHT,
|
||||
];
|
||||
|
||||
if (teams.length > 3) {
|
||||
if (teamList.length > 3) {
|
||||
snapPoints.push('80%');
|
||||
}
|
||||
|
||||
|
|
@ -89,7 +97,7 @@ const TeamPicker = ({setTeamId, teams, teamId, crossTeamSearchEnabled}: Props) =
|
|||
theme,
|
||||
title,
|
||||
});
|
||||
}, [teams, theme, title, setTeamId, teamId, crossTeamSearchEnabled]));
|
||||
}, [teams, teamList, theme, title, setTeamId, teamId, crossTeamSearchEnabled]));
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
|||
Loading…
Reference in a new issue