diff --git a/README.md b/README.md index 98e7dfae..603ff6cf 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,10 @@
+# 카라멜 팝콘 +## 팝콘, 신다혜, 킹지,안수경, 민오, 선리 + + ## 🔥 Projects!

diff --git a/index.html b/index.html index ebac1c4c..e1b41e7f 100644 --- a/index.html +++ b/index.html @@ -52,7 +52,7 @@

🌝 문벅스 메뉴 관리

-

☕ 에스프레소 메뉴 관리

+

☕ 에스프레소 메뉴 관리

총 0개
@@ -65,11 +65,11 @@

☕ 에스프레소 메뉴 관리

id="espresso-menu-name" name="espressoMenuName" class="input-field" - placeholder="에스프레소 메뉴 이름" + placeholder="메뉴 이름" autocomplete="off" /> + + + `; + } + const updateTotalCount = () => { + const menuCount = $('#espresso-menu-list').childElementCount; + $('.menu-count').innerText = `총 ${menuCount}개` + } + const updateMenu = (e) => { + const $targetList = e.target.closest('li'); + + const $menuName = $targetList.querySelector(".menu-name"); + let updatedMenu = prompt('메뉴명을 수정하세요.', $menuName.innerText) ?? ''; + updatedMenu = updatedMenu.trim().length > 0 ? updatedMenu : $menuName.innerText; + $menuName.innerText = updatedMenu; + + //localStorage변경 + updateStoreMenu(getTargetIndex($targetList),{name : updatedMenu}, currentCategory); + + } + const removeMenu = (e) => { + const wantDelete = confirm('정말 삭제하시겠습니까?'); + if(wantDelete){ + const $targetList = e.target.closest('li'); + + removeStoreMenu(getTargetIndex($targetList), currentCategory); + + $targetList.remove(); + updateTotalCount(); + } + } + const soldOutMenu = (e) => { + const $targetList = e.target.closest('li'); + const index = getTargetIndex($targetList); + const menu = fetchMenu(); + const targetItem = menu[currentCategory][index]; + + let soldOut = !targetItem.hasOwnProperty('soldOut') ? true : targetItem.soldOut ? false : true; + + soldOut ? $targetList.children[0].classList.add('sold-out') : $targetList.children[0].classList.remove('sold-out'); + + const storeTemplate = {...targetItem, soldOut}; + updateStoreMenu(index, storeTemplate, currentCategory); + + } + const getTargetIndex = (selectedItem) => { + const $menuItems = Array.from(selectedItem.closest('ul').children); + return $menuItems.indexOf(selectedItem); + } + const setSavedMenu = (category) => { + currentCategory = category; + const menu = fetchMenu(); + menu[currentCategory].forEach(menu => { + addMenu(menu); + }); + updateTotalCount(); + } + const handleCategory = (e) => { + clearListMenu(); + setSavedMenu(e.target.dataset.categoryName) + const categoryName = e.target.innerText; + const $headingChild = $('.heading').children; + + for(let index = 0; index < $headingChild.length; index++ ){ + if($headingChild[index].classList.contains('heading-title')){ + $headingChild[index].innerText = `${categoryName} 메뉴 관리`; + $('.input-label').innerText = `${categoryName.substring(2)} 메뉴 이름`; + } + } + }; + const clearListMenu = () => { + while($('#espresso-menu-list').hasChildNodes()){ + $('#espresso-menu-list').removeChild($('#espresso-menu-list').firstChild); + } + } + + const setCategoryEvent = () => { + const $categorys = document.querySelectorAll('.cafe-category-name'); + $categorys.forEach(category => { + category.addEventListener('click', handleCategory); + }); + } + + setSavedMenu('espresso'); + setCategoryEvent(); + + $('#espresso-menu-form').addEventListener('submit', submitMenu); + $('#espresso-menu-list').addEventListener('click', (e)=> { + if(e.target.classList.contains('menu-edit-button')){ + updateMenu(e); + } + if(e.target.classList.contains('menu-remove-button')){ + removeMenu(e); + } + if(e.target.classList.contains('menu-sold-out-button')){ + soldOutMenu(e); + } + }); + +} + +App(); diff --git a/src/js/store/index.js b/src/js/store/index.js new file mode 100644 index 00000000..29dad39f --- /dev/null +++ b/src/js/store/index.js @@ -0,0 +1,40 @@ + const defaultMenuCategory = { + espresso : [], + frappuccino: [], + blended: [], + teavana: [], + desert: [] + } + +export function fetchMenu() { + let menuItem = JSON.parse(localStorage.getItem("menu")); + if(!menuItem) { + menuItem = defaultMenuCategory + localStorage.menu = JSON.stringify(menuItem); + }; + + return menuItem; +} + +export function storeMenu(menu, category) { + let savedMenus = JSON.parse(localStorage.getItem('menu')); + savedMenus[category].push({name : menu}); + localStorage.menu = JSON.stringify(savedMenus); +} + +export function removeStoreMenu(index, category){ + const savedMenus = JSON.parse(localStorage.getItem('menu')); + savedMenus[category].splice(index,1); + localStorage.menu = JSON.stringify(savedMenus); +} + +export function updateStoreMenu(index,item, category){ + const savedMenus = JSON.parse(localStorage.getItem('menu')); + savedMenus[category][index] = item; + localStorage.menu = JSON.stringify(savedMenus); +} + +export function updateSoldOutInfoMenu(index, category){ + const savedMenus = JSON.parse(localStorage.getItem('menu')); + +} \ No newline at end of file