From 3c6e465380b300eb44dfe40f351b2900012a4132 Mon Sep 17 00:00:00 2001 From: Mateusz Titz Date: Wed, 4 Sep 2024 12:49:54 +0200 Subject: [PATCH] Add basic code skeleton for new Search Router PoC --- src/CONST.ts | 1 - src/components/Search/SearchRouter.tsx | 99 +++++++++++++++++++ .../Search/SearchRouter/SearchRouterInput.tsx | 50 ++++++++++ .../createCustomBottomTabNavigator/TopBar.tsx | 3 + .../utils/generators/ModalStyleUtils.ts | 3 +- 5 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 src/components/Search/SearchRouter.tsx create mode 100644 src/components/Search/SearchRouter/SearchRouterInput.tsx diff --git a/src/CONST.ts b/src/CONST.ts index 5f3fe783f1ac..63f74b7b3943 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -964,7 +964,6 @@ const CONST = { BOTTOM_DOCKED: 'bottom_docked', POPOVER: 'popover', RIGHT_DOCKED: 'right_docked', - ONBOARDING: 'onboarding', }, ANCHOR_ORIGIN_VERTICAL: { TOP: 'top', diff --git a/src/components/Search/SearchRouter.tsx b/src/components/Search/SearchRouter.tsx new file mode 100644 index 000000000000..ff0845fdc292 --- /dev/null +++ b/src/components/Search/SearchRouter.tsx @@ -0,0 +1,99 @@ +import React, {useState} from 'react'; +import {View} from 'react-native'; +import Button from '@components/Button'; +import * as Expensicons from '@components/Icon/Expensicons'; +import Modal from '@components/Modal'; +import SelectionList from '@components/SelectionList'; +import TableListItem from '@components/SelectionList/TableListItem'; +import useLocalize from '@hooks/useLocalize'; +import useResponsiveLayout from '@hooks/useResponsiveLayout'; +import useThemeStyles from '@hooks/useThemeStyles'; +import Navigation from '@libs/Navigation/Navigation'; +import * as SearchUtils from '@libs/SearchUtils'; +import CONST from '@src/CONST'; +import ROUTES from '@src/ROUTES'; +import type {SearchDataTypes} from '@src/types/onyx/SearchResults'; +import SearchRouterInput from './SearchRouter/SearchRouterInput'; +import type {SearchQueryJSON} from './types'; + +type SearchRouterProps = { + type?: SearchDataTypes; +}; + +function SearchRouter({type}: SearchRouterProps) { + const styles = useThemeStyles(); + const {translate} = useLocalize(); + const {isSmallScreenWidth} = useResponsiveLayout(); + + const [isDisplayed, setIsDisplayed] = useState(false); + const [currentQuery, setCurrentQuery] = useState(undefined); + + const modalType = isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE : CONST.MODAL.MODAL_TYPE.POPOVER; + const fullscreen = true; + + const onSearch = (userQuery: string) => { + if (userQuery.length < 3) { + return; + } + + const query = type ? `type:${type} ${userQuery}` : userQuery; + const queryJSON = SearchUtils.buildSearchQueryJSON(query); + + if (queryJSON) { + setCurrentQuery(queryJSON); + } + }; + + const sectionData = currentQuery + ? [ + { + text: `Search for: ${currentQuery.inputQuery}`, + }, + ] + : []; + + return ( + <> +