fix: visible nodes are not always available

This commit is contained in:
EnixCoda 2019-02-23 21:13:06 +08:00
parent 76c7c25990
commit dff92bde6c
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD
2 changed files with 9 additions and 3 deletions

View file

@ -24,6 +24,7 @@ class FileExplorer extends React.Component<Props & ConnectorState> {
freeze: false,
searchKey: '',
searched: false,
visibleNodes: null,
}
componentWillMount() {

View file

@ -12,7 +12,7 @@ import { raiseError } from 'analytics'
export type ConnectorState = {
stateText: string
visibleNodes: VisibleNodes
visibleNodes: VisibleNodes | null
searchKey: string
searched: boolean
@ -141,7 +141,9 @@ const handleKeyDown: MethodCreator<
ConnectorState,
[React.KeyboardEvent]
> = dispatch => event =>
dispatch.get(({ searched, visibleNodes: { nodes, focusedNode, expandedNodes, depths } }) => {
dispatch.get(({ searched, visibleNodes }) => {
if (!visibleNodes) return
const { nodes, focusedNode, expandedNodes, depths } = visibleNodes
function handleVerticalMove(index: number) {
if (0 <= index && index < nodes.length) {
DOMHelper.focusFileExplorer()
@ -325,7 +327,9 @@ const focusNode: MethodCreator<Props, ConnectorState, [TreeNode | null, boolean]
node: TreeNode | null,
skipScroll = false,
) =>
dispatch.get(({ visibleNodes: { nodes } }) => {
dispatch.get(({ visibleNodes }) => {
if (!visibleNodes) return
const { nodes } = visibleNodes
visibleNodesGenerator.focusNode(node)
if (node && !skipScroll) {
// when focus a node not in viewport(by keyboard), scroll to it
@ -354,6 +358,7 @@ const mountExpandingIndicator: MethodCreator<
[TreeNode]
> = dispatch => node =>
dispatch.get(({ visibleNodes }) => {
if (!visibleNodes) return
const dummyVisibleNodes = {
...visibleNodes,
nodes: visibleNodes.nodes.slice(),