Skip to content

Commit de2b9f0

Browse files
authored
Merge pull request #22 from codeforjapan/12-get-from-database
#12対応
2 parents e8c1735 + 3a6f867 commit de2b9f0

File tree

5 files changed

+160
-20
lines changed

5 files changed

+160
-20
lines changed

src/layouts/classes.vue

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<template>
2+
<v-app>
3+
<v-overlay v-if="loading" color="#F8F9FA" opacity="1" z-index="9999">
4+
<div class="loader">
5+
Loading
6+
</div>
7+
</v-overlay>
8+
<!--
9+
<v-navigation-drawer
10+
v-model="drawer"
11+
:mini-variant="miniVariant"
12+
:clipped="clipped"
13+
fixed
14+
app
15+
>
16+
<v-list>
17+
<v-list-item
18+
v-for="(item, i) in items"
19+
:key="i"
20+
:to="item.to"
21+
router
22+
exact
23+
>
24+
<v-list-item-action>
25+
<v-icon>{{ item.icon }}</v-icon>
26+
</v-list-item-action>
27+
<v-list-item-content>
28+
<v-list-item-title v-text="item.title" />
29+
</v-list-item-content>
30+
</v-list-item>
31+
</v-list>
32+
</v-navigation-drawer>
33+
-->
34+
<v-app-bar
35+
fixed
36+
app
37+
dense
38+
style="
39+
background-color: rgba(0, 0, 0, 0);
40+
color: white;
41+
text-align: center;
42+
"
43+
elevation="0"
44+
>
45+
<span>
46+
{{ schoolName }}
47+
</span>
48+
<v-spacer />
49+
<div class="date">
50+
<v-btn icon small dark @click="prevDate">
51+
<v-icon>mdi-chevron-left</v-icon>
52+
</v-btn>
53+
<v-btn text dark style="padding: 0 0;">
54+
{{ ViewDate }}
55+
</v-btn>
56+
<v-btn icon small dark @click="nextDate">
57+
<v-icon>mdi-chevron-right</v-icon>
58+
</v-btn>
59+
</div>
60+
<span>
61+
{{ className }}
62+
</span>
63+
</v-app-bar>
64+
<v-content style="background-color: #0071c2;">
65+
<v-container class="px-4 py-8">
66+
<nuxt />
67+
</v-container>
68+
</v-content>
69+
<v-footer dark color="#0071c2">
70+
<span>&copy; Code For Japan {{ new Date().getFullYear() }}</span>
71+
</v-footer>
72+
</v-app>
73+
</template>
74+
75+
<script>
76+
import { mapGetters, mapActions } from 'vuex'
77+
export default {
78+
middleware: 'checkClassData',
79+
computed: {
80+
...mapGetters('modules/class', ['schoolName', 'className', 'ViewDate']),
81+
},
82+
data() {
83+
return {
84+
loading: true,
85+
}
86+
},
87+
mounted() {
88+
this.loading = false
89+
this.setViewDate(this.$dayjs().format('YYYY-MM-DD'))
90+
},
91+
methods: {
92+
...mapActions('modules/class', ['setViewDate', 'prevDate', 'nextDate']),
93+
},
94+
}
95+
</script>
96+
97+
<style scoped>
98+
.date-icon {
99+
margin-right: 15px;
100+
}
101+
.date {
102+
position: absolute;
103+
top: 50%;
104+
left: 50%;
105+
transform: translate(-50%, -50%);
106+
}
107+
</style>

