mirror of
				https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
				synced 2025-10-31 03:46:50 +00:00 
			
		
		
		
	add clear search and no result
This commit is contained in:
		| @@ -164,7 +164,10 @@ function addTagsToStorage(ID, addedTags) { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // legacy function | ||||
| /** | ||||
|  * Test Helper Function to get all reviews from local storage | ||||
|  * @returns {Object} all active reviews from local storage | ||||
|  */ | ||||
| export function getAllReviewsFromStorage() { | ||||
| 	if (!(localStorage.getItem("activeIDS"))) { | ||||
| 		// we wanna init the active ID array and start the nextID count | ||||
| @@ -182,8 +185,8 @@ export function getAllReviewsFromStorage() { | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Get all IDs of active reviews | ||||
|  * @returns {number[]} list of all active IDs | ||||
|  * Get all IDs of active reviews (order: most recent) | ||||
|  * @returns {number[]} list of all active IDs by recency | ||||
|  */ | ||||
| export function getIDsFromStorage() { | ||||
| 	if (!(localStorage.getItem("activeIDS"))) { | ||||
| @@ -192,17 +195,20 @@ export function getIDsFromStorage() { | ||||
| 		localStorage.setItem("nextID",  JSON.stringify(0)); | ||||
| 	} | ||||
| 	let activeIDS = JSON.parse(localStorage.getItem("activeIDS")); | ||||
| 	return activeIDS; | ||||
| 	return activeIDS.reverse(); | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Returns all review IDs which contain the same tag specified.  | ||||
|  * Returns all review IDs which contain the same tag specified (order: most recent) | ||||
|  * @param {string} tag to filter by | ||||
|  * @returns {number[]} list of IDs of reviews that all contain the specified tag | ||||
|  * @returns {number[]} list of IDs of reviews that all contain the specified tag by recency | ||||
|  */ | ||||
| export function getIDsByTag(tag) { | ||||
| 	let tagArr = JSON.parse(localStorage.getItem("!" + tag.toLowerCase())); | ||||
| 	return tagArr; | ||||
| 	if(!tagArr){ | ||||
| 		tagArr = []; | ||||
| 	} | ||||
| 	return tagArr.reverse(); | ||||
| } | ||||
|  | ||||
| /** | ||||
|   | ||||
| @@ -42,6 +42,14 @@ function initFormHandler() { | ||||
| 		sortAndFilter(searchTag); | ||||
| 	}); | ||||
|  | ||||
| 	//for clearing tag filter | ||||
| 	let clearSearchBtn = document.getElementById("clear-search"); | ||||
| 	clearSearchBtn.addEventListener("click", function(){ | ||||
| 		searchTag = null; | ||||
| 		searchField.value = ""; | ||||
| 		sortAndFilter(searchTag); | ||||
| 	}) | ||||
|  | ||||
| 	//sort by selected method | ||||
| 	let sortMethod = document.getElementById("sort"); | ||||
| 	sortMethod.addEventListener("input", function(){ | ||||
| @@ -74,7 +82,7 @@ function sortAndFilter(searchTag){ | ||||
| 			reviewIDs = getIDsFromStorage(); | ||||
| 		} | ||||
| 		//reversed for recency | ||||
| 		loadReviews(0, reviewIDs.reverse()); | ||||
| 		loadReviews(0, reviewIDs); | ||||
| 	}  | ||||
| 	//sort method: top rated | ||||
| 	else if (sortMethod.value == "top"){ | ||||
| @@ -98,6 +106,18 @@ function sortAndFilter(searchTag){ | ||||
|  */ | ||||
| function loadReviews(index, reviewIDs){ | ||||
| 	let reviewBox = document.getElementById("review-container"); | ||||
| 	// label if there are no reviews to display | ||||
| 	if(reviewIDs.length == 0){ | ||||
| 		let emptyLabel = document.createElement("label"); | ||||
| 		emptyLabel.setAttribute("id", "empty"); | ||||
| 		emptyLabel.innerText = "No Reviews To Display"; | ||||
| 		reviewBox.append(emptyLabel); | ||||
| 	} else { | ||||
| 		let emptyLabel = document.getElementById("empty"); | ||||
| 		if(emptyLabel){ | ||||
| 			reviewBox.removeChild(emptyLabel); | ||||
| 		} | ||||
| 	} | ||||
| 	let moreBtn = document.getElementById("more-btn"); | ||||
| 	//delete load more button if exists | ||||
| 	if(moreBtn){ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user