Download studio/src/components/GlobalSearchModal.jsx from shak3008/DiffWeave: direct link, hf CLI and curl.
- Browser
- Download file 13.7 kB
-
https://huggingface.co/spaces/shak3008/DiffWeave/resolve/main/studio/src/components/GlobalSearchModal.jsx
- Command line
-
hf download hf://spaces/shak3008/DiffWeave/studio/src/components/GlobalSearchModal.jsx
-
curl -L -o GlobalSearchModal.jsx https://huggingface.co/spaces/shak3008/DiffWeave/resolve/main/studio/src/components/GlobalSearchModal.jsx
13.7 kB
| import React, { useState, useEffect, useRef } from 'react'; | |
| import { useNavigate } from 'react-router-dom'; | |
| import { | |
| Search, | |
| X, | |
| Globe, | |
| Lock, | |
| Files, | |
| Database, | |
| Users, | |
| Heart, | |
| ArrowRight, | |
| ExternalLink, | |
| Sparkles, | |
| Command | |
| } from 'lucide-react'; | |
| import { api } from '../api/client'; | |
| export default function GlobalSearchModal({ isOpen, onClose, onSelectWorkspace, onSelectUser }) { | |
| const [query, setQuery] = useState(''); | |
| const [filterType, setFilterType] = useState('ALL'); // 'ALL' | 'WORKSPACES' | 'USERS' | |
| const [loading, setLoading] = useState(false); | |
| const [results, setResults] = useState({ workspaces: [], users: [] }); | |
| const [recentSearches, setRecentSearches] = useState(['Clinical', 'Legal', 'Master', 'Adhi']); | |
| const inputRef = useRef(null); | |
| const navigate = useNavigate(); | |
| useEffect(() => { | |
| if (isOpen) { | |
| setTimeout(() => inputRef.current?.focus(), 50); | |
| if (query.trim()) { | |
| performSearch(query); | |
| } | |
| } else { | |
| setQuery(''); | |
| } | |
| }, [isOpen]); | |
| useEffect(() => { | |
| if (!isOpen) return; | |
| const timeout = setTimeout(() => { | |
| performSearch(query); | |
| }, 200); | |
| return () => clearTimeout(timeout); | |
| }, [query]); | |
| const performSearch = async (searchStr) => { | |
| const q = searchStr.trim(); | |
| if (!q) { | |
| setResults({ workspaces: [], users: [] }); | |
| return; | |
| } | |
| setLoading(true); | |
| try { | |
| const data = await api.searchGlobal(q); | |
| setResults({ | |
| workspaces: data.workspaces || [], | |
| users: data.users || [], | |
| }); | |
| } catch (err) { | |
| console.warn('Global search error:', err); | |
| } finally { | |
| setLoading(false); | |
| } | |
| }; | |
| const handleOpenWorkspace = (ws) => { | |
| if (onSelectWorkspace) onSelectWorkspace(ws); | |
| navigate(`/workspaces/${ws.id}/diff`); | |
| onClose(); | |
| }; | |
| if (!isOpen) return null; | |
| const filteredWorkspaces = filterType === 'USERS' ? [] : results.workspaces; | |
| const filteredUsers = filterType === 'WORKSPACES' ? [] : results.users; | |
| const totalFound = filteredWorkspaces.length + filteredUsers.length; | |
| return ( | |
| <div className="fixed inset-0 z-50 flex items-start justify-center pt-16 sm:pt-24 px-4 bg-black/80 backdrop-blur-md"> | |
| <div className="bg-[#0B0F19] border border-slate-700/80 rounded-2xl w-full max-w-2xl shadow-2xl overflow-hidden flex flex-col max-h-[80vh] animate-in fade-in zoom-in-95 duration-150"> | |
| {/* Search Input Bar */} | |
| <div className="p-4 border-b border-slate-800 flex items-center space-x-3 bg-[#0D121F]"> | |
| <Search className="w-5 h-5 text-emerald-400 shrink-0" /> | |
| <input | |
| ref={inputRef} | |
| type="text" | |
| value={query} | |
| onChange={(e) => setQuery(e.target.value)} | |
| placeholder="Search workspaces, collaborators, or knowledge registries..." | |
| className="flex-1 bg-transparent text-sm text-white placeholder-slate-500 focus:outline-none font-mono" | |
| /> | |
| {loading && ( | |
| <div className="w-4 h-4 border-2 border-emerald-500 border-t-transparent rounded-full animate-spin shrink-0" /> | |
| )} | |
| {query && ( | |
| <button | |
| onClick={() => setQuery('')} | |
| className="p-1 rounded text-slate-500 hover:text-white transition" | |
| > | |
| <X className="w-4 h-4" /> | |
| </button> | |
| )} | |
| <button | |
| onClick={onClose} | |
| className="px-2 py-0.5 rounded bg-slate-800 text-[11px] font-mono text-slate-400 hover:text-white transition" | |
| > | |
| ESC | |
| </button> | |
| </div> | |
| {/* Filter Pills */} | |
| <div className="px-4 py-2 bg-[#090D15] border-b border-slate-800/80 flex items-center space-x-2 text-xs"> | |
| <span className="text-[11px] text-slate-500 font-mono mr-1">Filter:</span> | |
| {[ | |
| { id: 'ALL', label: 'All Results' }, | |
| { id: 'WORKSPACES', label: `Workspaces (${results.workspaces.length})` }, | |
| { id: 'USERS', label: `Users (${results.users.length})` } | |
| ].map((pill) => ( | |
| <button | |
| key={pill.id} | |
| onClick={() => setFilterType(pill.id)} | |
| className={`px-2.5 py-1 rounded-lg text-[11px] font-semibold transition ${ | |
| filterType === pill.id | |
| ? 'bg-emerald-500/10 text-emerald-300 border border-emerald-500/30' | |
| : 'text-slate-400 hover:text-white hover:bg-slate-800' | |
| }`} | |
| > | |
| {pill.label} | |
| </button> | |
| ))} | |
| </div> | |
| {/* Results Container */} | |
| <div className="p-4 overflow-y-auto flex-1 space-y-5"> | |
| {!query.trim() ? ( | |
| <div className="space-y-4 py-2"> | |
| <div className="text-xs text-slate-400 font-mono flex items-center space-x-1.5"> | |
| <Sparkles className="w-3.5 h-3.5 text-amber-400" /> | |
| <span>Suggested Searches</span> | |
| </div> | |
| <div className="flex flex-wrap gap-2"> | |
| {recentSearches.map((term) => ( | |
| <button | |
| key={term} | |
| onClick={() => setQuery(term)} | |
| className="px-3 py-1.5 rounded-xl bg-[#121826] hover:bg-[#1A2236] border border-slate-800 text-xs text-slate-300 font-mono hover:text-white transition flex items-center space-x-1.5" | |
| > | |
| <Search className="w-3 h-3 text-emerald-400" /> | |
| <span>{term}</span> | |
| </button> | |
| ))} | |
| </div> | |
| <p className="text-[11px] text-slate-500 pt-3"> | |
| Tip: Search by workspace name, topic keyword, or teammate's email/username. | |
| </p> | |
| </div> | |
| ) : totalFound === 0 && !loading ? ( | |
| <div className="py-12 text-center space-y-2"> | |
| <Search className="w-8 h-8 text-slate-600 mx-auto" /> | |
| <p className="text-xs text-slate-300 font-medium">No results found for "{query}".</p> | |
| <p className="text-[11px] text-slate-500"> | |
| Try searching by a broader keyword or checking for spelling. | |
| </p> | |
| </div> | |
| ) : ( | |
| <> | |
| {/* Workspaces Section */} | |
| {filteredWorkspaces.length > 0 && ( | |
| <div className="space-y-2.5"> | |
| <div className="flex items-center justify-between text-xs text-slate-400 font-mono"> | |
| <span className="font-bold uppercase tracking-wider text-slate-300">Workspaces</span> | |
| <span>{filteredWorkspaces.length} found</span> | |
| </div> | |
| <div className="space-y-2"> | |
| {filteredWorkspaces.map((ws) => ( | |
| <div | |
| key={ws.id} | |
| onClick={() => handleOpenWorkspace(ws)} | |
| className="p-3.5 rounded-xl bg-[#111726] hover:bg-[#172036] border border-slate-800 hover:border-emerald-500/40 transition cursor-pointer flex flex-col sm:flex-row sm:items-center justify-between gap-3 group" | |
| > | |
| <div className="flex items-start space-x-3 min-w-0"> | |
| <div className={`p-2 rounded-lg shrink-0 mt-0.5 ${ | |
| ws.visibility === 'public' | |
| ? 'bg-sky-500/10 text-sky-400 border border-sky-500/20' | |
| : 'bg-amber-500/10 text-amber-400 border border-amber-500/20' | |
| }`}> | |
| {ws.visibility === 'public' ? ( | |
| <Globe className="w-4 h-4" /> | |
| ) : ( | |
| <Lock className="w-4 h-4" /> | |
| )} | |
| </div> | |
| <div className="min-w-0"> | |
| <div className="flex items-center space-x-2"> | |
| <span className="font-bold text-xs text-white group-hover:text-emerald-300 truncate"> | |
| {ws.name} | |
| </span> | |
| <span className={`px-1.5 py-0.2 rounded text-[9px] font-mono font-bold uppercase ${ | |
| ws.visibility === 'public' | |
| ? 'bg-sky-500/10 text-sky-400 border border-sky-500/20' | |
| : 'bg-amber-500/10 text-amber-400 border border-amber-500/20' | |
| }`}> | |
| {ws.visibility} | |
| </span> | |
| </div> | |
| <p className="text-[11px] text-slate-400 line-clamp-1 mt-0.5"> | |
| {ws.description || `Maintained by ${ws.owner?.username || 'Owner'}`} | |
| </p> | |
| <div className="flex items-center space-x-3 text-[10px] text-slate-500 font-mono mt-1"> | |
| <span className="flex items-center space-x-1"> | |
| <Files className="w-3 h-3 text-slate-400" /> | |
| <span>{ws.doc_count || 0} docs</span> | |
| </span> | |
| <span>•</span> | |
| <span className="flex items-center space-x-1"> | |
| <Database className="w-3 h-3 text-emerald-400" /> | |
| <span>{ws.knowledge_count || 0} facts</span> | |
| </span> | |
| <span>•</span> | |
| <span className="flex items-center space-x-1 text-pink-400"> | |
| <Heart className="w-3 h-3 fill-pink-400/50" /> | |
| <span>{ws.follower_count || 0} followers</span> | |
| </span> | |
| </div> | |
| </div> | |
| </div> | |
| <div className="flex items-center space-x-2 shrink-0 self-end sm:self-center"> | |
| <span className="text-xs text-emerald-400 font-semibold group-hover:translate-x-0.5 transition flex items-center space-x-1"> | |
| <span>Open</span> | |
| <ArrowRight className="w-3.5 h-3.5" /> | |
| </span> | |
| </div> | |
| </div> | |
| ))} | |
| </div> | |
| </div> | |
| )} | |
| {/* Users Section */} | |
| {filteredUsers.length > 0 && ( | |
| <div className="space-y-2.5 pt-2"> | |
| <div className="flex items-center justify-between text-xs text-slate-400 font-mono"> | |
| <span className="font-bold uppercase tracking-wider text-slate-300">Users & Collaborators</span> | |
| <span>{filteredUsers.length} found</span> | |
| </div> | |
| <div className="divide-y divide-slate-800/80 rounded-xl border border-slate-800 bg-[#111726] overflow-hidden text-xs"> | |
| {filteredUsers.map((u) => ( | |
| <div | |
| key={u.id} | |
| onClick={() => { | |
| if (onSelectUser) onSelectUser(u); | |
| onClose(); | |
| }} | |
| className="p-3.5 flex items-center justify-between hover:bg-[#161D2E] transition cursor-pointer group" | |
| > | |
| <div className="flex items-center space-x-3 min-w-0"> | |
| <div className="w-8 h-8 rounded-full bg-emerald-500/20 text-emerald-400 font-bold flex items-center justify-center text-xs border border-emerald-500/30 shrink-0"> | |
| {(u.username || u.email)[0].toUpperCase()} | |
| </div> | |
| <div className="min-w-0"> | |
| <span className="font-semibold text-white block group-hover:text-emerald-300 transition truncate"> | |
| {u.username || 'Collaborator'} | |
| </span> | |
| <span className="text-[10px] text-slate-400 font-mono block truncate">{u.email}</span> | |
| </div> | |
| </div> | |
| <div className="flex items-center space-x-3 shrink-0"> | |
| <span className="px-2 py-0.5 rounded text-[10px] font-mono bg-slate-800 text-slate-300"> | |
| {u.workspaces_count || 0} workspaces | |
| </span> | |
| <span className="text-xs text-emerald-400 font-semibold group-hover:translate-x-0.5 transition flex items-center space-x-1"> | |
| <span>Profile</span> | |
| <ArrowRight className="w-3.5 h-3.5" /> | |
| </span> | |
| </div> | |
| </div> | |
| ))} | |
| </div> | |
| </div> | |
| )} | |
| </> | |
| )} | |
| </div> | |
| {/* Footer */} | |
| <div className="px-4 py-2.5 bg-[#090D15] border-t border-slate-800/80 flex items-center justify-between text-[11px] text-slate-500 font-mono"> | |
| <div className="flex items-center space-x-2"> | |
| <Command className="w-3.5 h-3.5 text-slate-400" /> | |
| <span>Global Registry Search across all public & shared repositories</span> | |
| </div> | |
| <span>Press ESC to close</span> | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |