fix: prevent unnecessary unmount

This commit is contained in:
EnixCoda 2020-10-27 01:58:12 +08:00
parent 5f9af7dd7f
commit 391c3e457c
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD
2 changed files with 18 additions and 30 deletions

View file

@ -62,34 +62,6 @@ const RawFileExplorer: React.FC<Props & ConnectorState> = function RawFileExplor
[visibleNodes, goTo],
)
function renderFiles(visibleNodes: VisibleNodes) {
const { nodes } = visibleNodes
const searchKey = visibleNodes.lastMatch?.match.searchKey
const inSearch = searchKey !== ''
if (inSearch && nodes.length === 0) {
return (
<Text marginTop={6} textAlign="center" color="text.gray">
No results found.
</Text>
)
}
return (
<SizeObserver className={'files'}>
{({ width = 0, height = 0 }) => (
<ListView
height={height}
width={width}
onNodeClick={onNodeClick}
renderActions={renderActions}
visibleNodes={visibleNodes}
expandTo={expandTo}
metaData={metaData}
/>
)}
</SizeObserver>
)
}
return (
<div
className={cx(`file-explorer`, { freeze })}
@ -114,7 +86,24 @@ const RawFileExplorer: React.FC<Props & ConnectorState> = function RawFileExplor
onSearch={props.search}
onFocus={props.onFocusSearchBar}
/>
{renderFiles(visibleNodes)}
{visibleNodes.lastMatch?.match.searchKey !== '' && visibleNodes.nodes.length === 0 && (
<Text marginTop={6} textAlign="center" color="text.gray">
No results found.
</Text>
)}
<SizeObserver className={'files'}>
{({ width = 0, height = 0 }) => (
<ListView
height={height}
width={width}
onNodeClick={onNodeClick}
renderActions={renderActions}
visibleNodes={visibleNodes}
expandTo={expandTo}
metaData={metaData}
/>
)}
</SizeObserver>
</>
)
)}

View file

@ -304,7 +304,6 @@ class FlattenLayer extends CompressLayer {
searchKey: string
} | null,
) => {
// this.focusNode(null)
this.shake(
match
? {