mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 03:14:11 +00:00
feat(webui): add chatbot layout and drag-drop context store
This commit is contained in:
@@ -23,7 +23,16 @@ import { cn } from '@/ui/lib/utils'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
import type { AncestorFolder } from '@shumai/dtos'
|
||||
import { Link, useNavigate } from '@tanstack/react-router'
|
||||
import { Check, ChevronDown, Columns2, FileIcon, History, LayoutGrid, List } from 'lucide-react'
|
||||
import {
|
||||
Check,
|
||||
ChevronDown,
|
||||
Columns2,
|
||||
FileIcon,
|
||||
History,
|
||||
LayoutGrid,
|
||||
List,
|
||||
MessageSquare,
|
||||
} from 'lucide-react'
|
||||
|
||||
interface BreadcrumbNavProps {
|
||||
teamId: string
|
||||
@@ -43,6 +52,8 @@ interface BreadcrumbNavProps {
|
||||
onLeftSidebarToggle?: () => void
|
||||
isRightSidebarCollapsed: boolean
|
||||
onRightSidebarToggle: () => void
|
||||
isChatbotOpen?: boolean
|
||||
onChatbotToggle?: () => void
|
||||
isPublic?: boolean
|
||||
shareId?: string
|
||||
onFolderClick?: (folderId: string) => void
|
||||
@@ -81,6 +92,8 @@ export function BreadcrumbNav({
|
||||
onLeftSidebarToggle,
|
||||
isRightSidebarCollapsed,
|
||||
onRightSidebarToggle,
|
||||
isChatbotOpen = false,
|
||||
onChatbotToggle,
|
||||
isPublic = false,
|
||||
onFolderClick,
|
||||
fileId,
|
||||
@@ -364,67 +377,89 @@ export function BreadcrumbNav({
|
||||
)}
|
||||
</div>
|
||||
|
||||
{!fileId && (
|
||||
<div className="flex flex-shrink-0 items-center gap-1 rounded-md border border-border bg-background p-1">
|
||||
{/* Left Sidebar Toggle */}
|
||||
{!isPublic && onLeftSidebarToggle && (
|
||||
<button
|
||||
onClick={onLeftSidebarToggle}
|
||||
className="rounded p-1.5 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground"
|
||||
title={isLeftSidebarCollapsed ? 'Show Left Sidebar' : 'Hide Left Sidebar'}
|
||||
>
|
||||
{isLeftSidebarCollapsed ? (
|
||||
<DockToLeft className="h-4 w-4" />
|
||||
) : (
|
||||
<DockToLeftFilled className="h-4 w-4 fill-primary stroke-0" />
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
|
||||
{/* Card View */}
|
||||
{!isPublic && displayStyle && onDisplayStyleChange && (
|
||||
<>
|
||||
<button
|
||||
onClick={() => onDisplayStyleChange('card')}
|
||||
className={`rounded p-1.5 transition-colors ${
|
||||
displayStyle === 'card'
|
||||
? 'bg-accent text-accent-foreground'
|
||||
: 'text-muted-foreground hover:bg-accent/50 hover:text-foreground'
|
||||
}`}
|
||||
title="Card View"
|
||||
>
|
||||
<LayoutGrid className="h-4 w-4" />
|
||||
</button>
|
||||
|
||||
{/* List View */}
|
||||
<button
|
||||
onClick={() => onDisplayStyleChange('list')}
|
||||
className={`rounded p-1.5 transition-colors ${
|
||||
displayStyle === 'list'
|
||||
? 'bg-accent text-accent-foreground'
|
||||
: 'text-muted-foreground hover:bg-accent/50 hover:text-foreground'
|
||||
}`}
|
||||
title="List View"
|
||||
>
|
||||
<List className="h-4 w-4" />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Right Sidebar Toggle */}
|
||||
<div className="flex flex-shrink-0 items-center gap-1 rounded-md border border-border bg-background p-1">
|
||||
{/* Left Sidebar Toggle */}
|
||||
{!fileId && !isPublic && onLeftSidebarToggle && (
|
||||
<button
|
||||
onClick={onRightSidebarToggle}
|
||||
onClick={onLeftSidebarToggle}
|
||||
className="rounded p-1.5 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground"
|
||||
title={isRightSidebarCollapsed ? 'Show Right Sidebar' : 'Hide Right Sidebar'}
|
||||
title={isLeftSidebarCollapsed ? 'Show Left Sidebar' : 'Hide Left Sidebar'}
|
||||
>
|
||||
{isRightSidebarCollapsed ? (
|
||||
<DockToRight className="h-4 w-4" />
|
||||
{isLeftSidebarCollapsed ? (
|
||||
<DockToLeft className="h-4 w-4" />
|
||||
) : (
|
||||
<DockToRightFilled className="h-4 w-4 fill-primary stroke-0" />
|
||||
<DockToLeftFilled className="h-4 w-4 fill-primary stroke-0" />
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
)}
|
||||
|
||||
{/* Card View */}
|
||||
{!fileId && !isPublic && displayStyle && onDisplayStyleChange && (
|
||||
<>
|
||||
<button
|
||||
onClick={() => onDisplayStyleChange('card')}
|
||||
className={`rounded p-1.5 transition-colors ${
|
||||
displayStyle === 'card'
|
||||
? 'bg-accent text-accent-foreground'
|
||||
: 'text-muted-foreground hover:bg-accent/50 hover:text-foreground'
|
||||
}`}
|
||||
title="Card View"
|
||||
>
|
||||
<LayoutGrid className="h-4 w-4" />
|
||||
</button>
|
||||
|
||||
{/* List View */}
|
||||
<button
|
||||
onClick={() => onDisplayStyleChange('list')}
|
||||
className={`rounded p-1.5 transition-colors ${
|
||||
displayStyle === 'list'
|
||||
? 'bg-accent text-accent-foreground'
|
||||
: 'text-muted-foreground hover:bg-accent/50 hover:text-foreground'
|
||||
}`}
|
||||
title="List View"
|
||||
>
|
||||
<List className="h-4 w-4" />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Right Sidebar Toggle */}
|
||||
<button
|
||||
onClick={onRightSidebarToggle}
|
||||
className={`rounded p-1.5 transition-colors ${
|
||||
!isRightSidebarCollapsed && !isChatbotOpen
|
||||
? 'bg-accent text-accent-foreground'
|
||||
: 'text-muted-foreground hover:bg-accent/50 hover:text-foreground'
|
||||
}`}
|
||||
title={isRightSidebarCollapsed ? 'Show Right Sidebar' : 'Hide Right Sidebar'}
|
||||
>
|
||||
{!isRightSidebarCollapsed && !isChatbotOpen ? (
|
||||
<DockToRightFilled className="h-4 w-4 fill-primary stroke-0" />
|
||||
) : (
|
||||
<DockToRight className="h-4 w-4" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
{/* Chatbot Toggle Button */}
|
||||
{!isPublic && onChatbotToggle && (
|
||||
<button
|
||||
onClick={onChatbotToggle}
|
||||
className={`rounded p-1.5 transition-colors ${
|
||||
isChatbotOpen
|
||||
? 'bg-accent text-accent-foreground'
|
||||
: 'text-muted-foreground hover:bg-accent/50 hover:text-foreground'
|
||||
}`}
|
||||
title={isChatbotOpen ? m.hide_chatbot() : m.show_chatbot()}
|
||||
>
|
||||
<MessageSquare
|
||||
className={cn(
|
||||
'h-4 w-4 transition-colors',
|
||||
isChatbotOpen ? 'text-primary fill-primary stroke-1' : 'text-muted-foreground',
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import { useDroppable } from '@dnd-kit/react'
|
||||
import { useChatbotStore } from '@/ui/stores/chatbot'
|
||||
import { File, Folder, X, MessageSquare } from 'lucide-react'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
|
||||
export function ChatbotSidebar() {
|
||||
const { chatAssets, removeAsset, clearAssets } = useChatbotStore()
|
||||
|
||||
const { ref: setDroppableRef, isDropTarget: isOver } = useDroppable({
|
||||
id: 'chatbot-sidebar',
|
||||
data: {
|
||||
type: 'chatbot-sidebar',
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={setDroppableRef}
|
||||
className={cn(
|
||||
'flex flex-col h-full bg-background transition-colors duration-200 min-h-0',
|
||||
isOver && 'bg-accent/50 ring-2 ring-primary ring-inset',
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center justify-between p-4 border-b border-border flex-shrink-0">
|
||||
<div className="flex items-center gap-2 font-semibold">
|
||||
<MessageSquare className="h-5 w-5 text-primary" />
|
||||
<span>{m.chatbot_context()}</span>
|
||||
</div>
|
||||
{chatAssets.length > 0 && (
|
||||
<button
|
||||
onClick={clearAssets}
|
||||
className="text-xs text-muted-foreground hover:text-foreground underline transition-colors"
|
||||
>
|
||||
{m.clear()}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex-1 p-4 overflow-y-auto min-h-0 space-y-4">
|
||||
{chatAssets.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center h-48 border-2 border-dashed border-border rounded-lg text-muted-foreground p-4 text-center">
|
||||
<MessageSquare className="h-8 w-8 mb-2 opacity-50 text-muted-foreground" />
|
||||
<p className="text-sm">{m.chatbot_drag_drop_hint()}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
<h3 className="text-xs font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
{m.context_assets_count({ count: chatAssets.length })}
|
||||
</h3>
|
||||
<div className="divide-y divide-border border border-border rounded-md bg-muted/10 max-h-[400px] overflow-y-auto">
|
||||
{chatAssets.map((asset) => (
|
||||
<div
|
||||
key={asset.id}
|
||||
className="flex items-center justify-between p-2.5 text-sm group"
|
||||
>
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
{asset.type === 'folder' ? (
|
||||
<Folder className="h-4 w-4 text-blue-500 flex-shrink-0" />
|
||||
) : (
|
||||
<File className="h-4 w-4 text-muted-foreground flex-shrink-0" />
|
||||
)}
|
||||
<span className="truncate font-medium text-foreground">{asset.name}</span>
|
||||
<span className="text-[10px] bg-muted text-muted-foreground px-1.5 py-0.5 rounded-full capitalize">
|
||||
{asset.type}
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => removeAsset(asset.id)}
|
||||
className="text-muted-foreground hover:text-destructive opacity-0 group-hover:opacity-100 focus:opacity-100 transition-opacity p-0.5"
|
||||
title={m.remove_from_context()}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -25,6 +25,8 @@ import { FileViewerRightSidebar } from './file-viewer-right-sidebar'
|
||||
import { FolderTree } from './folder-tree'
|
||||
import { ResizeHandle } from './resize-handle'
|
||||
import { useFileSystemDnd } from './use-file-system-dnd'
|
||||
import { useChatbotStore } from '@/ui/stores/chatbot'
|
||||
import { ChatbotSidebar } from './chatbot-sidebar'
|
||||
|
||||
type FileSystemManagerProps = {
|
||||
teamId: string
|
||||
@@ -87,6 +89,7 @@ export default function FileSystemManager({
|
||||
const [lastSelectedId, setLastSelectedId] = useState<string | null>(null)
|
||||
const [leftSidebarWidth, setLeftSidebarWidth] = useState(240)
|
||||
const [rightSidebarWidth, setRightSidebarWidth] = useState(360)
|
||||
const { isChatbotOpen } = useChatbotStore()
|
||||
|
||||
const { members, fetchMembers } = useMemberStore()
|
||||
const { metadata, fetchMetadata, setMetadata: setUserMetadata } = useUserMetadataStore()
|
||||
@@ -433,10 +436,13 @@ export default function FileSystemManager({
|
||||
onClick={() => setIsLeftSidebarCollapsed(true)}
|
||||
/>
|
||||
)}
|
||||
{!isRightSidebarCollapsed && (
|
||||
{(!isRightSidebarCollapsed || isChatbotOpen) && (
|
||||
<div
|
||||
className="md:hidden fixed inset-0 bg-black/50 z-40"
|
||||
onClick={() => setIsRightSidebarCollapsed(true)}
|
||||
onClick={() => {
|
||||
setIsRightSidebarCollapsed(true)
|
||||
useChatbotStore.getState().setIsChatbotOpen(false)
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -495,7 +501,7 @@ export default function FileSystemManager({
|
||||
rootFolderId={rootFolderId}
|
||||
/>
|
||||
|
||||
{!isRightSidebarCollapsed && (
|
||||
{(!isRightSidebarCollapsed || isChatbotOpen) && (
|
||||
<>
|
||||
<ResizeHandle
|
||||
onResize={(delta) => {
|
||||
@@ -507,7 +513,9 @@ export default function FileSystemManager({
|
||||
style={{ width: rightSidebarWidth }}
|
||||
className="bg-background border-l border-border flex flex-col flex-shrink-0"
|
||||
>
|
||||
{singleSelectedFile ? (
|
||||
{isChatbotOpen ? (
|
||||
<ChatbotSidebar />
|
||||
) : singleSelectedFile ? (
|
||||
<FileViewerRightSidebar
|
||||
teamId={teamId}
|
||||
projectId={projectId}
|
||||
|
||||
@@ -2,10 +2,12 @@ import { useTopNavStore } from '@/ui/stores/top-nav'
|
||||
import { BreadcrumbNav } from './breadcrumb-nav'
|
||||
import { ShumaiLogo } from '@/ui/components/ui/icons'
|
||||
import { useUiStore } from '@/ui/stores/ui'
|
||||
import { useChatbotStore } from '@/ui/stores/chatbot'
|
||||
|
||||
export function TopNav() {
|
||||
const { projectState } = useTopNavStore()
|
||||
const uiStore = useUiStore()
|
||||
const { isChatbotOpen, setIsChatbotOpen } = useChatbotStore()
|
||||
|
||||
if (!projectState) {
|
||||
return <TeamHeader />
|
||||
@@ -58,14 +60,32 @@ export function TopNav() {
|
||||
const onRightSidebarToggle =
|
||||
isPublic && projectState.onRightSidebarToggle
|
||||
? projectState.onRightSidebarToggle
|
||||
: () =>
|
||||
isFileView
|
||||
? uiStore.setFileViewRightSidebarCollapsed(!uiStore.fileViewRightSidebarCollapsed)
|
||||
: isShareConfig
|
||||
? uiStore.setShareConfigRightSidebarCollapsed(
|
||||
!uiStore.shareConfigRightSidebarCollapsed,
|
||||
)
|
||||
: uiStore.setFileListRightSidebarCollapsed(!uiStore.fileListRightSidebarCollapsed)
|
||||
: () => {
|
||||
if (!isPublic && isChatbotOpen) {
|
||||
setIsChatbotOpen(false)
|
||||
if (isFileView) {
|
||||
uiStore.setFileViewRightSidebarCollapsed(false)
|
||||
} else if (isShareConfig) {
|
||||
uiStore.setShareConfigRightSidebarCollapsed(false)
|
||||
} else {
|
||||
uiStore.setFileListRightSidebarCollapsed(false)
|
||||
}
|
||||
} else {
|
||||
if (isFileView) {
|
||||
uiStore.setFileViewRightSidebarCollapsed(!uiStore.fileViewRightSidebarCollapsed)
|
||||
} else if (isShareConfig) {
|
||||
uiStore.setShareConfigRightSidebarCollapsed(!uiStore.shareConfigRightSidebarCollapsed)
|
||||
} else {
|
||||
uiStore.setFileListRightSidebarCollapsed(!uiStore.fileListRightSidebarCollapsed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const onChatbotToggle = isPublic
|
||||
? undefined
|
||||
: () => {
|
||||
setIsChatbotOpen(!isChatbotOpen)
|
||||
}
|
||||
|
||||
const displayStyle = projectId ? (uiStore.viewModes[projectId] ?? 'card') : 'card'
|
||||
const onDisplayStyleChange = isPublic
|
||||
@@ -88,6 +108,8 @@ export function TopNav() {
|
||||
onLeftSidebarToggle={onLeftSidebarToggle}
|
||||
isRightSidebarCollapsed={isRightSidebarCollapsed}
|
||||
onRightSidebarToggle={onRightSidebarToggle}
|
||||
isChatbotOpen={!isPublic && isChatbotOpen}
|
||||
onChatbotToggle={onChatbotToggle}
|
||||
isPublic={isPublic}
|
||||
shareId={shareId}
|
||||
fileId={fileId}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { useState } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
import type { DragEndEvent, DragStartEvent } from '@dnd-kit/react'
|
||||
import type { DragState } from './dnd-types'
|
||||
import { useChatbotStore } from '@/ui/stores/chatbot'
|
||||
|
||||
interface UseFileSystemDndProps {
|
||||
teamId: string
|
||||
@@ -188,6 +189,24 @@ export function useFileSystemDnd({
|
||||
const targetId = (target.id as string).split(':').pop()!
|
||||
const targetData = target.data as { type: string; item: AssetInfo } | undefined
|
||||
|
||||
if (targetData?.type === 'chatbot-sidebar') {
|
||||
const draggedItems = [...folders, ...files].filter((item) =>
|
||||
dragState.draggedIds.has(item.id!),
|
||||
)
|
||||
|
||||
const chatAssets = draggedItems.map((item) => ({
|
||||
id: item.id!,
|
||||
name: item.name || 'Unnamed',
|
||||
type: item.type as 'file' | 'folder',
|
||||
}))
|
||||
|
||||
useChatbotStore.getState().addAssets(chatAssets)
|
||||
toast.success(`Added ${chatAssets.length} item(s) to chatbot context`)
|
||||
onClearSelection()
|
||||
setDragState(undefined)
|
||||
return
|
||||
}
|
||||
|
||||
if (targetData?.type === 'share-link') {
|
||||
const shareId = targetId
|
||||
const assetIds = Array.from(dragState.draggedIds)
|
||||
|
||||
Reference in New Issue
Block a user