THE PROBLEM
This is not supposed to happen.
When the user searches for "elmo", a "big bird" design also comes up. Not ideal and effectively defeats the purpose of the whole search page.
DEBUGGING:
Backend server started:
Frontend Breakpoints set:
This is when the search button is clicked; code should check if Public or Private is selected
Below is the code that is supposed to handle the event that Public is selected
The first breakpoint makes the HTML table
The second breakpoint logs the name of the design found into the console
Backend Breakpoint set:
Red Cherry Tomato inserted at the beginning of the /api/users/search part of the code (called by the getPublic() frontend function)
Running frontend/step over:
The searchTerm is correctly logged and stored, so we know it's not an issue with differentiating between public/private searches
Now in the getPublic() function, fetching to backend ^^
Call to backend function worked without any issue. Continue with displayDataInTable ^^
now logging the names of the designs fetched from the backend ^^
After running through for each of the designs, these designs were logged in the console. The table is created, as expected, but returns "big bird" design even when only "elmo" was searched for.
We found the problem! The displayDataInTable function does absolutely nothing with searchTerm, so it returns everything (all the designs) that were fetched from the backend without any conditionals. Everything else works as normal (public/private, making table, getting/inserting data from backend into table).
Fixing the problem:
Added the line (conditional)
if (searchTerm && (item.Name.includes(searchTerm) || (item.Content && item.Content.includes(searchTerm))))
Removed previous breakpoints that worked fine, now logging all the designs that match the searchTerm
Stepped through the breakpoints. Found out that the conditional was tested twice (for each of the 2 designs in the database) but logging only occurred once (meaning the stuff inside the conditional only ran once), and this time the table was correct :)
THE PROBLEM This is not supposed to happen.
When the user searches for "elmo", a "big bird" design also comes up. Not ideal and effectively defeats the purpose of the whole search page.
DEBUGGING: Backend server started:![Screenshot-2024-03-05-at-10-53-20-PM.png](https://i.postimg.cc/rsMnD9x0/Screenshot-2024-03-05-at-10-53-20-PM.png)
Frontend Breakpoints set:
This is when the search button is clicked; code should check if Public or Private is selected
Below is the code that is supposed to handle the event that Public is selected
Backend Breakpoint set:
Red Cherry Tomato inserted at the beginning of the /api/users/search part of the code (called by the getPublic() frontend function)
Running frontend/step over:
The searchTerm is correctly logged and stored, so we know it's not an issue with differentiating between public/private searches
We found the problem! The displayDataInTable function does absolutely nothing with searchTerm, so it returns everything (all the designs) that were fetched from the backend without any conditionals. Everything else works as normal (public/private, making table, getting/inserting data from backend into table).
Fixing the problem:
Added the line (conditional)
if (searchTerm && (item.Name.includes(searchTerm) || (item.Content && item.Content.includes(searchTerm))))
Removed previous breakpoints that worked fine, now logging all the designs that match the searchTerm
Stepped through the breakpoints. Found out that the conditional was tested twice (for each of the 2 designs in the database) but logging only occurred once (meaning the stuff inside the conditional only ran once), and this time the table was correct :)![Screenshot-2024-03-06-at-9-27-16-PM.png](https://i.postimg.cc/kGHm4WnL/Screenshot-2024-03-06-at-9-27-16-PM.png)