mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2024-12-27 09:29:10 +00:00
tag functionality
This commit is contained in:
parent
1718c7cedb
commit
c168d0f902
@ -73,10 +73,10 @@
|
|||||||
Restaurant:
|
Restaurant:
|
||||||
<input type="text" id="restaurant" name="restaurant" required>
|
<input type="text" id="restaurant" name="restaurant" required>
|
||||||
</label>
|
</label>
|
||||||
<label for="tags">
|
<label for="tag-form">
|
||||||
Tags:
|
Tags:
|
||||||
<input type="text" id="tags" name="tags" required>
|
<input type="text" id="tag-form" name="tag-form" required>
|
||||||
<div id="tag-container">
|
<div class='tag-container' id="tag-container-form">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<button type="button" id="tagAdd">Add Tag</button>
|
<button type="button" id="tagAdd">Add Tag</button>
|
||||||
|
@ -102,6 +102,7 @@ class ReviewCard extends HTMLElement {
|
|||||||
* "mealName": "string",
|
* "mealName": "string",
|
||||||
* "restaurant": "string",
|
* "restaurant": "string",
|
||||||
* "rating": number
|
* "rating": number
|
||||||
|
* "tags": string array
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
set data(data) {
|
set data(data) {
|
||||||
@ -138,10 +139,21 @@ class ReviewCard extends HTMLElement {
|
|||||||
div.append(span1);
|
div.append(span1);
|
||||||
div.append(img2);
|
div.append(img2);
|
||||||
|
|
||||||
|
//added tags
|
||||||
|
let tagContainer = document.createElement('div')
|
||||||
|
tagContainer.setAttribute('class', 'tag-container');
|
||||||
|
for (let i = 0; i < data['tags'].length; i++) {
|
||||||
|
let newTag = document.createElement('p');
|
||||||
|
newTag.setAttribute('class','tag');
|
||||||
|
newTag.innerHTML = data['tags'][i]
|
||||||
|
tagContainer.append(newTag)
|
||||||
|
}
|
||||||
|
|
||||||
articleEl.append(img1)
|
articleEl.append(img1)
|
||||||
articleEl.append(pMeal)
|
articleEl.append(pMeal)
|
||||||
articleEl.append(pRestaurant)
|
articleEl.append(pRestaurant)
|
||||||
articleEl.append(div)
|
articleEl.append(div)
|
||||||
|
articleEl.append(tagContainer)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
module.exports = {getReviewsFromStorage, saveReviewsToStorage};
|
//
|
||||||
|
//module.exports = {getReviewsFromStorage, saveReviewsToStorage};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Array<Object>} An array of reviews found in localStorage
|
* @returns {Array<Object>} An array of reviews found in localStorage
|
||||||
*/
|
*/
|
||||||
function getReviewsFromStorage() {
|
export function getReviewsFromStorage() {
|
||||||
let result = JSON.parse(localStorage.getItem('reviews'))
|
let result = JSON.parse(localStorage.getItem('reviews'))
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
@ -16,6 +17,6 @@ function getReviewsFromStorage() {
|
|||||||
* saves that string to 'reviews' in localStorage
|
* saves that string to 'reviews' in localStorage
|
||||||
* @param {Array<Object>} reviews An array of reviews
|
* @param {Array<Object>} reviews An array of reviews
|
||||||
*/
|
*/
|
||||||
function saveReviewsToStorage(reviews) {
|
export function saveReviewsToStorage(reviews) {
|
||||||
localStorage.setItem('reviews', JSON.stringify(reviews));
|
localStorage.setItem('reviews', JSON.stringify(reviews));
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
// main.js
|
// main.js
|
||||||
const {getReviewsFromStorage, saveReviewsToStorage} = require('./localStorage');
|
import {getReviewsFromStorage, saveReviewsToStorage} from './localStorage.js';
|
||||||
|
|
||||||
// Run the init() function when the page has loaded
|
// Run the init() function when the page has loaded
|
||||||
window.addEventListener('DOMContentLoaded', init);
|
window.addEventListener('DOMContentLoaded', init);
|
||||||
@ -31,14 +31,16 @@ function addReviewsToDocument(reviews) {
|
|||||||
* <button>.
|
* <button>.
|
||||||
*/
|
*/
|
||||||
function initFormHandler() {
|
function initFormHandler() {
|
||||||
let tagContainer = document.getElementById('tag-container');
|
//accessing form components
|
||||||
|
let tagContainer = document.getElementById('tag-container-form');
|
||||||
let theForm = document.querySelector('form')
|
let theForm = document.querySelector('form')
|
||||||
let submitButt = document.querySelector('button[type="submit"]')
|
let submitButt = document.querySelector('button[type="submit"]')
|
||||||
|
|
||||||
submitButt.addEventListener('click', function(){
|
submitButt.addEventListener('click', function(){
|
||||||
let deleteTags = document.querySelectorAll('.tag')
|
/*
|
||||||
for(let i = 0; i < deleteTags.length; i ++) {
|
* User submits the form for their review.
|
||||||
tagContainer.removeChild(deleteTags[i]);
|
* We create reviewCard and put in storage
|
||||||
}
|
*/
|
||||||
let formData = new FormData(theForm);
|
let formData = new FormData(theForm);
|
||||||
let reviewObject = {}
|
let reviewObject = {}
|
||||||
for (let [key, value] of formData) {
|
for (let [key, value] of formData) {
|
||||||
@ -46,7 +48,14 @@ function initFormHandler() {
|
|||||||
console.log(`${value}`)
|
console.log(`${value}`)
|
||||||
reviewObject[`${key}`] = `${value}`
|
reviewObject[`${key}`] = `${value}`
|
||||||
}
|
}
|
||||||
//console.log(reviewObject)
|
reviewObject['tags'] = []
|
||||||
|
|
||||||
|
let deleteTags = document.querySelectorAll('.tag')
|
||||||
|
for(let i = 0; i < deleteTags.length; i ++) {
|
||||||
|
reviewObject['tags'].push(deleteTags[i].innerHTML);
|
||||||
|
tagContainer.removeChild(deleteTags[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let newReview = document.createElement('review-card')
|
let newReview = document.createElement('review-card')
|
||||||
newReview.data = reviewObject
|
newReview.data = reviewObject
|
||||||
@ -78,10 +87,9 @@ function initFormHandler() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//allowing for tags selection/creation for user's review card
|
|
||||||
let tagAddButton = document.getElementById('tagAdd');
|
let tagAddButton = document.getElementById('tagAdd');
|
||||||
tagAddButton.addEventListener('click', ()=> {
|
tagAddButton.addEventListener('click', ()=> {
|
||||||
let tagField = document.getElementById('tags');
|
let tagField = document.getElementById('tag-form');
|
||||||
if (tagField.value.length > 0) {
|
if (tagField.value.length > 0) {
|
||||||
let p = document.createElement('p');
|
let p = document.createElement('p');
|
||||||
p.innerHTML = tagField.value;
|
p.innerHTML = tagField.value;
|
||||||
|
@ -4,13 +4,16 @@
|
|||||||
"imgAlt": "tacos pic",
|
"imgAlt": "tacos pic",
|
||||||
"mealName": "Birria Tacos",
|
"mealName": "Birria Tacos",
|
||||||
"restaurant": "Mike's Red Tacos",
|
"restaurant": "Mike's Red Tacos",
|
||||||
"rating": 5
|
"rating": 5,
|
||||||
|
"tags": ["delicious", "#worthit","omg"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"imgSrc": "https://www.redwormcomposting.com/images/worm-burrito.JPG",
|
"imgSrc": "https://www.redwormcomposting.com/images/worm-burrito.JPG",
|
||||||
"imgAlt": "wolftown pic",
|
"imgAlt": "wolftown pic",
|
||||||
"mealName": "Carnitas Burrito",
|
"mealName": "Carnitas Burrito",
|
||||||
"restaurant": "Wolftown UCSD",
|
"restaurant": "Wolftown UCSD",
|
||||||
"rating": 0
|
"rating": 0,
|
||||||
|
"tags": ["gross", "why","no"]
|
||||||
|
|
||||||
}
|
}
|
||||||
]
|
]
|
@ -47,6 +47,11 @@
|
|||||||
row-gap: 10px;
|
row-gap: 10px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tag-container {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row wrap;
|
||||||
|
}
|
||||||
.tag {
|
.tag {
|
||||||
background-color: grey;
|
background-color: grey;
|
||||||
border-radius: 7px;
|
border-radius: 7px;
|
||||||
@ -66,14 +71,14 @@
|
|||||||
color: white;
|
color: white;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
.tag:hover::before{
|
.tag:hover::before {
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
.danger {
|
.danger {
|
||||||
background-color: rgb(254, 171, 171);
|
background-color: rgb(254, 171, 171);
|
||||||
border-color: red;
|
border-color: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hidden {
|
.hidden {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user