src/layouts/default.vue

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,28 @@
3131
</v-list>
3232
</v-navigation-drawer>
3333
-->
34-
<v-app-bar fixed app>
35-
<v-toolbar-title>
36-
4<ruby>年<rt>ねん</rt></ruby> 3<ruby>組<rt>くみ</rt></ruby>
37-
</v-toolbar-title>
34+
<v-app-bar
35+
fixed
36+
app
37+
dense
38+
style="
39+
background-color: rgba(0, 0, 0, 0);
40+
color: white;
41+
text-align: center;
42+
"
43+
elevation="10"
44+
>
45+
<v-spacer />
46+
<v-btn icon dark>
47+
<v-icon>mdi-chevron-left</v-icon>
48+
</v-btn>
49+
<v-btn text dark>
50+
2020 / 05 / 14
51+
</v-btn>
52+
<v-btn icon dark>
53+
<v-icon>mdi-chevron-right</v-icon>
54+
</v-btn>
3855
<v-spacer />
39-
<Calender class="date-icon" />
40-
<v-toolbar-title>
41-
4<ruby>月<rt>がつ</rt></ruby> 3<ruby>日<rt>か</rt></ruby>
42-
</v-toolbar-title>
4356
</v-app-bar>
4457
<v-content style="background-color: #0071c2;">
4558
<v-container class="px-4 py-8">
@@ -53,11 +66,7 @@
5366
</template>
5467

5568
<script>
56-
import Calender from '@/assets/svgs/icon_calender.svg'
5769
export default {
58-
components: {
59-
Calender,
60-
},
6170
data() {
6271
return {
6372
loading: true,

src/pages/classes/index.vue

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="MainPage">
33
<v-row class="DataBlock">
4-
<v-col v-for="(item, i) in Lessons[today]" :key="i" cols="12" md="6">
4+
<v-col v-for="(item, i) in Lessons[ViewDate]" :key="i" cols="12" md="6">
55
<StudyCard
66
:schooltime="i + 1"
77
:realtime="item.realTime"
@@ -18,14 +18,9 @@ import { mapGetters } from 'vuex'
1818
import StudyCard from '@/components/StudyCard'
1919
export default {
2020
components: { StudyCard },
21-
middleware: 'checkClassData',
21+
layout: 'classes',
2222
computed: {
23-
...mapGetters('modules/class', ['Lessons']),
24-
},
25-
data() {
26-
return {
27-
today: this.$dayjs().format('YYYY-MM-DD'),
28-
}
23+
...mapGetters('modules/class', ['Lessons', 'ViewDate']),
2924
},
3025
}
3126
</script>

src/plugins/firebase.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const firebaseConfig = {
1414

1515
if (!firebase.apps.length) {
1616
firebase.initializeApp(firebaseConfig)
17+
firebase.firestore().enablePersistence({
18+
synchronizeTabs: true,
19+
})
1720
}
1821

1922
export default firebase

src/store/modules/class.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import firebase from '@/plugins/firebase'
22
export const state = () => ({
33
classId: '',
44
classData: {},
5+
ViewDate: '',
56
})
67

78
export const getters = {
@@ -20,6 +21,9 @@ export const getters = {
2021
Lessons(state) {
2122
return state.classData.Lessons
2223
},
24+
ViewDate(state) {
25+
return state.ViewDate
26+
},
2327
isLoadedClassData: (state) => {
2428
return state.classId !== ''
2529
},
@@ -32,6 +36,19 @@ export const mutations = {
3236
setClassId(state, classId) {
3337
state.classId = classId
3438
},
39+
setViewDate(state, date) {
40+
state.ViewDate = date
41+
},
42+
nextDate(state) {
43+
state.ViewDate = this.$dayjs(state.ViewDate)
44+
.add(1, 'd')
45+
.format('YYYY-MM-DD')
46+
},
47+
prevDate(state) {
48+
state.ViewDate = this.$dayjs(state.ViewDate)
49+
.subtract(1, 'd')
50+
.format('YYYY-MM-DD')
51+
},
3552
}
3653

3754
export const actions = {
@@ -52,6 +69,15 @@ export const actions = {
5269
setClassId({ commit }, classId) {
5370
commit('setClassId', classId)
5471
},
72+
setViewDate({ commit }, date) {
73+
commit('setViewDate', date)
74+
},
75+
prevDate({ commit }) {
76+
commit('prevDate')
77+
},
78+
nextDate({ commit }) {
79+
commit('nextDate')
80+
},
5581
isLoadedClassData: (state) => {
5682
return state.classData !== {}
5783
},

0 commit comments

Comments
 (0)