From 0da52bee9eef0c88ea2663d531879d421782b653 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Wed, 15 Apr 2020 21:33:15 +0800 Subject: [PATCH] chore: minor fixes --- src/components/FileExplorer.tsx | 27 ++++++++++++++++----------- src/content.scss | 1 + src/driver/core/FileExplorer.ts | 18 +++++------------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/components/FileExplorer.tsx b/src/components/FileExplorer.tsx index b030096..eea76a8 100644 --- a/src/components/FileExplorer.tsx +++ b/src/components/FileExplorer.tsx @@ -20,9 +20,9 @@ import { SizeObserver } from './SizeObserver' const VisibleNodesContext = React.createContext(null) const RawFileExplorer: React.FC = function RawFileExplorer(props) { - const { visibleNodes, freeze, onNodeClick, searchKey } = props + const { state, visibleNodes, freeze, onNodeClick, searchKey } = props const { - val: { access_token: accessToken, compressSingletonFolder }, + val: { compressSingletonFolder }, } = useConfigs() React.useEffect(() => { @@ -32,8 +32,8 @@ const RawFileExplorer: React.FC = function RawFileExplor React.useEffect(() => { const { setUpTree, treeRoot, metaData } = props - setUpTree({ treeRoot, metaData, compressSingletonFolder, accessToken }) - }, [props.setUpTree, props.treeRoot, compressSingletonFolder, accessToken]) + setUpTree({ treeRoot, metaData, compressSingletonFolder }) + }, [props.setUpTree, props.treeRoot, compressSingletonFolder]) React.useEffect(() => { const { execAfterRender } = props @@ -69,8 +69,7 @@ const RawFileExplorer: React.FC = function RawFileExplor [renderActions, onNodeClick, searchKey], ) - const renderFiles = React.useCallback( - ({ nodes, focusedNode }: VisibleNodes) => { + function renderFiles({ nodes, focusedNode }: VisibleNodes) { const inSearch = searchKey !== '' if (inSearch && nodes.length === 0) { return ( @@ -94,9 +93,7 @@ const RawFileExplorer: React.FC = function RawFileExplor )} ) - }, - [searchKey, ListView, renderNode], - ) + } const revealNode = React.useCallback(function revealNode( goTo: (path: string[]) => void, @@ -118,8 +115,15 @@ const RawFileExplorer: React.FC = function RawFileExplor onKeyDown={props.handleKeyDown} onClick={freeze ? props.toggleShowSettings : undefined} > - {props.stateText ? ( - + {state !== 'done' ? ( + ) : ( visibleNodes && ( <> @@ -139,6 +143,7 @@ const RawFileExplorer: React.FC = function RawFileExplor RawFileExplorer.defaultProps = { freeze: false, + state: 'pulling', searchKey: '', visibleNodes: null, } diff --git a/src/content.scss b/src/content.scss index d738f2c..305ba49 100644 --- a/src/content.scss +++ b/src/content.scss @@ -290,6 +290,7 @@ $minimal-z-index: max($github-header-z-index, $github-pull-request-float-header- &-icon { width: 20px; height: 20px; + margin-right: 2px; .octicon { width: 20px; diff --git a/src/driver/core/FileExplorer.ts b/src/driver/core/FileExplorer.ts index 11578b5..307e96e 100644 --- a/src/driver/core/FileExplorer.ts +++ b/src/driver/core/FileExplorer.ts @@ -15,7 +15,7 @@ export type Props = { } export type ConnectorState = { - stateText: string + state: 'pulling' | 'rendering' | 'done' visibleNodes: VisibleNodes | null searchKey: string searched: boolean // derived state from searchKey, = !!searchKey @@ -57,14 +57,13 @@ let visibleNodesGenerator: VisibleNodesGenerator type BoundMethodCreator = MethodCreator -export const init: BoundMethodCreator = dispatch => () => - dispatch.call(setStateText, 'Fetching File List...') +export const init: BoundMethodCreator = dispatch => () => dispatch.set({ state: 'pulling' }) export const setUpTree: BoundMethodCreator<[ - Pick & Pick, + Pick & Pick, ]> = dispatch => async ({ treeRoot, metaData, compressSingletonFolder }) => { if (!treeRoot) return - dispatch.call(setStateText, 'Rendering File List...') + dispatch.set({ state: 'rendering' }) visibleNodesGenerator = new VisibleNodesGenerator(treeRoot, { compress: compressSingletonFolder, @@ -73,7 +72,7 @@ export const setUpTree: BoundMethodCreator<[ visibleNodesGenerator.init() tasksAfterRender.push(DOMHelper.focusSearchInput) - dispatch.call(setStateText, '') + dispatch.set({ state: 'done' }) const targetPath = platform.getCurrentPath(metaData.branchName) if (targetPath) dispatch.call(goTo, targetPath) } @@ -85,13 +84,6 @@ export const execAfterRender: BoundMethodCreator = dispatch => () => { tasksAfterRender.length = 0 } -export const setStateText: BoundMethodCreator<[ConnectorState['stateText']]> = dispatch => ( - text: string, -) => - dispatch.set({ - stateText: text, - }) - export const handleKeyDown: BoundMethodCreator<[React.KeyboardEvent]> = dispatch => event => { const [{ searched, visibleNodes }, { loadWithPJAX }] = dispatch.get() if (!visibleNodes) return