-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Search] Selection Mode for small screens #44820
Changes from 6 commits
4832073
57ed2ba
0aecf72
3b3b2b7
d3a7f9e
6cf4194
362a9c3
3a7d32d
9eddb40
789ad91
b51eaec
212ddc1
6899d60
29fc205
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React, {useCallback} from 'react'; | ||
import React, {useMemo} from 'react'; | ||
import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu'; | ||
import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
|
@@ -10,6 +10,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; | |
import useTheme from '@hooks/useTheme'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as SearchActions from '@libs/actions/Search'; | ||
import SearchSelectedNarrow from '@pages/Search/SearchSelectedNarrow'; | ||
import variables from '@styles/variables'; | ||
import CONST from '@src/CONST'; | ||
import type {SearchQuery} from '@src/types/onyx/SearchResults'; | ||
|
@@ -22,11 +23,12 @@ type SearchHeaderProps = { | |
selectedItems?: SelectedTransactions; | ||
clearSelectedItems?: () => void; | ||
hash: number; | ||
isMobileSelectionModeActive?: boolean; | ||
}; | ||
|
||
type SearchHeaderOptionValue = DeepValueOf<typeof CONST.SEARCH.BULK_ACTION_TYPES> | undefined; | ||
|
||
function SearchPageHeader({query, selectedItems = {}, hash, clearSelectedItems}: SearchHeaderProps) { | ||
function SearchPageHeader({query, selectedItems = {}, hash, clearSelectedItems, isMobileSelectionModeActive}: SearchHeaderProps) { | ||
const {translate} = useLocalize(); | ||
const theme = useTheme(); | ||
const styles = useThemeStyles(); | ||
|
@@ -39,12 +41,13 @@ function SearchPageHeader({query, selectedItems = {}, hash, clearSelectedItems}: | |
finished: {icon: Illustrations.CheckmarkCircle, title: translate('common.finished')}, | ||
}; | ||
|
||
const getHeaderButtons = useCallback(() => { | ||
const selectedItemsKeys = Object.keys(selectedItems ?? []); | ||
|
||
const headerButtonsOptions = useMemo(() => { | ||
const options: Array<DropdownOption<SearchHeaderOptionValue>> = []; | ||
const selectedItemsKeys = Object.keys(selectedItems ?? []); | ||
|
||
if (selectedItemsKeys.length === 0) { | ||
return null; | ||
return options; | ||
} | ||
|
||
const itemsToDelete = selectedItemsKeys.filter((id) => selectedItems[id].canDelete); | ||
|
@@ -107,21 +110,18 @@ function SearchPageHeader({query, selectedItems = {}, hash, clearSelectedItems}: | |
}); | ||
} | ||
|
||
return ( | ||
<ButtonWithDropdownMenu | ||
onPress={() => null} | ||
shouldAlwaysShowDropdownMenu | ||
pressOnEnter | ||
buttonSize={CONST.DROPDOWN_BUTTON_SIZE.MEDIUM} | ||
customText={translate('workspace.common.selected', {selectedNumber: selectedItemsKeys.length})} | ||
options={options} | ||
isSplitButton={false} | ||
isDisabled={isOffline} | ||
/> | ||
); | ||
}, [clearSelectedItems, hash, isOffline, selectedItems, styles.colorMuted, styles.fontWeightNormal, theme.icon, translate]); | ||
return options; | ||
}, [clearSelectedItems, hash, selectedItems, selectedItemsKeys, styles, theme, translate]); | ||
|
||
if (isSmallScreenWidth) { | ||
if (isMobileSelectionModeActive) { | ||
return ( | ||
<SearchSelectedNarrow | ||
options={headerButtonsOptions} | ||
itemsLength={selectedItemsKeys.length} | ||
rlinoz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/> | ||
); | ||
} | ||
return null; | ||
} | ||
|
||
|
@@ -131,11 +131,23 @@ function SearchPageHeader({query, selectedItems = {}, hash, clearSelectedItems}: | |
icon={headerContent[query]?.icon} | ||
shouldShowBackButton={false} | ||
> | ||
{getHeaderButtons()} | ||
{headerButtonsOptions.length > 0 && ( | ||
<ButtonWithDropdownMenu | ||
onPress={() => null} | ||
shouldAlwaysShowDropdownMenu | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is that correct? that is just the action on pressing the main button that would display the list, and each option has their own onPress? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. onPress function fires only when we pass |
||
pressOnEnter | ||
buttonSize={CONST.DROPDOWN_BUTTON_SIZE.MEDIUM} | ||
customText={translate('workspace.common.selected', {selectedNumber: selectedItemsKeys.length})} | ||
options={headerButtonsOptions} | ||
isSplitButton={false} | ||
isDisabled={isOffline} | ||
/> | ||
)} | ||
</HeaderWithBackButton> | ||
); | ||
} | ||
|
||
SearchPageHeader.displayName = 'SearchPageHeader'; | ||
|
||
export type {SearchHeaderOptionValue}; | ||
export default SearchPageHeader; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know its a minor thing and NAB
but a bool prop to me should be named using a pattern like:
isContentCentered
/shouldCenterContent
.If I just see the name
centeredContent
then I would presume there is some content inside this property (like a piece of JSX or icon or something...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, renamed