From 52d0fed437c7eb4bd3839e014fb4b4c5f3c5b08e Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Sun, 25 Dec 2022 00:02:36 +0530 Subject: [PATCH] refactor(dev-only): add animation to file view search box and fix search bar on mobile --- .../ContentListView/ContentListView.tsx | 8 ++- .../Header/ContentListHeader.tsx | 3 +- .../ContentListView/Header/SearchButton.tsx | 50 +++++++++++-------- .../Components/SearchBar/SearchBar.tsx | 5 +- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/packages/web/src/javascripts/Components/ContentListView/ContentListView.tsx b/packages/web/src/javascripts/Components/ContentListView/ContentListView.tsx index b2cf340fb..a60ec2a13 100644 --- a/packages/web/src/javascripts/Components/ContentListView/ContentListView.tsx +++ b/packages/web/src/javascripts/Components/ContentListView/ContentListView.tsx @@ -315,8 +315,12 @@ const ContentListView = forwardRef( itemListController={itemListController} /> )} - {!isFilesTableViewEnabled && ( - + {(!isFilesTableViewEnabled || isMobileScreen()) && ( + )} { - if (!isFilesSmartView || !isFilesTableViewEnabled) { + if (!isFilesSmartView || !isFilesTableViewEnabled || isMobileScreen()) { return null } diff --git a/packages/web/src/javascripts/Components/ContentListView/Header/SearchButton.tsx b/packages/web/src/javascripts/Components/ContentListView/Header/SearchButton.tsx index e2ac07fb0..b47a5f236 100644 --- a/packages/web/src/javascripts/Components/ContentListView/Header/SearchButton.tsx +++ b/packages/web/src/javascripts/Components/ContentListView/Header/SearchButton.tsx @@ -4,42 +4,48 @@ import Icon from '@/Components/Icon/Icon' import DecoratedInput from '@/Components/Input/DecoratedInput' import { ElementIds } from '@/Constants/ElementIDs' import { ItemListController } from '@/Controllers/ItemList/ItemListController' +import { classNames } from '@standardnotes/snjs' import { observer } from 'mobx-react-lite' -import { useState } from 'react' +import { useRef, useState } from 'react' type Props = { itemListController: ItemListController } const SearchButton = ({ itemListController }: Props) => { + const searchButtonRef = useRef(null) + const { noteFilterText, setNoteFilterText, clearFilterText } = itemListController const [isSearchBarVisible, setIsSearchBarVisible] = useState(false) return ( <> - {isSearchBarVisible && ( - { - if (node && document.activeElement !== node) { - node.focus() - } - }} - onChange={(query) => setNoteFilterText(query)} - left={[]} - right={[noteFilterText && ]} - roundedFull - /> - )} + { + if (node && document.activeElement !== node) { + node.focus() + } + }} + onChange={(query) => setNoteFilterText(query)} + left={[]} + right={[noteFilterText && ]} + roundedFull + /> { setIsSearchBarVisible(!isSearchBarVisible) }} diff --git a/packages/web/src/javascripts/Components/SearchBar/SearchBar.tsx b/packages/web/src/javascripts/Components/SearchBar/SearchBar.tsx index b48df9151..a5a12372e 100644 --- a/packages/web/src/javascripts/Components/SearchBar/SearchBar.tsx +++ b/packages/web/src/javascripts/Components/SearchBar/SearchBar.tsx @@ -12,9 +12,10 @@ import { ElementIds } from '@/Constants/ElementIDs' type Props = { itemListController: ItemListController searchOptionsController: SearchOptionsController + hideOptions?: boolean } -const SearchBar = ({ itemListController, searchOptionsController }: Props) => { +const SearchBar = ({ itemListController, searchOptionsController, hideOptions = false }: Props) => { const searchInputRef = useRef(null) const { noteFilterText, setNoteFilterText, clearFilterText, onFilterEnter } = itemListController @@ -66,7 +67,7 @@ const SearchBar = ({ itemListController, searchOptionsController }: Props) => { roundedFull /> - {(focusedSearch || noteFilterText) && ( + {(focusedSearch || noteFilterText) && !hideOptions && (