Merge branch 'main' of gitlab.com:soapbox-pub/act2

This commit is contained in:
Alex Gleason committed 2025-09-18 12:35:48 -05:00
commit 8d00ac57c7
3 files changed
+129 -28

No files matched your search

+43 -21
View File
@@ -71,6 +71,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
const [systemPrompt, setSystemPrompt] = useState('');
const [showScrollToBottom, setShowScrollToBottom] = useState(false);
const [attachedFiles, setAttachedFiles] = useState<File[]>([]);
const [scrolledProjects] = useState(() => new Set<string>());
// Use external state if provided, otherwise default to false
const isBuildLoading = externalIsBuildLoading || false;
@@ -235,16 +236,6 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
}
}, [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
const scrollToBottom = () => {
@@ -253,20 +244,28 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
}
};
// Add scroll event listener
// Simple scroll event listener
useEffect(() => {
const container = scrollAreaRef.current;
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
checkScrollPosition();
setShowScrollToBottom(!isNearBottom && hasScrollableContent);
};
container.addEventListener('scroll', handleScroll);
// Check immediately
handleScroll();
return () => {
container.removeEventListener('scroll', checkScrollPosition);
container.removeEventListener('scroll', handleScroll);
};
}, []);
}, [messages]); // Re-run when messages change to ensure proper setup
useEffect(() => {
if (scrollAreaRef.current && (messages || streamingMessage)) {
@@ -280,11 +279,34 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
container.scrollTop = container.scrollHeight;
}
// Update scroll button visibility
checkScrollPosition();
}
}, [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) => {
setAttachedFiles(prev => [...prev, file]);
};
@@ -526,7 +548,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
<div className="border-t p-4">
{/* 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
value={input}
onChange={(e) => setInput(e.target.value)}
@@ -534,7 +556,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
onPaste={handlePaste}
onFocus={handleFirstInteraction}
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()}
rows={1}
style={{
@@ -549,7 +571,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
/>
{/* 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 */}
<FileAttachment
onFileSelect={handleFileSelect}
+84 -5
View File
@@ -2,9 +2,10 @@ import { useState, useEffect, useCallback } from 'react';
import { useProjectsManager } from '@/hooks/useProjectsManager';
import { useFS } from '@/hooks/useFS';
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 { createGitignoreFilter, normalizePathForGitignore } from '@/lib/gitignore';
import { Input } from '@/components/ui/input';
interface FileTreeProps {
projectId: string;
@@ -22,11 +23,14 @@ interface FileNode {
export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProps) {
const [tree, setTree] = useState<FileNode[]>([]);
const [filteredTree, setFilteredTree] = useState<FileNode[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [gitignoreFilter, setGitignoreFilter] = useState<{
isIgnored: (path: string) => boolean;
shouldShow: (path: string) => boolean;
} | null>(null);
const [searchTerm, setSearchTerm] = useState('');
const [isSearching, setIsSearching] = useState(false);
const { fs } = useFS();
const projectsManager = useProjectsManager();
const { data: gitStatus } = useGitStatus(projectId);
@@ -127,6 +131,7 @@ export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProp
const structure = await buildFileTree(projectId, '');
setTree(structure);
setFilteredTree(structure);
} catch (_error) {
console.error('Failed to load file tree:', _error);
} finally {
@@ -151,7 +156,9 @@ export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProp
});
};
// Update both the original tree and filtered tree
setTree(prev => toggleNode(prev));
setFilteredTree(prev => toggleNode(prev));
};
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 isSelected = selectedFile === node.path;
@@ -232,12 +291,32 @@ export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProp
return (
<div className="p-2">
{tree.length === 0 ? (
<div className="text-center text-sm text-muted-foreground py-8">
No files found
{/* Search Section */}
<div className="mb-3">
<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>
) : (
tree.map(node => renderNode(node))
filteredTree.map(node => renderNode(node))
)}
</div>
);