refactor(Notes): update favorite filtering logic for clarity and consistency in NotesPageClient and NotesList components

This commit is contained in:
Julien Froidefond
2026-01-12 10:59:11 +01:00
parent 1ea76fed64
commit 1eef15f502
2 changed files with 18 additions and 10 deletions

View File

@@ -284,11 +284,14 @@ function NotesPageContent({
// Filtrer les notes par dossier
const filteredNotes =
selectedFolderId === '__favorites__'
? notes.filter((note) => note.isFavorite) // Notes favorites
? notes.filter((note) => note.isFavorite === true) // Notes favorites
: selectedFolderId === '__uncategorized__'
? notes.filter((note) => !note.folderId) // Notes sans dossier
: selectedFolderId
? notes.filter((note) => note.folderId === selectedFolderId)
? notes.filter((note) => {
// Gérer les cas où folderId pourrait être undefined ou null
return note.folderId === selectedFolderId;
})
: notes; // Toutes les notes
// Gérer le changement de dossier
@@ -299,7 +302,7 @@ function NotesPageContent({
// Sélectionner automatiquement la première note du dossier
const folderNotes =
folderId === '__favorites__'
? notes.filter((note) => note.isFavorite)
? notes.filter((note) => note.isFavorite === true)
: folderId === '__uncategorized__'
? notes.filter((note) => !note.folderId)
: folderId
@@ -422,7 +425,7 @@ function NotesPageContent({
availableTags={availableTags}
onNoteDrop={handleNoteDrop}
favoritesCount={
notes.filter((note) => note.isFavorite).length
notes.filter((note) => note.isFavorite === true).length
}
/>
</div>

View File

@@ -128,9 +128,14 @@ function SortableNoteItem({
<div className="flex-1 min-w-0">
<div className="flex items-start justify-between gap-2 mb-1">
<h3 className="font-medium text-sm text-[var(--foreground)] truncate">
{getNoteTitle(note.content)}
</h3>
<div className="flex items-center gap-1.5 flex-1 min-w-0">
{note.isFavorite === true && (
<Star className="w-3 h-3 text-[var(--accent)] fill-current flex-shrink-0" />
)}
<h3 className="font-medium text-sm text-[var(--foreground)] truncate">
{getNoteTitle(note.content)}
</h3>
</div>
{showDeleteConfirm === note.id ? (
<div className="flex gap-1">
<button
@@ -158,18 +163,18 @@ function SortableNoteItem({
onClick={handleToggleFavorite}
disabled={isPending}
className={`p-1 rounded-md transition-colors ${
note.isFavorite
note.isFavorite === true
? 'text-[var(--accent)] bg-[var(--accent)]/20'
: 'hover:bg-[var(--accent)]/20 text-[var(--muted-foreground)] hover:text-[var(--accent)]'
}`}
title={
note.isFavorite
note.isFavorite === true
? 'Retirer des favoris'
: 'Ajouter aux favoris'
}
>
<Star
className={`w-3 h-3 ${note.isFavorite ? 'fill-current' : ''}`}
className={`w-3 h-3 ${note.isFavorite === true ? 'fill-current' : ''}`}
/>
</button>
<button