Skip to content

Commit a63fc10

Browse files
committed
feat: 메뉴 관련 localStorage 기능 추가 및 리팩토링
1 parent 015f492 commit a63fc10

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h1 class="text-3xl font-bold">🥤 자판기 🥤</h1>
3434
type="button"
3535
id="product-manage-menu"
3636
name="manager"
37-
class="button active"
37+
class="button"
3838
>
3939
상품 관리
4040
</button>

src/js/controller/vendingMachine.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@ import ChangeChargerModel from "../model/changeCharger.js";
44
import { $, $$ } from "../utils/selector.js";
55
import { ValidationError } from "../utils/error.js";
66
import { ERROR_MESSAGE } from "../utils/constants.js";
7-
import { validateChargerInput, validateManagerInputs } from "../utils/utils.js";
7+
import {
8+
getLocalStorage,
9+
setLocalStorage,
10+
validateChargerInput,
11+
validateManagerInputs,
12+
} from "../utils/utils.js";
813

914
class VendingMachineController {
1015
#currentModel;
1116
#models;
1217
#handlers;
1318

1419
constructor() {
15-
this.currentMenu = "manager";
20+
this.currentMenu = getLocalStorage("menu") || "manager";
1621

1722
const $menu = $("#menu");
23+
const $menuItem = $(`#menu button[name=${this.currentMenu}]`);
1824
const managerModel = new ProductManagerModel();
1925
const chargerModel = new ChangeChargerModel();
2026
const purchaseModel = new ProductPurchaseModel();
@@ -40,6 +46,7 @@ class VendingMachineController {
4046
this.#currentModel.initialize();
4147
this.#handlers[this.currentMenu]();
4248

49+
$menuItem.classList.add("active");
4350
$menu.addEventListener("click", this.menuHandler.bind(this));
4451
}
4552

@@ -112,6 +119,7 @@ class VendingMachineController {
112119
this.#currentModel = this.#models[$target.name];
113120

114121
$target.classList.add("active");
122+
setLocalStorage("menu", this.currentMenu);
115123
}
116124

117125
changeView($target) {

0 commit comments

Comments
 (0)