Skip to content

Commit 02c4f78

Browse files
committed
feat: add attachment indicators to notes list and fix star toggle preservation
- Add paperclip badges showing attachment count in notes list - Display attachment count even when zero for consistency - Preserve local attachments field when updating notes from API responses
1 parent d43e824 commit 02c4f78

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

src/components/notes/NotesPanel/NoteCard.tsx

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { memo, useMemo } from 'react';
2-
import { Star } from 'lucide-react';
2+
import { Star, Paperclip } from 'lucide-react';
33
import type { Note, Folder as FolderType } from '@/types/note.ts';
44

55
interface NoteCardProps {
@@ -91,23 +91,29 @@ function NoteCard({
9191
>
9292
{note.title || 'Untitled'}
9393
</h3>
94-
<button
95-
onClick={(e) => {
96-
e.stopPropagation();
97-
onToggleStar(note.id);
98-
}}
99-
className={`shrink-0 rounded p-1 transition-opacity ${
100-
note.starred ? 'opacity-100' : 'opacity-0 group-hover:opacity-100'
101-
} hover:bg-muted`}
102-
>
103-
<Star
104-
className={`h-3.5 w-3.5 ${
105-
note.starred
106-
? 'fill-yellow-500 text-yellow-500'
107-
: 'text-muted-foreground'
108-
}`}
109-
/>
110-
</button>
94+
<div className="flex items-center gap-1">
95+
{note.attachments && note.attachments.length > 0 && (
96+
<div className="flex items-center gap-0.5 text-xs text-muted-foreground">
97+
<Paperclip className="h-3 w-3" />
98+
<span>{note.attachments.length}</span>
99+
</div>
100+
)}
101+
<button
102+
onClick={(e) => {
103+
e.stopPropagation();
104+
onToggleStar(note.id);
105+
}}
106+
className="shrink-0 rounded p-1 hover:bg-muted"
107+
>
108+
<Star
109+
className={`h-3.5 w-3.5 ${
110+
note.starred
111+
? 'fill-yellow-500 text-yellow-500'
112+
: 'text-muted-foreground'
113+
}`}
114+
/>
115+
</button>
116+
</div>
111117
</div>
112118

113119
<p
@@ -182,15 +188,4 @@ function NoteCard({
182188
);
183189
}
184190

185-
export default memo(NoteCard, (prevProps, nextProps) => {
186-
return (
187-
prevProps.note.id === nextProps.note.id &&
188-
prevProps.note.title === nextProps.note.title &&
189-
prevProps.note.content === nextProps.note.content &&
190-
prevProps.note.starred === nextProps.note.starred &&
191-
prevProps.note.updatedAt === nextProps.note.updatedAt &&
192-
prevProps.note.folderId === nextProps.note.folderId &&
193-
prevProps.isSelected === nextProps.isSelected &&
194-
prevProps.folders === nextProps.folders
195-
);
196-
});
191+
export default memo(NoteCard);

src/hooks/useNotes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,11 @@ export function useNotes() {
354354
const updatedNote = convertApiNote(apiNote);
355355

356356
setNotes((prev) =>
357-
prev.map((note) => (note.id === noteId ? updatedNote : note))
357+
prev.map((note) => (note.id === noteId ? { ...updatedNote, attachments: note.attachments } : note))
358358
);
359359

360360
if (selectedNote?.id === noteId) {
361-
setSelectedNote(updatedNote);
361+
setSelectedNote({ ...updatedNote, attachments: selectedNote.attachments });
362362
}
363363
} catch (error) {
364364
console.error('Failed to toggle star:', error);

0 commit comments

Comments
 (0)