feat: remove expanding indicator

This commit is contained in:
EnixCoda 2019-08-11 14:29:36 +08:00
parent b757fa1fd9
commit f768935330
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD
3 changed files with 3 additions and 63 deletions

View file

@ -1,7 +1,6 @@
import * as React from 'react'
import Icon from 'components/Icon'
import cx from 'utils/cx'
import LoadingIndicator from 'components/LoadingIndicator'
import { TreeNode } from 'utils/VisibleNodesGenerator'
import { os, OperatingSystems } from 'utils/general'
@ -41,18 +40,7 @@ export default class Node extends React.PureComponent<Props> {
render() {
const { node, depth, expanded, focused, renderActions, style } = this.props
const { name, path, virtual } = node
if (virtual) {
// this is not a real node
// for now, all virtual nodes are indicators for pending state
return (
<div className={cx(`node-item-row`, { focused })} style={style}>
<div className={'node-item'}>
<LoadingIndicator text={name} />
</div>
</div>
)
}
const { name, path } = node
return (
<div
className={cx(`node-item-row`, { focused, disabled: node.accessDenied })}

View file

@ -305,8 +305,6 @@ const search: MethodCreator<Props, ConnectorState, [string]> = dispatch => {
}
}
const delayExpandThreshold = 400
const goTo: MethodCreator<Props, ConnectorState, [string[]]> = dispatch => async currentPath => {
await visibleNodesGenerator.search('')
dispatch.set({ searchKey: '', searched: false })
@ -319,26 +317,12 @@ const goTo: MethodCreator<Props, ConnectorState, [string[]]> = dispatch => async
dispatch.call(updateVisibleNodes)
}
function shouldDelayExpand(node: TreeNode) {
return (
visibleNodesGenerator.visibleNodes.expandedNodes.has(node) &&
Array.isArray(node.contents) &&
node.contents.length > delayExpandThreshold
)
}
const setExpand: MethodCreator<Props, ConnectorState, [TreeNode, boolean]> = dispatch => (
node,
expand = false,
) => {
visibleNodesGenerator.setExpand(node, expand)
const applyChanges = () => dispatch.call(focusNode, node, false)
if (shouldDelayExpand(node)) {
dispatch.call(mountExpandingIndicator, node)
tasksAfterRender.push(() => setTimeout(applyChanges, 0))
} else {
applyChanges()
}
dispatch.call(focusNode, node, false)
}
const toggleNodeExpansion: MethodCreator<Props, ConnectorState, [TreeNode, boolean]> = dispatch => (
@ -346,16 +330,8 @@ const toggleNodeExpansion: MethodCreator<Props, ConnectorState, [TreeNode, boole
skipScrollToNode,
) => {
visibleNodesGenerator.toggleExpand(node)
const applyChanges = () => {
dispatch.call(focusNode, node, skipScrollToNode)
tasksAfterRender.push(DOMHelper.focusFileExplorer)
}
if (shouldDelayExpand(node)) {
dispatch.call(mountExpandingIndicator, node)
tasksAfterRender.push(() => setTimeout(applyChanges, 0))
} else {
applyChanges()
}
}
const focusNode: MethodCreator<Props, ConnectorState, [TreeNode | null, boolean]> = dispatch => (
@ -387,28 +363,6 @@ const onNodeClick: MethodCreator<Props, ConnectorState, [TreeNode]> = dispatch =
}
}
const mountExpandingIndicator: MethodCreator<
Props,
ConnectorState,
[TreeNode]
> = dispatch => node =>
dispatch.get(({ visibleNodes }) => {
if (!visibleNodes) return
const dummyVisibleNodes = {
...visibleNodes,
nodes: visibleNodes.nodes.slice(),
}
dummyVisibleNodes.nodes.splice(dummyVisibleNodes.nodes.indexOf(node) + 1, 0, {
virtual: true,
name: 'Loading',
path: '-',
type: 'virtual',
})
dispatch.set({
visibleNodes: dummyVisibleNodes,
})
})
const updateVisibleNodes: MethodCreator<Props, ConnectorState> = dispatch => () => {
const { visibleNodes } = visibleNodesGenerator
dispatch.set({ visibleNodes })
@ -429,5 +383,4 @@ export default {
focusNode,
onNodeClick,
updateVisibleNodes,
mountExpandingIndicator,
}

View file

@ -27,8 +27,7 @@ export type TreeNode = {
path: string
url?: string
sha?: string
virtual?: boolean
type: 'tree' | 'blob' | 'commit' | 'virtual'
type: 'tree' | 'blob' | 'commit'
accessDenied?: boolean
}