Skip to content

Conversation

@Akb98443
Copy link

@Akb98443 Akb98443 commented Oct 10, 2025

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

  • Added and Styled the Save icon with teal color and hover effects using Tailwind CSS.
  • Added validation in NoteEditor to prevent saving notes with empty title/content".
  • Updated createNote and updateNote functions to include validation and toast alerts.
  • Modified keyboard shortcut (Ctrl+S) to validate note before saving.

Why These Changes?

  • Prevents silent data loss by blocking invalid notes from being saved.
  • Improves user experience with clear feedback via toast alerts.
  • Ensures consistent validation across manual save, autosave, and keyboard shortcuts.

How to Test

  1. Try saving a note with empty title or content — you should see a warning toast.
  2. Press Ctrl+S with an invalid note — it should not save and show a toast.
  3. Click "Create Note" while editing an invalid note — it will not save the invalid note.
  4. Hover over the Save icon — it should change color as expected.

@vercel
Copy link

vercel bot commented Oct 10, 2025

@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.

@vercel
Copy link

vercel bot commented Oct 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
scratchpad-scribe Ready Ready Preview Comment Oct 14, 2025 5:42am

Copy link
Contributor

Copilot AI left a 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';
Copy link

Copilot AI Oct 14, 2025

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.

Suggested change
import { title } from 'process';

Copilot uses AI. Check for mistakes.
import { title } from 'process';
const STORAGE_KEY = 'notes-app-data';

//Add validation : Avanish
Copy link

Copilot AI Oct 14, 2025

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'.

Suggested change
//Add validation : Avanish
// Added validation : Avanish

Copilot uses AI. Check for mistakes.

const updateNote = (id: string, updates: Partial<Pick<Note, 'title' | 'content'>>) => {

//Validate fro the emppty title ans empty content : Avanish
Copy link

Copilot AI Oct 14, 2025

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'.

Suggested change
//Validate fro the emppty title ans empty content : Avanish
// Validate for the empty title and empty content : Avanish

Copilot uses AI. Check for mistakes.


if (!isValid && hasInteracted) {
toast.warning('Please use a non-Empty title and non-empty content to save your note.');
Copy link

Copilot AI Oct 14, 2025

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.

Suggested change
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.');

Copilot uses AI. Check for mistakes.
const trimmedContent = content.trim();

if (!trimmedTitle || !trimmedContent) {
toast.error('Cannot save: Content and Title can not be empty ');
Copy link

Copilot AI Oct 14, 2025

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.

Suggested change
toast.error('Cannot save: Content and Title can not be empty ');
toast.error('Cannot save: Content and Title cannot be empty.');

Copilot uses AI. Check for mistakes.
Comment on lines +40 to +41
const validNotes = notes.filter(isValidNote);
localStorage.setItem(STORAGE_KEY, JSON.stringify(validNotes));
Copy link

Copilot AI Oct 14, 2025

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.

Suggested change
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));

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Save Button to Complement Existing Keyboard Shortcut

2 participants