mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Merge branch 'main' of gitlab.com:soapbox-pub/act2
This commit is contained in:
3 files changed
+129
-28
No files matched your search
@@ -8,12 +8,12 @@
|
|||||||
"theme_color": "#000000",
|
"theme_color": "#000000",
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
"src": "/icon-192.png",
|
"src": "/favicon.png",
|
||||||
"sizes": "192x192",
|
"sizes": "192x192",
|
||||||
"type": "image/png"
|
"type": "image/png"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"src": "/icon-512.png",
|
"src": "/favicon.png",
|
||||||
"sizes": "512x512",
|
"sizes": "512x512",
|
||||||
"type": "image/png"
|
"type": "image/png"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
const [systemPrompt, setSystemPrompt] = useState('');
|
const [systemPrompt, setSystemPrompt] = useState('');
|
||||||
const [showScrollToBottom, setShowScrollToBottom] = useState(false);
|
const [showScrollToBottom, setShowScrollToBottom] = useState(false);
|
||||||
const [attachedFiles, setAttachedFiles] = useState<File[]>([]);
|
const [attachedFiles, setAttachedFiles] = useState<File[]>([]);
|
||||||
|
const [scrolledProjects] = useState(() => new Set<string>());
|
||||||
|
|
||||||
// Use external state if provided, otherwise default to false
|
// Use external state if provided, otherwise default to false
|
||||||
const isBuildLoading = externalIsBuildLoading || false;
|
const isBuildLoading = externalIsBuildLoading || false;
|
||||||
@@ -235,16 +236,6 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
}
|
}
|
||||||
}, [addRecentlyUsedModel, isConfigured, providerModel, searchParams, setSearchParams, startGeneration]);
|
}, [addRecentlyUsedModel, isConfigured, providerModel, searchParams, setSearchParams, startGeneration]);
|
||||||
|
|
||||||
// Function to check if user is at the bottom of the scroll area
|
|
||||||
const checkScrollPosition = () => {
|
|
||||||
if (!scrollAreaRef.current) return;
|
|
||||||
|
|
||||||
const container = scrollAreaRef.current;
|
|
||||||
const threshold = 100; // 100px threshold
|
|
||||||
const isNearBottom = container.scrollTop + container.clientHeight >= container.scrollHeight - threshold;
|
|
||||||
|
|
||||||
setShowScrollToBottom(!isNearBottom && container.scrollHeight > container.clientHeight);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Function to scroll to bottom
|
// Function to scroll to bottom
|
||||||
const scrollToBottom = () => {
|
const scrollToBottom = () => {
|
||||||
@@ -253,20 +244,28 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add scroll event listener
|
// Simple scroll event listener
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const container = scrollAreaRef.current;
|
const container = scrollAreaRef.current;
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
|
|
||||||
container.addEventListener('scroll', checkScrollPosition);
|
const handleScroll = () => {
|
||||||
|
const threshold = 100;
|
||||||
|
const isNearBottom = container.scrollTop + container.clientHeight >= container.scrollHeight - threshold;
|
||||||
|
const hasScrollableContent = container.scrollHeight > container.clientHeight;
|
||||||
|
|
||||||
// Check initial position
|
setShowScrollToBottom(!isNearBottom && hasScrollableContent);
|
||||||
checkScrollPosition();
|
};
|
||||||
|
|
||||||
|
container.addEventListener('scroll', handleScroll);
|
||||||
|
|
||||||
|
// Check immediately
|
||||||
|
handleScroll();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
container.removeEventListener('scroll', checkScrollPosition);
|
container.removeEventListener('scroll', handleScroll);
|
||||||
};
|
};
|
||||||
}, []);
|
}, [messages]); // Re-run when messages change to ensure proper setup
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (scrollAreaRef.current && (messages || streamingMessage)) {
|
if (scrollAreaRef.current && (messages || streamingMessage)) {
|
||||||
@@ -280,11 +279,34 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
container.scrollTop = container.scrollHeight;
|
container.scrollTop = container.scrollHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update scroll button visibility
|
|
||||||
checkScrollPosition();
|
|
||||||
}
|
}
|
||||||
}, [messages, streamingMessage, isLoading]);
|
}, [messages, streamingMessage, isLoading]);
|
||||||
|
|
||||||
|
// Scroll to bottom when first visiting a project (including page refresh)
|
||||||
|
useEffect(() => {
|
||||||
|
if (projectId && !scrolledProjects.has(projectId)) {
|
||||||
|
// Small delay to ensure messages have loaded
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
scrollToBottom();
|
||||||
|
scrolledProjects.add(projectId);
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
return () => clearTimeout(timer);
|
||||||
|
}
|
||||||
|
}, [projectId, scrolledProjects]);
|
||||||
|
|
||||||
|
// Also scroll on initial mount if we have a projectId
|
||||||
|
useEffect(() => {
|
||||||
|
if (projectId && !scrolledProjects.has(projectId)) {
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
scrollToBottom();
|
||||||
|
scrolledProjects.add(projectId);
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
return () => clearTimeout(timer);
|
||||||
|
}
|
||||||
|
}, []); // Empty dependency array = runs on mount
|
||||||
|
|
||||||
const handleFileSelect = (file: File) => {
|
const handleFileSelect = (file: File) => {
|
||||||
setAttachedFiles(prev => [...prev, file]);
|
setAttachedFiles(prev => [...prev, file]);
|
||||||
};
|
};
|
||||||
@@ -526,7 +548,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
|
|
||||||
<div className="border-t p-4">
|
<div className="border-t p-4">
|
||||||
{/* Chat Input Container */}
|
{/* Chat Input Container */}
|
||||||
<div className="relative rounded-2xl border border-input bg-background shadow-sm focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 transition-all">
|
<div className="flex flex-col rounded-2xl border border-input bg-background shadow-sm focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 transition-all">
|
||||||
<Textarea
|
<Textarea
|
||||||
value={input}
|
value={input}
|
||||||
onChange={(e) => setInput(e.target.value)}
|
onChange={(e) => setInput(e.target.value)}
|
||||||
@@ -534,7 +556,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
onPaste={handlePaste}
|
onPaste={handlePaste}
|
||||||
onFocus={handleFirstInteraction}
|
onFocus={handleFirstInteraction}
|
||||||
placeholder={providerModel.trim() ? "Ask me to add features, edit files, or build your project..." : "Please select a model to start chatting..."}
|
placeholder={providerModel.trim() ? "Ask me to add features, edit files, or build your project..." : "Please select a model to start chatting..."}
|
||||||
className="min-h-[52px] max-h-32 resize-none border-0 bg-transparent px-4 py-3 pb-12 text-sm focus-visible:ring-0 focus-visible:ring-offset-0 placeholder:text-muted-foreground"
|
className="flex-1 resize-none border-0 bg-transparent px-4 py-3 text-sm focus-visible:ring-0 focus-visible:ring-offset-0 placeholder:text-muted-foreground"
|
||||||
disabled={isLoading || !providerModel.trim()}
|
disabled={isLoading || !providerModel.trim()}
|
||||||
rows={1}
|
rows={1}
|
||||||
style={{
|
style={{
|
||||||
@@ -549,7 +571,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Bottom Controls Row */}
|
{/* Bottom Controls Row */}
|
||||||
<div className="absolute bottom-2 left-2 right-2 flex items-center gap-4">
|
<div className="flex items-center gap-4 px-2 py-2">
|
||||||
{/* File Attachment */}
|
{/* File Attachment */}
|
||||||
<FileAttachment
|
<FileAttachment
|
||||||
onFileSelect={handleFileSelect}
|
onFileSelect={handleFileSelect}
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ import { useState, useEffect, useCallback } from 'react';
|
|||||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
import { useGitStatus } from '@/hooks/useGitStatus';
|
import { useGitStatus } from '@/hooks/useGitStatus';
|
||||||
import { ChevronRight, ChevronDown, File, Folder } from 'lucide-react';
|
import { ChevronRight, ChevronDown, File, Folder, Search } from 'lucide-react';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { createGitignoreFilter, normalizePathForGitignore } from '@/lib/gitignore';
|
import { createGitignoreFilter, normalizePathForGitignore } from '@/lib/gitignore';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
|
||||||
interface FileTreeProps {
|
interface FileTreeProps {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
@@ -22,11 +23,14 @@ interface FileNode {
|
|||||||
|
|
||||||
export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProps) {
|
export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProps) {
|
||||||
const [tree, setTree] = useState<FileNode[]>([]);
|
const [tree, setTree] = useState<FileNode[]>([]);
|
||||||
|
const [filteredTree, setFilteredTree] = useState<FileNode[]>([]);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [gitignoreFilter, setGitignoreFilter] = useState<{
|
const [gitignoreFilter, setGitignoreFilter] = useState<{
|
||||||
isIgnored: (path: string) => boolean;
|
isIgnored: (path: string) => boolean;
|
||||||
shouldShow: (path: string) => boolean;
|
shouldShow: (path: string) => boolean;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
|
const [isSearching, setIsSearching] = useState(false);
|
||||||
const { fs } = useFS();
|
const { fs } = useFS();
|
||||||
const projectsManager = useProjectsManager();
|
const projectsManager = useProjectsManager();
|
||||||
const { data: gitStatus } = useGitStatus(projectId);
|
const { data: gitStatus } = useGitStatus(projectId);
|
||||||
@@ -127,6 +131,7 @@ export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProp
|
|||||||
|
|
||||||
const structure = await buildFileTree(projectId, '');
|
const structure = await buildFileTree(projectId, '');
|
||||||
setTree(structure);
|
setTree(structure);
|
||||||
|
setFilteredTree(structure);
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
console.error('Failed to load file tree:', _error);
|
console.error('Failed to load file tree:', _error);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -151,7 +156,9 @@ export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProp
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Update both the original tree and filtered tree
|
||||||
setTree(prev => toggleNode(prev));
|
setTree(prev => toggleNode(prev));
|
||||||
|
setFilteredTree(prev => toggleNode(prev));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFileClick = (filePath: string, type: 'file' | 'directory') => {
|
const handleFileClick = (filePath: string, type: 'file' | 'directory') => {
|
||||||
@@ -162,6 +169,58 @@ export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProp
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Search functions
|
||||||
|
const searchInFiles = useCallback(async (nodes: FileNode[], term: string): Promise<FileNode[]> => {
|
||||||
|
if (!term.trim()) return nodes;
|
||||||
|
|
||||||
|
const results: FileNode[] = [];
|
||||||
|
const searchTermLower = term.toLowerCase();
|
||||||
|
|
||||||
|
for (const node of nodes) {
|
||||||
|
if (node.type === 'file') {
|
||||||
|
const fileNameMatch = node.name.toLowerCase().includes(searchTermLower);
|
||||||
|
|
||||||
|
if (fileNameMatch) {
|
||||||
|
results.push(node);
|
||||||
|
}
|
||||||
|
} else if (node.type === 'directory' && node.children) {
|
||||||
|
const childResults = await searchInFiles(node.children, term);
|
||||||
|
if (childResults.length > 0) {
|
||||||
|
// Create a filtered directory node with matching children
|
||||||
|
results.push({
|
||||||
|
...node,
|
||||||
|
children: childResults,
|
||||||
|
isOpen: true, // Auto-expand directories with matches
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results }, []);
|
||||||
|
|
||||||
|
// Perform search when search term changes
|
||||||
|
useEffect(() => {
|
||||||
|
const performSearch = async () => {
|
||||||
|
if (!searchTerm.trim()) {
|
||||||
|
setFilteredTree(tree);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsSearching(true);
|
||||||
|
try {
|
||||||
|
const results = await searchInFiles(tree, searchTerm);
|
||||||
|
setFilteredTree(results);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Search failed:', error);
|
||||||
|
setFilteredTree([]);
|
||||||
|
} finally {
|
||||||
|
setIsSearching(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
performSearch();
|
||||||
|
}, [searchTerm, tree, searchInFiles]);
|
||||||
|
|
||||||
const renderNode = (node: FileNode, depth: number = 0) => {
|
const renderNode = (node: FileNode, depth: number = 0) => {
|
||||||
const isSelected = selectedFile === node.path;
|
const isSelected = selectedFile === node.path;
|
||||||
|
|
||||||
@@ -232,12 +291,32 @@ export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProp
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-2">
|
<div className="p-2">
|
||||||
{tree.length === 0 ? (
|
{/* Search Section */}
|
||||||
<div className="text-center text-sm text-muted-foreground py-8">
|
<div className="mb-3">
|
||||||
No files found
|
<div className="relative">
|
||||||
|
<Search className="absolute left-2 top-2.5 h-4 w-4 text-muted-foreground" />
|
||||||
|
<Input
|
||||||
|
placeholder="Search files..."
|
||||||
|
value={searchTerm}
|
||||||
|
onChange={(e) => setSearchTerm(e.target.value)}
|
||||||
|
className="pl-8"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* File Tree */}
|
||||||
|
{isSearching ? (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{[...Array(3)].map((_, i) => (
|
||||||
|
<div key={i} className="h-6 bg-muted rounded animate-pulse"></div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : filteredTree.length === 0 ? (
|
||||||
|
<div className="text-center text-sm text-muted-foreground py-4">
|
||||||
|
{searchTerm ? 'No files found matching your search' : 'No files found'}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
tree.map(node => renderNode(node))
|
filteredTree.map(node => renderNode(node))
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user