@@ -4,17 +4,23 @@ import ChangeChargerModel from "../model/changeCharger.js";
4
4
import { $ , $$ } from "../utils/selector.js" ;
5
5
import { ValidationError } from "../utils/error.js" ;
6
6
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" ;
8
13
9
14
class VendingMachineController {
10
15
#currentModel;
11
16
#models;
12
17
#handlers;
13
18
14
19
constructor ( ) {
15
- this . currentMenu = "manager" ;
20
+ this . currentMenu = getLocalStorage ( "menu" ) || "manager" ;
16
21
17
22
const $menu = $ ( "#menu" ) ;
23
+ const $menuItem = $ ( `#menu button[name=${ this . currentMenu } ]` ) ;
18
24
const managerModel = new ProductManagerModel ( ) ;
19
25
const chargerModel = new ChangeChargerModel ( ) ;
20
26
const purchaseModel = new ProductPurchaseModel ( ) ;
@@ -40,6 +46,7 @@ class VendingMachineController {
40
46
this . #currentModel. initialize ( ) ;
41
47
this . #handlers[ this . currentMenu ] ( ) ;
42
48
49
+ $menuItem . classList . add ( "active" ) ;
43
50
$menu . addEventListener ( "click" , this . menuHandler . bind ( this ) ) ;
44
51
}
45
52
@@ -112,6 +119,7 @@ class VendingMachineController {
112
119
this . #currentModel = this . #models[ $target . name ] ;
113
120
114
121
$target . classList . add ( "active" ) ;
122
+ setLocalStorage ( "menu" , this . currentMenu ) ;
115
123
}
116
124
117
125
changeView ( $target ) {
0 commit comments