Skip to content
This repository was archived by the owner on Jul 19, 2020. It is now read-only.

Commit

Permalink
feat: cache dimibob in localStorage (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
junhoyeo authored Jul 10, 2019
1 parent 222b72b commit d3f63de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import './assets/style.css';
Vue.prototype.$api = axios;
Vue.prototype.moment = moment;

/* eslint-disable no-new */
new Vue({
el: '#app',
render: h => h(App),
Expand Down
18 changes: 16 additions & 2 deletions src/pages/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,32 @@ export default {
},
async created() {
await this.getDimibob();
try {
const dimibob = await JSON.parse(localStorage.dimibob);
if (dimibob.timestamp !== this.moment().format('YYYYMMDD')) {
throw Error();
}
this.dimibob = dimibob;
} catch (err) {
await this.getDimibob();
}
this.getTimetable();
},
methods: {
async getDimibob() {
const today = this.moment().format('YYYYMMDD');
const { data: { breakfast, lunch, dinner } } = await this.$api.get(`https://dev-api.dimigo.in/dimibobs/${today}`);
console.log(breakfast);
this.dimibob.breakfast = breakfast || '์•„์นจ ๊ธ‰์‹ ์ •๋ณด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.';
this.dimibob.lunch = lunch || '์ ์‹ฌ ๊ธ‰์‹ ์ •๋ณด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.';
this.dimibob.dinner = dinner || '์ €๋… ๊ธ‰์‹ ์ •๋ณด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.';
localStorage.dimibob = JSON.stringify({
breakfast,
lunch,
dinner,
timestamp: this.moment().format('YYYYMMDD'),
});
},
getTimetable() {
Expand Down

0 comments on commit d3f63de

Please sign in to comment.