Skip to content

Commit 8319d8f

Browse files
committed
Make DateListWindowImpl fire input event
1 parent bfc2b32 commit 8319d8f

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

src/components/CalendarBar.vue

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export type CalendarBarConfig = {
6565
export interface DateListWindow {
6666
list: Array<Date>
6767
currentDate: Date
68+
inputHandler: (value: Date) => Date
6869
selectDate(date: Date): DateListWindow
6970
nextDay(): DateListWindow
7071
prevDay(): DateListWindow
@@ -79,11 +80,13 @@ class DateListWindowImpl implements DateListWindow {
7980
startWeekOn: StartWeekOn
8081
currentDate: Date
8182
list: Array<Date>
83+
inputHandler: (value: Date) => Date
8284
8385
constructor(
8486
view: View = 'Week',
8587
startWeekOn: StartWeekOn = 'Monday',
86-
date: Date = new Date()
88+
date: Date = new Date(),
89+
inputHandler: (value: Date) => Date
8790
) {
8891
this.view = view
8992
this.startWeekOn = view === 'Weekday' ? 'Monday' : startWeekOn
@@ -96,6 +99,7 @@ class DateListWindowImpl implements DateListWindow {
9699
this.startWeekOn,
97100
this.currentDate
98101
)
102+
this.inputHandler = inputHandler
99103
}
100104
101105
nextDay(): DateListWindow {
@@ -128,6 +132,9 @@ class DateListWindowImpl implements DateListWindow {
128132
isValid(date) ? date : new Date()
129133
)
130134
this.list = this.generateDateList()
135+
136+
// CalendarBar を経由して変更を通知
137+
this.inputHandler(this.currentDate)
131138
return this
132139
}
133140
@@ -211,28 +218,18 @@ export default class CalendarBar extends Vue {
211218
dateListWindow: DateListWindow = new DateListWindowImpl(
212219
this.config?.view ?? 'Week',
213220
this.config?.startWeekOn ?? 'Monday',
214-
this.date ?? new Date()
221+
this.value ?? new Date(),
222+
this.input
215223
)
216224
217-
@Emit('changeCurrentDate')
218-
changeCurrentDate(): Date {
219-
return this.dateListWindow.currentDate
220-
}
221-
222-
private get date(): Date {
223-
return this.value
224-
}
225-
226225
@Emit()
227226
public input(value: Date) {
228227
return value
229228
}
230229
231-
@Watch('dateListWindow.currentDate', { immediate: true })
232-
// @Watch('dateListWindow.currentDate')
233-
onChangeCurrentDate() {
234-
this.input(this.dateListWindow.currentDate)
235-
this.changeCurrentDate()
230+
@Watch('value', { immediate: true })
231+
onValueChanged(newValue: Date) {
232+
this.dateListWindow.selectDate(newValue)
236233
}
237234
238235
get currentMonthString(): string {

src/layouts/classes.vue

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</v-btn>
1414
<template v-slot:extension>
1515
<div class="header-calender">
16-
<CalendarBar v-model="date" />
16+
<CalendarBar v-model="app.currentDate" />
1717
</div>
1818
</template>
1919
</v-app-bar>
@@ -33,7 +33,7 @@ import { vxm } from '@/store'
3333
3434
type LocalData = {
3535
loading: boolean
36-
date: Date
36+
app: typeof vxm.app
3737
}
3838
3939
export default Vue.extend({
@@ -45,12 +45,7 @@ export default Vue.extend({
4545
data(): LocalData {
4646
return {
4747
loading: true,
48-
date: new Date()
49-
}
50-
},
51-
watch: {
52-
date(value) {
53-
vxm.app.setDate(value)
48+
app: vxm.app
5449
}
5550
},
5651
mounted(): void {

src/layouts/protected.vue

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</div>
2222
<template v-slot:extension>
2323
<div class="header-calender">
24-
<CalendarBar v-model="date" />
24+
<CalendarBar v-model="app.currentDate" />
2525
</div>
2626
</template>
2727
</v-app-bar>
@@ -41,7 +41,7 @@ import CalendarBar from '@/components/CalendarBar.vue'
4141
4242
type LocalData = {
4343
loading: boolean
44-
date: Date
44+
app: typeof vxm.app
4545
}
4646
4747
export default Vue.extend({
@@ -53,12 +53,7 @@ export default Vue.extend({
5353
data(): LocalData {
5454
return {
5555
loading: true,
56-
date: new Date()
57-
}
58-
},
59-
watch: {
60-
date(value) {
61-
vxm.app.setDate(value)
56+
app: vxm.app
6257
}
6358
},
6459
mounted(): void {

0 commit comments

Comments
 (0)