mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-03 07:57:22 +00:00
Add search to projects sidebar
This commit is contained in:
7 files changed
+57
-4
No files matched your search
@@ -1,9 +1,10 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import React, { useEffect, useState, useMemo } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Plus, Folder, GitBranch, Loader2, ChevronDown, Star, Columns2, X, Settings, HelpCircle } from 'lucide-react';
|
||||
import { Plus, Folder, GitBranch, Loader2, ChevronDown, Star, Columns2, X, Settings, HelpCircle, Search } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { useProjects } from '@/hooks/useProjects';
|
||||
import { useProjectSessionStatus } from '@/hooks/useProjectSessionStatus';
|
||||
@@ -93,10 +94,24 @@ export function ProjectSidebar({
|
||||
const queryClient = useQueryClient();
|
||||
const { data: projects = [], isLoading, error } = useProjects();
|
||||
const [favorites] = useLocalStorage<string[]>('project-favorites', []);
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
|
||||
const isMobile = useIsMobile();
|
||||
const navigate = useNavigate();
|
||||
|
||||
// Fast in-memory search filtering
|
||||
const filteredProjects = useMemo(() => {
|
||||
if (!searchQuery.trim()) {
|
||||
return projects;
|
||||
}
|
||||
|
||||
const query = searchQuery.toLowerCase();
|
||||
return projects.filter(project =>
|
||||
project.id.toLowerCase().includes(query) ||
|
||||
project.name.toLowerCase().includes(query)
|
||||
);
|
||||
}, [projects, searchQuery]);
|
||||
|
||||
// Custom navigate function that closes sidebar on mobile
|
||||
const navigateAndClose = (path: string) => {
|
||||
navigate(path);
|
||||
@@ -166,7 +181,7 @@ export function ProjectSidebar({
|
||||
|
||||
<div className="flex-1 overflow-y-auto">
|
||||
<div className="p-2">
|
||||
<div className="mb-2">
|
||||
<div className="mb-2 space-y-3">
|
||||
<div className="relative rounded-md bg-gradient-to-r from-primary to-accent hover:from-primary/90 hover:to-accent/90 transition-all duration-200">
|
||||
<div className="flex">
|
||||
<button
|
||||
@@ -195,6 +210,20 @@ export function ProjectSidebar({
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Search Input */}
|
||||
{projects.length > 0 && (
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none" />
|
||||
<Input
|
||||
type="text"
|
||||
placeholder={t('searchProjects')}
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="pl-9 h-9 bg-sidebar-accent/50 border-sidebar-border focus-visible:ring-primary/50"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
@@ -214,9 +243,15 @@ export function ProjectSidebar({
|
||||
<p className="text-sm">{t('noProjectsYet')}</p>
|
||||
<p className="text-xs">{t('createFirstProject')}</p>
|
||||
</div>
|
||||
) : filteredProjects.length === 0 ? (
|
||||
<div className="text-center p-6 text-muted-foreground">
|
||||
<Search className="h-8 w-8 mx-auto mb-2 opacity-50" />
|
||||
<p className="text-sm">{t('noProjectsFound')}</p>
|
||||
<p className="text-xs">{t('tryDifferentSearch')}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-1">
|
||||
{projects.map((project) => (
|
||||
{filteredProjects.map((project) => (
|
||||
<ProjectItem
|
||||
key={project.id}
|
||||
project={project}
|
||||
|
||||
@@ -113,6 +113,9 @@
|
||||
"importRepository": "Import Repository",
|
||||
"noProjectsYet": "No projects yet",
|
||||
"createFirstProject": "Create your first project to get started",
|
||||
"searchProjects": "Search projects...",
|
||||
"noProjectsFound": "No projects found",
|
||||
"tryDifferentSearch": "Try a different search term",
|
||||
"closeSidebar": "Close sidebar",
|
||||
"collapseSidebar": "Collapse sidebar",
|
||||
"welcomeToShakespeare": "Welcome to Shakespeare",
|
||||
|
||||
@@ -108,6 +108,9 @@
|
||||
"importRepository": "Shigo da Repository",
|
||||
"noProjectsYet": "Babu ayyuka har yanzu",
|
||||
"createFirstProject": "Ƙirƙiri aikin farko don farawa",
|
||||
"searchProjects": "Nemo ayyuka...",
|
||||
"noProjectsFound": "Ba a sami ayyuka ba",
|
||||
"tryDifferentSearch": "Gwada kalmar nema daban",
|
||||
"closeSidebar": "Rufe gefen mashigi",
|
||||
"collapseSidebar": "Rufe gefen mashigi",
|
||||
"welcomeToShakespeare": "Maraba da Shakespeare",
|
||||
|
||||
@@ -108,6 +108,9 @@
|
||||
"importRepository": "Bubata Repository",
|
||||
"noProjectsYet": "Enwebeghị ọrụ ọ bụla",
|
||||
"createFirstProject": "Mepụta ọrụ mbụ gị iji malite",
|
||||
"searchProjects": "Chọọ ọrụ...",
|
||||
"noProjectsFound": "Achọtaghị ọrụ ọ bụla",
|
||||
"tryDifferentSearch": "Nwalee okwu ọchụchọ dị iche",
|
||||
"closeSidebar": "Mechie sidebar",
|
||||
"collapseSidebar": "Gbakọọ sidebar",
|
||||
"welcomeToShakespeare": "Nnọọ na Shakespeare",
|
||||
|
||||
@@ -110,6 +110,9 @@
|
||||
"importRepository": "Importar Repositório",
|
||||
"noProjectsYet": "Nenhum projeto ainda",
|
||||
"createFirstProject": "Crie seu primeiro projeto para começar",
|
||||
"searchProjects": "Pesquisar projetos...",
|
||||
"noProjectsFound": "Nenhum projeto encontrado",
|
||||
"tryDifferentSearch": "Tente um termo de pesquisa diferente",
|
||||
"closeSidebar": "Fechar barra lateral",
|
||||
"collapseSidebar": "Recolher barra lateral",
|
||||
"welcomeToShakespeare": "Bem-vindo ao Shakespeare",
|
||||
|
||||
@@ -108,6 +108,9 @@
|
||||
"importRepository": "Gbe Repository wọle",
|
||||
"noProjectsYet": "Ko si awọn iṣẹ akanṣe sibẹsibẹ",
|
||||
"createFirstProject": "Ṣẹda iṣẹ akanṣe akọkọ rẹ lati bẹrẹ",
|
||||
"searchProjects": "Wa awọn iṣẹ akanṣe...",
|
||||
"noProjectsFound": "Ko ri awọn iṣẹ akanṣe",
|
||||
"tryDifferentSearch": "Gbiyanju ọrọ wiwa miiran",
|
||||
"closeSidebar": "Ti ẹgbẹ sidebar",
|
||||
"collapseSidebar": "Subu sidebar",
|
||||
"welcomeToShakespeare": "Kaabo si Shakespeare",
|
||||
|
||||
@@ -110,6 +110,9 @@
|
||||
"importRepository": "导入仓库",
|
||||
"noProjectsYet": "还没有项目",
|
||||
"createFirstProject": "创建您的第一个项目开始使用",
|
||||
"searchProjects": "搜索项目...",
|
||||
"noProjectsFound": "未找到项目",
|
||||
"tryDifferentSearch": "尝试不同的搜索词",
|
||||
"closeSidebar": "关闭侧边栏",
|
||||
"collapseSidebar": "折叠侧边栏",
|
||||
"welcomeToShakespeare": "欢迎使用Shakespeare",
|
||||
|
||||
Reference in new issue
Block a user