Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: actions/setup-node@v4
with:
Expand Down
28 changes: 25 additions & 3 deletions src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DocumentTextIcon,PlusIcon } from '@heroicons/react/24/outline';
import { DocumentTextIcon, MagnifyingGlassIcon, PlusIcon } from '@heroicons/react/24/outline';
import { useEffect,useState } from 'react';
import { useNavigate } from 'react-router-dom';

Expand All @@ -16,6 +16,7 @@ export function HomePage() {
const { notes, fetchNotes, deleteNote, createNote } = useNotes();
const [deleteModalOpen, setDeleteModalOpen] = useState(false);
const [noteToDelete, setNoteToDelete] = useState<Note | null>(null);
const [search, setSearch] = useState('');

const handleDelete = (note: Note) => {
setNoteToDelete(note);
Expand All @@ -33,6 +34,11 @@ export function HomePage() {
await createNote({ ...note, title: `${note.title} (copy)` });
};

const filteredNotes = notes.filter((note) => {
const q = search.toLowerCase();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable name is too small


Short variable names affect code readability and complicate code refactoring, because of the difficulty in searching and replacing such short characters.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable name is too small


Short variable names affect code readability and complicate code refactoring, because of the difficulty in searching and replacing such short characters.

return note.title?.toLowerCase().includes(q) || note.text?.toLowerCase().includes(q);
});

useEffect(() => {
const loadNotes = async () => {
setIsLoading(true);
Expand All @@ -58,7 +64,7 @@ export function HomePage() {

return (
<div className="min-h-screen p-6 max-w-6xl mx-auto">
<header className="flex items-center justify-between mb-8">
<header className="flex items-center justify-between mb-6">
<h1 className="text-3xl font-bold text-gray-900">Notes</h1>
<button
onClick={() => navigate('/edit/new')}
Expand All @@ -69,14 +75,30 @@ export function HomePage() {
</button>
</header>

<div className="relative mb-8">
<MagnifyingGlassIcon className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400" />
<input
type="text"
placeholder="Search notes..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="w-full pl-9 pr-4 py-2 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-300"
/>
</div>

{notes.length === 0 ? (
<div className="flex flex-col items-center justify-center py-20 text-gray-500">
<DocumentTextIcon className="w-16 h-16 mb-4" />
<p className="text-xl">No notes yet. Create one!</p>
</div>
) : filteredNotes.length === 0 ? (
<div className="flex flex-col items-center justify-center py-20 text-gray-500">
<MagnifyingGlassIcon className="w-16 h-16 mb-4" />
<p className="text-xl">No notes match your search.</p>
</div>
) : (
<div className="grid grid-cols-[repeat(auto-fit,minmax(280px,1fr))] gap-6">
{notes.map((note) => (
{filteredNotes.map((note) => (
<NoteCard
key={note.id}
note={note}
Expand Down
Loading