mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat: settings for icons
This commit is contained in:
parent
eab2790d03
commit
b5d9275e63
4 changed files with 78 additions and 10 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { useConfigs } from 'containers/ConfigsContext'
|
||||
import * as React from 'react'
|
||||
import { cx } from 'utils/cx'
|
||||
import { OperatingSystems, os } from 'utils/general'
|
||||
|
|
@ -72,14 +73,23 @@ const NodeItemIcon = React.memo(function NodeItemIcon({
|
|||
node: TreeNode
|
||||
open?: boolean
|
||||
}) {
|
||||
const {
|
||||
val: { icons },
|
||||
} = useConfigs()
|
||||
|
||||
if (icons === 'native') return <Icon type={getIconType(node)} />
|
||||
const src = React.useMemo(
|
||||
() => (node.type === 'tree' ? getFolderIconSrc(node, open) : getFileIconSrc(node)),
|
||||
[open],
|
||||
)
|
||||
return (
|
||||
<>
|
||||
<Icon placeholder={node.type === 'blob'} type={getIconType(node)} />
|
||||
{node.type !== 'commit' && <img alt={node.name} className={'node-item-icon'} src={src} />}
|
||||
<Icon placeholder={node.type !== 'tree'} type={getIconType(node)} />
|
||||
{node.type === 'commit' ? (
|
||||
<Icon type={getIconType(node)} />
|
||||
) : (
|
||||
<img alt={node.name} className={cx('node-item-icon', { dim: icons === 'dim' })} src={src} />
|
||||
)}
|
||||
</>
|
||||
)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import * as React from 'react'
|
|||
import { Config } from 'utils/configHelper'
|
||||
import { useStates } from 'utils/hooks'
|
||||
import { AccessTokenSettings } from './settings/AccessTokenSettings'
|
||||
import { FileTreeIconSettings } from './settings/FileTreeIconSettings'
|
||||
import { ShortcutSettings } from './settings/ShortcutSettings'
|
||||
import { SimpleToggleField } from './SimpleToggleField'
|
||||
|
||||
|
|
@ -70,6 +71,7 @@ function SettingsBarContent() {
|
|||
<div className={'shadow-shelter'} />
|
||||
<AccessTokenSettings />
|
||||
<ShortcutSettings />
|
||||
<FileTreeIconSettings />
|
||||
<div className={'gitako-settings-bar-content-section others'}>
|
||||
<h4>More</h4>
|
||||
{moreFields.map(field => (
|
||||
|
|
|
|||
56
src/components/settings/FileTreeIconSettings.tsx
Normal file
56
src/components/settings/FileTreeIconSettings.tsx
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { useConfigs } from 'containers/ConfigsContext'
|
||||
import * as React from 'react'
|
||||
import { Config } from 'utils/configHelper'
|
||||
|
||||
const options: {
|
||||
key: Config['icons']
|
||||
value: Config['icons']
|
||||
label: string
|
||||
}[] = [
|
||||
{
|
||||
key: 'rich',
|
||||
value: 'rich',
|
||||
label: `VSCode icons`,
|
||||
},
|
||||
{
|
||||
key: 'dim',
|
||||
value: 'dim',
|
||||
label: `VSCode icons (single color)`,
|
||||
},
|
||||
{
|
||||
key: 'native',
|
||||
value: 'native',
|
||||
label: `Native GitHub icons`,
|
||||
},
|
||||
]
|
||||
|
||||
type Props = {}
|
||||
|
||||
export function FileTreeIconSettings(props: React.PropsWithChildren<Props>) {
|
||||
const configContext = useConfigs()
|
||||
return (
|
||||
<div className={'gitako-settings-bar-content-section toggle-shortcut'}>
|
||||
<h4>File Tree Icons</h4>
|
||||
<span>Icons can make a difference.</span>
|
||||
<br />
|
||||
<div className={'toggle-shortcut-input-control'}>
|
||||
<select
|
||||
onChange={e => {
|
||||
configContext.set({
|
||||
icons: e.target.value as Config['icons'],
|
||||
})
|
||||
}}
|
||||
className={'toggle-shortcut-input form-control'}
|
||||
placeholder={'focus here and press the shortcut keys'}
|
||||
value={configContext.val.icons}
|
||||
>
|
||||
{options.map(option => (
|
||||
<option key={option.key} value={option.value}>
|
||||
{option.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ export type Config = {
|
|||
copyFileButton: boolean
|
||||
copySnippetButton: boolean
|
||||
intelligentToggle: boolean | null // `null` stands for intelligent, boolean for sidebar open status
|
||||
icons: 'rich' | 'dim' | 'native'
|
||||
}
|
||||
|
||||
export enum configKeys {
|
||||
|
|
@ -18,6 +19,7 @@ export enum configKeys {
|
|||
copyFileButton = 'copyFileButton',
|
||||
copySnippetButton = 'copySnippetButton',
|
||||
intelligentToggle = 'intelligentToggle',
|
||||
icons = 'icons',
|
||||
}
|
||||
|
||||
export const defaultConfigs: Config = {
|
||||
|
|
@ -28,19 +30,17 @@ export const defaultConfigs: Config = {
|
|||
copyFileButton: true,
|
||||
copySnippetButton: true,
|
||||
intelligentToggle: null,
|
||||
icons: 'rich',
|
||||
}
|
||||
|
||||
const configKeyArray = Object.values(configKeys)
|
||||
|
||||
function applyDefaultConfigs(configs: Config) {
|
||||
return configKeyArray.reduce(
|
||||
(applied, configKey) => {
|
||||
const key = configKey as keyof Config
|
||||
Object.assign(applied, { [key]: key in configs ? configs[key] : defaultConfigs[key] })
|
||||
return applied
|
||||
},
|
||||
{} as Config,
|
||||
)
|
||||
return configKeyArray.reduce((applied, configKey) => {
|
||||
const key = configKey as keyof Config
|
||||
Object.assign(applied, { [key]: key in configs ? configs[key] : defaultConfigs[key] })
|
||||
return applied
|
||||
}, {} as Config)
|
||||
}
|
||||
|
||||
export async function get(): Promise<Config> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue