Skip to content

Commit 0e50e0f

Browse files
committed
chore(TimePicker): revert to previous as no longer needed
Signed-off-by: Grigory Vodyanov <[email protected]>
1 parent bb244f6 commit 0e50e0f

File tree

1 file changed

+34
-80
lines changed

1 file changed

+34
-80
lines changed

src/components/Shared/TimePicker.vue

Lines changed: 34 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,62 @@
44
-->
55

66
<template>
7-
<NcActions :manual-open="true"
8-
:open="isListOpen"
9-
@click="isListOpen = !isListOpen">
10-
<template #icon>
11-
<NcTextField :value.sync="date" :error="isInvalidTime">
12-
<ClockOutline/>
13-
</NcTextField>
14-
</template>
15-
<NcActionButton v-for="time in timeList" :key="time" @click="changeFromList(parse(time))">
16-
<template #icon></template>
17-
{{ time }}
18-
</NcActionButton>
19-
</NcActions>
7+
<DateTimePicker ::clearable="false"
8+
:first-day-of-week="firstDay"
9+
:format="format"
10+
:lang="lang"
11+
:minute-step="5"
12+
:show-second="false"
13+
type="time"
14+
:use12h="showAmPm"
15+
:value="date"
16+
v-bind="$attrs"
17+
v-on="$listeners"
18+
@change="change" />
2019
</template>
2120

2221
<script>
23-
import { NcActions, NcTextField, NcActionButton } from '@nextcloud/vue'
24-
import ClockOutline from 'vue-material-design-icons/ClockOutline.vue'
22+
import { NcDateTimePicker as DateTimePicker } from '@nextcloud/vue'
2523
import moment from '@nextcloud/moment'
2624
import { mapState } from 'pinia'
25+
import {
26+
getFirstDay,
27+
} from '@nextcloud/l10n'
28+
import { getLangConfigForVue2DatePicker } from '../../utils/localization.js'
2729
import useSettingsStore from '../../store/settings.js'
2830
2931
export default {
3032
name: 'TimePicker',
3133
components: {
32-
NcActions,
33-
NcTextField,
34-
NcActionButton,
35-
ClockOutline,
34+
DateTimePicker,
3635
},
3736
props: {
38-
initialDate: {
37+
date: {
3938
type: Date,
4039
required: true,
4140
},
4241
},
4342
data() {
4443
return {
45-
date: '',
46-
isInvalidTime: false,
47-
isListOpen: false,
44+
firstDay: getFirstDay() === 0 ? 7 : getFirstDay(),
45+
format: {
46+
stringify: this.stringify,
47+
parse: this.parse,
48+
},
4849
}
4950
},
5051
computed: {
5152
...mapState(useSettingsStore, {
5253
locale: 'momentLocale',
5354
}),
55+
/**
56+
* Returns the lang config for vue2-datepicker
57+
*
58+
* @return {object}
59+
*/
60+
lang() {
61+
return getLangConfigForVue2DatePicker(this.locale)
62+
},
5463
/**
5564
* Whether or not to offer am/pm in the timepicker
5665
*
@@ -62,51 +71,14 @@ export default {
6271
6372
return timeFormat.indexOf('a') !== -1
6473
},
65-
66-
timeList() {
67-
const times = []
68-
let currentTime = moment(this.initialDate)
69-
70-
for (let i = 0; i < 10; i++) {
71-
times.push(currentTime.format('LT'))
72-
currentTime = currentTime.add(15, 'minutes')
73-
}
74-
75-
return times
76-
},
77-
},
78-
watch: {
79-
date(value) {
80-
let isValidTime = false
81-
isValidTime = !isValidTime ? moment(value, 'LT', true).isValid() : isValidTime
82-
isValidTime = !isValidTime ? moment(value, 'HH:mm', true).isValid() : isValidTime
83-
isValidTime = !isValidTime ? moment(value, 'H:mm', true).isValid() : isValidTime
84-
85-
// Meaning it was changed through textfield
86-
if (!(value instanceof Date) && isValidTime) {
87-
this.isInvalidTime = false
88-
89-
const parsedDate = this.parse(value)
90-
this.$emit('change', parsedDate)
91-
} else if (!(value instanceof Date)) {
92-
this.isInvalidTime = true
93-
}
94-
},
95-
},
96-
mounted() {
97-
this.date = this.stringify(this.initialDate)
9874
},
9975
methods: {
10076
/**
10177
* Emits a change event for the Date
10278
*
10379
* @param {Date} date The new Date object
10480
*/
105-
changeFromList(date) {
106-
this.isInvalidTime = false
107-
this.isListOpen = false
108-
109-
this.date = this.stringify(date)
81+
change(date) {
11082
this.$emit('change', date)
11183
},
11284
/**
@@ -125,26 +97,8 @@ export default {
12597
* @return {Date}
12698
*/
12799
parse(value) {
128-
try {
129-
return moment(value, 'LT', this.locale).toDate()
130-
} catch (e) {
131-
console.error(e)
132-
}
100+
return moment(value, 'LT', this.locale).toDate()
133101
},
134102
},
135103
}
136104
</script>
137-
138-
<style scoped>
139-
:deep(.action-button__icon) {
140-
display: none;
141-
}
142-
143-
:deep(.action-button__text) {
144-
margin: 0 8px;
145-
}
146-
147-
:deep(.input-field__icon--trailing) {
148-
display: none;
149-
}
150-
</style>

0 commit comments

Comments
 (0)