-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add preview support for file selector
- Loading branch information
1 parent
e07a790
commit 56b0b8c
Showing
20 changed files
with
408 additions
and
187 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/extension/webview-api/controllers/system.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as os from 'os' | ||
|
||
import { Controller } from '../types' | ||
|
||
export interface SystemInfo { | ||
os: string | ||
cpu: string | ||
memory: string | ||
platform: string | ||
} | ||
|
||
export class SystemController extends Controller { | ||
readonly name = 'system' | ||
|
||
async getSystemInfo(): Promise<SystemInfo> { | ||
return { | ||
os: `${os.type()} ${os.release()}`, | ||
cpu: os.cpus()[0]?.model || 'Unknown', | ||
memory: `${Math.round(os.totalmem() / (1024 * 1024 * 1024))} GB`, | ||
platform: os.platform() | ||
} | ||
} | ||
|
||
async isWindows(): Promise<boolean> { | ||
return os.platform() === 'win32' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/webview/components/chat/selectors/mention-selector/files/mention-file-preview.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { memo, useCallback, useMemo } from 'react' | ||
import { ChevronDownIcon } from '@radix-ui/react-icons' | ||
import { FileIcon } from '@webview/components/file-icon' | ||
import { Tree, type TreeNodeRenderProps } from '@webview/components/tree' | ||
import { useFilesTreeItems } from '@webview/hooks/chat/use-files-tree-items' | ||
import type { FileInfo, MentionOption } from '@webview/types/chat' | ||
|
||
export const MentionFilePreview: React.FC<MentionOption> = memo( | ||
mentionOption => { | ||
const fileInfo = mentionOption.data as FileInfo | ||
const { treeItems, getAllChildrenIds } = useFilesTreeItems({ | ||
files: [fileInfo] | ||
}) | ||
|
||
const allExpandedIds = useMemo( | ||
() => getAllChildrenIds(treeItems[0]!), | ||
[treeItems, getAllChildrenIds] | ||
) | ||
|
||
const renderItem = useCallback( | ||
({ | ||
item, | ||
isExpanded, | ||
hasChildren, | ||
onToggleExpand, | ||
level | ||
}: TreeNodeRenderProps) => ( | ||
<div | ||
className="flex items-center py-1 text-sm cursor-pointer" | ||
style={{ marginLeft: `${level * 20}px` }} | ||
onClick={onToggleExpand} | ||
> | ||
{hasChildren && <ChevronDownIcon className="size-4 mr-1" />} | ||
|
||
<FileIcon | ||
className="size-4 mr-1" | ||
isFolder={hasChildren} | ||
isOpen={isExpanded} | ||
filePath={item.name} | ||
/> | ||
|
||
<span>{item.name}</span> | ||
</div> | ||
), | ||
[] | ||
) | ||
|
||
return ( | ||
<div className="flex flex-col h-full"> | ||
<div className="flex flex-col flex-1 overflow-auto"> | ||
<Tree | ||
items={treeItems} | ||
expandedItemIds={allExpandedIds} | ||
renderItem={renderItem} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.