chore: snapshot before performance optimization

This commit is contained in:
Sepehr Ramezani
2026-04-17 21:14:43 +02:00
parent b6a548acd8
commit 2eceb32fd4
95 changed files with 4357 additions and 1942 deletions

102
keep-notes/fix_dialog.py Normal file
View File

@@ -0,0 +1,102 @@
import re
with open('components/label-management-dialog.tsx', 'r') as f:
content = f.read()
# Add useNoteRefresh import
if 'useNoteRefresh' not in content:
content = content.replace("import { useLanguage } from '@/lib/i18n'", "import { useLanguage } from '@/lib/i18n'\nimport { useNoteRefresh } from '@/context/NoteRefreshContext'")
# Add useNoteRefresh to component
content = content.replace("const { t } = useLanguage()", "const { t } = useLanguage()\n const { triggerRefresh } = useNoteRefresh()\n const [confirmDeleteId, setConfirmDeleteId] = useState<string | null>(null)")
# Modify handleDeleteLabel
old_delete = """ const handleDeleteLabel = async (id: string) => {
if (confirm(t('labels.confirmDelete'))) {
try {
await deleteLabel(id)
} catch (error) {
console.error('Failed to delete label:', error)
}
}
}"""
new_delete = """ const handleDeleteLabel = async (id: string) => {
try {
await deleteLabel(id)
triggerRefresh()
setConfirmDeleteId(null)
} catch (error) {
console.error('Failed to delete label:', error)
}
}"""
content = content.replace(old_delete, new_delete)
# Also adding triggerRefresh() on addLabel and updateLabel:
content = content.replace(
"await addLabel(trimmed, 'gray')",
"await addLabel(trimmed, 'gray')\n triggerRefresh()"
)
content = content.replace(
"await updateLabel(id, { color })",
"await updateLabel(id, { color })\n triggerRefresh()"
)
# Inline confirm UI: Change the Trash2 button area
old_div = """ <div className="flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-muted-foreground hover:text-foreground"
onClick={() => setEditingColorId(isEditing ? null : label.id)}
title={t('labels.changeColor')}
>
<Palette className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-red-400 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-950/20"
onClick={() => handleDeleteLabel(label.id)}
title={t('labels.deleteTooltip')}
>
<Trash2 className="h-4 w-4" />
</Button>
</div>"""
new_div = """ {confirmDeleteId === label.id ? (
<div className="flex items-center gap-2">
<span className="text-xs text-red-500 font-medium">{t('labels.confirmDeleteShort') || 'Confirmer ?'}</span>
<Button variant="ghost" size="sm" className="h-7 px-2 text-xs" onClick={() => setConfirmDeleteId(null)}>
{t('common.cancel') || 'Annuler'}
</Button>
<Button variant="destructive" size="sm" className="h-7 px-2 text-xs" onClick={() => handleDeleteLabel(label.id)}>
{t('common.delete') || 'Supprimer'}
</Button>
</div>
) : (
<div className="flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-muted-foreground hover:text-foreground"
onClick={() => setEditingColorId(isEditing ? null : label.id)}
title={t('labels.changeColor')}
>
<Palette className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-red-400 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-950/20"
onClick={() => setConfirmDeleteId(label.id)}
title={t('labels.deleteTooltip')}
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
)}"""
content = content.replace(old_div, new_div)
with open('components/label-management-dialog.tsx', 'w') as f:
f.write(content)