Skip to content

Commit 6875050

Browse files
localStorage mobile
1 parent 1ae6e31 commit 6875050

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

js/app.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,22 @@
3131

3232
$("#add-counter").addEventListener("click", function () {
3333
store.dispatch(addCounter());
34+
saveDataToLocalStorage();
3435
});
3536

3637
$("#remove-all-counters").addEventListener("click", function () {
3738
showModalConfirm({
3839
title: `Removing all counters...`,
3940
id: "",
40-
callback: () => store.dispatch(removeAllCounters()),
41+
callback: () => {
42+
store.dispatch(removeAllCounters());
43+
saveDataToLocalStorage();
44+
}
4145
});
4246
});
4347

4448
window.addEventListener("beforeunload", function (e) {
45-
saveDataToLocalStorage();
49+
//saveDataToLocalStorage();
4650
});
4751

4852
//reducers
@@ -253,10 +257,12 @@
253257
function setListeners() {
254258
listener(".counter__increment", "click", function (dataId) {
255259
store.dispatch(incrementCounter(dataId));
260+
saveDataToLocalStorage();
256261
});
257262

258263
listener(".counter__decrement", "click", function (dataId) {
259264
store.dispatch(decrementCounter(dataId));
265+
saveDataToLocalStorage();
260266
});
261267

262268
$$(".counter__reset").forEach((item) => {
@@ -266,7 +272,10 @@
266272
showModalConfirm({
267273
title: `Reseting ${getCounterName(dataId)}...`,
268274
id: dataId,
269-
callback: (_id) => store.dispatch(resetCounter(_id)),
275+
callback: (_id) => {
276+
store.dispatch(resetCounter(_id));
277+
saveDataToLocalStorage();
278+
},
270279
});
271280
});
272281
});
@@ -278,7 +287,10 @@
278287
showModalConfirm({
279288
title: `Removing ${getCounterName(dataId)}...`,
280289
id: dataId,
281-
callback: (_id) => store.dispatch(removeCounter(_id)),
290+
callback: (_id) => {
291+
store.dispatch(removeCounter(_id)),
292+
saveDataToLocalStorage();
293+
}
282294
});
283295
});
284296
});
@@ -362,6 +374,8 @@
362374
if (name) {
363375
store.dispatch(updateCounterName(id, obj.name));
364376
}
377+
378+
saveDataToLocalStorage();
365379
}
366380

367381
function getCounterName(id) {

0 commit comments

Comments
 (0)