-
-
Notifications
You must be signed in to change notification settings - Fork 48
Added the save button and Added validation for note title/content and toast alert #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@Akb998877 is attempting to deploy a commit to the Dhanush Nehru's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements comprehensive validation for note creation and editing, ensuring notes have non-empty titles and content before being saved. It introduces visual feedback through toast notifications and adds a new save button with proper styling.
- Added validation logic to prevent saving notes with empty titles or content
- Implemented toast notifications to provide user feedback when validation fails
- Added a styled save button with teal color scheme and hover effects
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/pages/Index.tsx | Added validation for keyboard shortcut save functionality |
| src/hooks/useNotes.ts | Implemented core validation logic and updated create/update functions |
| src/components/NoteEditor.tsx | Added save button, validation UI feedback, and interaction tracking |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| import { Note } from '@/types/note'; | ||
|
|
||
| import { toast } from "sonner"; | ||
| import { title } from 'process'; |
Copilot
AI
Oct 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import 'title' from 'process' module should be removed as it's not used anywhere in the code.
| import { title } from 'process'; |
| import { title } from 'process'; | ||
| const STORAGE_KEY = 'notes-app-data'; | ||
|
|
||
| //Add validation : Avanish |
Copilot
AI
Oct 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed grammatical error in comment from 'Add validation' to 'Added validation'.
| //Add validation : Avanish | |
| // Added validation : Avanish |
|
|
||
| const updateNote = (id: string, updates: Partial<Pick<Note, 'title' | 'content'>>) => { | ||
|
|
||
| //Validate fro the emppty title ans empty content : Avanish |
Copilot
AI
Oct 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple spelling errors in comment: 'fro' should be 'for', 'emppty' should be 'empty', and 'ans' should be 'and'.
| //Validate fro the emppty title ans empty content : Avanish | |
| // Validate for the empty title and empty content : Avanish |
|
|
||
|
|
||
| if (!isValid && hasInteracted) { | ||
| toast.warning('Please use a non-Empty title and non-empty content to save your note.'); |
Copilot
AI
Oct 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent capitalization: 'non-Empty' should be 'non-empty' to match the style used elsewhere.
| toast.warning('Please use a non-Empty title and non-empty content to save your note.'); | |
| toast.warning('Please use a non-empty title and non-empty content to save your note.'); |
| const trimmedContent = content.trim(); | ||
|
|
||
| if (!trimmedTitle || !trimmedContent) { | ||
| toast.error('Cannot save: Content and Title can not be empty '); |
Copilot
AI
Oct 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space at the end of the error message should be removed, and 'can not' should be 'cannot' for consistency.
| toast.error('Cannot save: Content and Title can not be empty '); | |
| toast.error('Cannot save: Content and Title cannot be empty.'); |
| const validNotes = notes.filter(isValidNote); | ||
| localStorage.setItem(STORAGE_KEY, JSON.stringify(validNotes)); |
Copilot
AI
Oct 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filtering out invalid notes during localStorage save can cause data loss. Invalid notes that users are actively editing will be permanently removed. Consider saving all notes but marking invalid ones differently.
| const validNotes = notes.filter(isValidNote); | |
| localStorage.setItem(STORAGE_KEY, JSON.stringify(validNotes)); | |
| // Save all notes, but mark invalid ones with an 'invalid' flag | |
| const notesToSave = notes.map(note => ({ | |
| ...note, | |
| invalid: !isValidNote(note), | |
| })); | |
| localStorage.setItem(STORAGE_KEY, JSON.stringify(notesToSave)); |
Summary
This PR introduces validation logic to ensure notes have a non-empty title and content before they are saved or created. It also adds toast notifications to inform users when actions are blocked due to invalid input.
Related Issue
Closes #65 #66
Changes Made
NoteEditorto prevent saving notes with empty title/content".createNoteandupdateNotefunctions to include validation and toast alerts.Ctrl+S) to validate note before saving.Why These Changes?
How to Test
Ctrl+Swith an invalid note — it should not save and show a toast.