Skip to content

Commit

Permalink
Frontend: fix the bug for search
Browse files Browse the repository at this point in the history
- in AddAReminder.tsx: add a alert for creating a total null-Reminder.
- in HomePage.tsx: Add  "if(!query) return true;"
  • Loading branch information
TingSHI2015 committed Jul 5, 2024
1 parent 918ed43 commit 59a9c0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 9 additions & 0 deletions frontend/src/components/AddAReminder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@ export default function AddAReminder(props: Readonly<AddAReminderProps>){

const handleNewReminderSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();

if (!newReminder.name && !newReminder.time && !newReminder.date){
alert("Reminder must have at least one non-null field!");
return;
}

props.saveAReminder(newReminder);
setNewReminder({id: "", name:"", time:"", date:""});
if(props.onClose){
props.onClose();
}

};

const onNewReminderChange = (event: ChangeEvent<HTMLInputElement>) =>{
setNewReminder({...newReminder, [event.target.name]: event.target.value})
}



return (
<form className="form-add-a-reminder" onSubmit={handleNewReminderSubmit}>
<input type="text" onChange={onNewReminderChange} value={newReminder.name} name={"name"}
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/page/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ export default function HomePage(props: Readonly<HomePageProps>){
console.log(props)

const filteredReminders = props.reminders.filter(
reminder =>
(reminder.name ? reminder.name.toLowerCase().includes(query.toLowerCase()): false) ||
(reminder.time ? reminder.time.toLowerCase().includes(query.toLowerCase()): false) ||
(reminder.date ? reminder.date.toString().toLowerCase().includes(query.toLowerCase()): false)
reminder =>{
if(!query) return true; //if no query, include all reminders
return(
(reminder.name ? reminder.name.toLowerCase().includes(query.toLowerCase()): false) ||
(reminder.time ? reminder.time.toLowerCase().includes(query.toLowerCase()): false) ||
(reminder.date ? reminder.date.toString().toLowerCase().includes(query.toLowerCase()): false)
)
}

)


Expand Down

0 comments on commit 59a9c0c

Please sign in to comment.