Fix search resetting (#508)

This commit is contained in:
Hossein 2021-06-04 07:28:33 -04:00 committed by GitHub
parent 68d492a855
commit b45c1e7fd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 8 deletions

View File

@ -14,21 +14,17 @@ type Props = {
}
const ViewHeaderSearch = (props: Props) => {
const {boardTree} = props
const {boardTree, setSearchText} = props
const intl = useIntl()
const searchFieldRef = useRef<{focus(selectAll?: boolean): void}>(null)
const [isSearching, setIsSearching] = useState(Boolean(props.boardTree.getSearchText()))
const [isSearching, setIsSearching] = useState(Boolean(boardTree.getSearchText()))
const [searchValue, setSearchValue] = useState(boardTree.getSearchText())
useEffect(() => {
searchFieldRef.current?.focus()
}, [isSearching])
useEffect(() => {
setSearchValue(boardTree.getSearchText())
}, [boardTree])
useHotkeys('ctrl+shift+f,cmd+shift+f', () => {
setIsSearching(true)
searchFieldRef.current?.focus(true)
@ -44,13 +40,13 @@ const ViewHeaderSearch = (props: Props) => {
onCancel={() => {
setSearchValue('')
setIsSearching(false)
props.setSearchText('')
setSearchText('')
}}
onSave={() => {
if (searchValue === '') {
setIsSearching(false)
}
props.setSearchText(searchValue)
setSearchText(searchValue)
}}
/>
)

View File

@ -77,6 +77,7 @@ class MutableBoardTree implements BoardTree {
}
const rawBlocks = OctoUtils.mergeBlocks(boardTree.allBlocks, relevantBlocks)
const newBoardTree = this.buildTree(boardTree.board.id, rawBlocks)
newBoardTree?.setSearchText(boardTree.getSearchText())
if (newBoardTree && boardTree.activeView) {
newBoardTree.setActiveView(boardTree.activeView.id)
}