Skip to content

Commit 59ef12e

Browse files
committed
Fix loading hazard info list
1 parent 3c4196a commit 59ef12e

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

2wr-app/src/api/hazard-info-api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import baseApiInstance from './base-api-instance';
22

33
export default {
4-
async createPhoto(photo) {
5-
return (await baseApiInstance.getInstance()).post('photos', photo);
4+
async getAll() {
5+
return (await baseApiInstance.getInstance()).get('hazardinfo-list');
66
},
77
};

2wr-app/src/store/modules/prepare/hazards/hazard-info-store.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,29 @@ export default {
1616
},
1717
actions: {
1818
async getHazardInfosAsync({ commit, rootState }) {
19-
if (rootState.globalStore.online) {
20-
let response = await api.getDocuments();
21-
commit(SET_LIST, response.data);
22-
await localForage.setItem(CACHE_KEY, response.data);
23-
} else {
24-
var data = await localForage.getItem(CACHE_KEY)
25-
if (data) {
26-
console.log("Serving from cache");
27-
commit(SET_LIST, data);
19+
20+
try {
21+
commit("setBusy", null, { root: true });
22+
commit("setError", "", { root: true });
23+
24+
if (rootState.globalStore.online) {
25+
let response = await api.getAll();
26+
commit(SET_LIST, response.data);
27+
await localForage.setItem(CACHE_KEY, response.data);
2828
} else {
29-
console.log("Offline without data");
29+
var data = await localForage.getItem(CACHE_KEY)
30+
if (data) {
31+
console.log("Serving from cache");
32+
commit(SET_LIST, data);
33+
} else {
34+
console.log("Offline without data");
35+
}
3036
}
31-
32-
}
37+
} catch {
38+
commit("setError", "Could not load harzard information.", { root: true });
39+
} finally {
40+
commit("clearBusy", null, { root: true });
41+
}
3342
}
3443
}
3544
};

0 commit comments

Comments
 (0)