Spaces:
Running
Running
axeronis commited on
Commit ·
c3632ae
1
Parent(s): 8cbedfe
feat: add inline editing for search results - click to edit, save directly
Browse files
frontend/app/settings/brain/page.tsx
CHANGED
|
@@ -621,45 +621,86 @@ export default function BrainSettingsPage() {
|
|
| 621 |
) : searchResults?.results?.length > 0 ? (
|
| 622 |
<div className="space-y-4">
|
| 623 |
{searchResults.results.map((result: any, idx: number) => {
|
| 624 |
-
//
|
|
|
|
|
|
|
|
|
|
| 625 |
const sentences = result.content.split(/[.!?]+/).filter((s: string) => s.trim());
|
| 626 |
const matchingSentences = sentences
|
| 627 |
.filter((s: string) => s.toLowerCase().includes(searchQuery.toLowerCase()))
|
| 628 |
-
.slice(0, 3)
|
| 629 |
.join('. ');
|
| 630 |
const displayContent = matchingSentences || result.content.substring(0, 200) + '...';
|
| 631 |
|
| 632 |
return (
|
| 633 |
<motion.div
|
| 634 |
-
key={idx}
|
| 635 |
initial={{ opacity: 0, y: 10 }}
|
| 636 |
animate={{ opacity: 1, y: 0 }}
|
| 637 |
transition={{ delay: idx * 0.05 }}
|
| 638 |
-
className=
|
|
|
|
|
|
|
|
|
|
| 639 |
>
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
{((
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 650 |
</div>
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 663 |
</motion.div>
|
| 664 |
)
|
| 665 |
})}
|
|
|
|
| 621 |
) : searchResults?.results?.length > 0 ? (
|
| 622 |
<div className="space-y-4">
|
| 623 |
{searchResults.results.map((result: any, idx: number) => {
|
| 624 |
+
// Check if this result is being edited
|
| 625 |
+
const isEditing = editingEntry?.id === result.id;
|
| 626 |
+
|
| 627 |
+
// Extract only sentences containing the search query for preview
|
| 628 |
const sentences = result.content.split(/[.!?]+/).filter((s: string) => s.trim());
|
| 629 |
const matchingSentences = sentences
|
| 630 |
.filter((s: string) => s.toLowerCase().includes(searchQuery.toLowerCase()))
|
| 631 |
+
.slice(0, 3)
|
| 632 |
.join('. ');
|
| 633 |
const displayContent = matchingSentences || result.content.substring(0, 200) + '...';
|
| 634 |
|
| 635 |
return (
|
| 636 |
<motion.div
|
| 637 |
+
key={result.id || idx}
|
| 638 |
initial={{ opacity: 0, y: 10 }}
|
| 639 |
animate={{ opacity: 1, y: 0 }}
|
| 640 |
transition={{ delay: idx * 0.05 }}
|
| 641 |
+
className={cn(
|
| 642 |
+
"p-4 bg-surface-elevated border rounded-xl transition-all relative overflow-hidden",
|
| 643 |
+
isEditing ? "border-indigo-500 ring-2 ring-indigo-500/20" : "border-white/10 hover:border-indigo-300"
|
| 644 |
+
)}
|
| 645 |
>
|
| 646 |
+
{isEditing ? (
|
| 647 |
+
// Inline editing mode
|
| 648 |
+
<div className="space-y-3">
|
| 649 |
+
<textarea
|
| 650 |
+
value={editingEntry.content}
|
| 651 |
+
onChange={(e) => setEditingEntry({ ...editingEntry, content: e.target.value })}
|
| 652 |
+
className="w-full min-h-[150px] p-3 bg-surface border border-white/10 rounded-lg text-sm text-white placeholder:text-slate-500 focus:ring-2 focus:ring-indigo-500/30 focus:border-indigo-500 transition-all resize-y"
|
| 653 |
+
placeholder="Редактируйте текст..."
|
| 654 |
+
autoFocus
|
| 655 |
+
/>
|
| 656 |
+
<div className="flex items-center justify-between">
|
| 657 |
+
<span className="text-xs text-slate-500">Нажмите Сохранить для применения изменений</span>
|
| 658 |
+
<div className="flex gap-2">
|
| 659 |
+
<button
|
| 660 |
+
onClick={() => setEditingEntry(null)}
|
| 661 |
+
className="px-3 py-1.5 text-sm text-slate-400 hover:text-white transition-colors"
|
| 662 |
+
>
|
| 663 |
+
Отмена
|
| 664 |
+
</button>
|
| 665 |
+
<button
|
| 666 |
+
onClick={() => updateMutation.mutate(editingEntry)}
|
| 667 |
+
disabled={updateMutation.isPending}
|
| 668 |
+
className="px-4 py-1.5 bg-indigo-600 hover:bg-indigo-700 text-white text-sm rounded-lg font-medium transition-colors disabled:opacity-50 flex items-center gap-2"
|
| 669 |
+
>
|
| 670 |
+
{updateMutation.isPending && <Loader2 className="w-3 h-3 animate-spin" />}
|
| 671 |
+
Сохранить
|
| 672 |
+
</button>
|
| 673 |
+
</div>
|
| 674 |
+
</div>
|
| 675 |
</div>
|
| 676 |
+
) : (
|
| 677 |
+
// View mode - click to edit
|
| 678 |
+
<>
|
| 679 |
+
<div
|
| 680 |
+
className="cursor-pointer group"
|
| 681 |
+
onClick={() => setEditingEntry({
|
| 682 |
+
id: result.id,
|
| 683 |
+
content: result.content,
|
| 684 |
+
category: result.category || ''
|
| 685 |
+
})}
|
| 686 |
+
>
|
| 687 |
+
<p className="text-sm text-slate-300 leading-relaxed mb-3 group-hover:text-white transition-colors">
|
| 688 |
+
{displayContent}
|
| 689 |
+
<span className="text-indigo-400 text-xs ml-2">(нажмите для редактирования)</span>
|
| 690 |
+
</p>
|
| 691 |
+
</div>
|
| 692 |
+
<div className="flex items-center justify-between text-xs">
|
| 693 |
+
<div className="flex items-center gap-2">
|
| 694 |
+
<span className="font-bold text-indigo-600 bg-indigo-500/20 px-2 py-1 rounded-md">
|
| 695 |
+
{((result.similarity || 0) * 100).toFixed(0)}% совпадение
|
| 696 |
+
</span>
|
| 697 |
+
<span className="text-slate-400 font-medium uppercase tracking-wide">
|
| 698 |
+
{result.category || 'Общее'}
|
| 699 |
+
</span>
|
| 700 |
+
</div>
|
| 701 |
+
</div>
|
| 702 |
+
</>
|
| 703 |
+
)}
|
| 704 |
</motion.div>
|
| 705 |
)
|
| 706 |
})}
|