File tree Expand file tree Collapse file tree 4 files changed +43
-1
lines changed
full-stack-dev/3-js-basic/18-proj-habit-tracker/18-5-loading-saving-data Expand file tree Collapse file tree 4 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 1+ [
2+ {
3+ "id" : 1 ,
4+ "icon" : " gantel-icon" ,
5+ "name" : " Отжимания" ,
6+ "target" : 10 ,
7+ "days" : [
8+ { "comment" : " Первый подход всегда даётся тяжело.." },
9+ { "comment" : " Второй день немного легче!" }
10+ ]
11+ },
12+ {
13+ "id" : 2 ,
14+ "icon" : " food-icon" ,
15+ "name" : " Правильное питание" ,
16+ "target" : 10 ,
17+ "days" : [{ "comment" : " Круто!" }]
18+ }
19+ ]
File renamed without changes.
Original file line number Diff line number Diff line change 2727 < li class ="sidebar__nav-item ">
2828 < button class ="sidebar__nav-btn sidebar__nav-btn_active " type ="button " aria-label ="Выбрать привычку "
2929 title ="Отжимания ">
30- < img class ="sidebar__nav-icon " src ="./images/gantle -icon.svg " width ="23 " height ="23 "
30+ < img class ="sidebar__nav-icon " src ="./images/gantel -icon.svg " width ="23 " height ="23 "
3131 alt ="Иконка: Гантеля ">
3232 </ button >
3333 </ li >
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ let habbits = [ ] ;
4+ const HABBITS_KEY = 'HABBITS' ;
5+
6+ // ** utility **
7+ function loadData ( ) {
8+ const habbitsStr = localStorage . getItem ( HABBITS_KEY ) ;
9+ const habbitsArr = JSON . parse ( habbitsStr ) ;
10+
11+ if ( Array . isArray ( habbitsArr ) ) {
12+ habbits = habbitsArr ;
13+ }
14+ }
15+
16+ function saveData ( ) {
17+ localStorage . setItem ( HABBITS_KEY , JSON . stringify ( habbits ) ) ;
18+ }
19+
20+ // загрузка данных.. по сути автоматическая/сразу (соответственно через IIFE)
21+ ( ( ) => {
22+ loadData ( ) ;
23+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments