From 24b8abb3d1b99917e23cfa6d5b716805c9da755c Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Mon, 18 Jul 2022 12:32:49 +0800 Subject: [PATCH] feat: show diff in text --- src/components/FileExplorer/DiffStatText.tsx | 31 +++++++------------ .../FileExplorer/hooks/useNodeRenderers.tsx | 28 ++++++++++------- src/components/settings/FileTreeSettings.tsx | 7 +++++ src/styles/index.scss | 16 +++++----- src/utils/config/helper.ts | 3 ++ 5 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/components/FileExplorer/DiffStatText.tsx b/src/components/FileExplorer/DiffStatText.tsx index bcf5e39..caa60d0 100644 --- a/src/components/FileExplorer/DiffStatText.tsx +++ b/src/components/FileExplorer/DiffStatText.tsx @@ -1,6 +1,14 @@ import * as React from 'react' import { Icon } from '../Icon' +const iconMap = { + added: 'diffAdded', + ignored: 'diffIgnored', + modified: 'diffModified', + removed: 'diffRemoved', + renamed: 'diffRenamed', +} + export function DiffStatText({ diff: { status, additions, deletions }, }: { @@ -8,27 +16,10 @@ export function DiffStatText({ }) { return ( - {status !== 'modified' && ( - - )} - {additions > 0 && ( - {status === 'modified' ? `+${additions}` : additions} - )} + + {additions > 0 && {additions}} {additions > 0 && deletions > 0 && '/'} - {deletions > 0 && ( - {status === 'modified' ? `-${deletions}` : deletions} - )} + {deletions > 0 && {deletions}} ) } diff --git a/src/components/FileExplorer/hooks/useNodeRenderers.tsx b/src/components/FileExplorer/hooks/useNodeRenderers.tsx index 53db57c..118fc57 100644 --- a/src/components/FileExplorer/hooks/useNodeRenderers.tsx +++ b/src/components/FileExplorer/hooks/useNodeRenderers.tsx @@ -4,6 +4,7 @@ import * as React from 'react' import { is } from 'utils/is' import { Icon } from '../../Icon' import { SearchMode } from '../../searchModes' +import { DiffStatText } from '../DiffStatText' import { DiffStatGraph } from './../DiffStatGraph' export type NodeRenderer = (node: TreeNode) => React.ReactNode @@ -19,19 +20,22 @@ export function useNodeRenderers(allRenderers: (NodeRenderer | null | undefined) } export function useRenderFileStatus() { - function renderFileStatus({ diff }: TreeNode) { - return ( - diff && ( - - - + const { showDiffInText } = useConfigs().value + return React.useCallback( + function renderFileStatus({ diff }: TreeNode) { + return ( + diff && ( + + {showDiffInText ? : } + + ) ) - ) - } - return React.useMemo(() => renderFileStatus, []) + }, + [showDiffInText], + ) } export function useRenderFileCommentAmounts() { diff --git a/src/components/settings/FileTreeSettings.tsx b/src/components/settings/FileTreeSettings.tsx index 24da05d..bf5de99 100644 --- a/src/components/settings/FileTreeSettings.tsx +++ b/src/components/settings/FileTreeSettings.tsx @@ -76,6 +76,13 @@ export function FileTreeSettings() { tooltip: 'Show number of comments next to file names in Pull Requests.', }} /> + Config = () => ({ compactFileTree: false, restoreExpandedFolders: true, pjaxMode: platformName === 'GitHub' ? 'native' : 'pjax-api', // use native on GitHub + showDiffInText: false, }) const configKeyArray = Object.values(configKeys)