Skip to content

Commit

Permalink
feat(TimePicker): recreate without library
Browse files Browse the repository at this point in the history
Signed-off-by: Grigory Vodyanov <scratchx@gmx.com>
  • Loading branch information
GVodyanov committed Oct 14, 2024
1 parent 490c2ad commit 36c58c1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 32 deletions.
9 changes: 9 additions & 0 deletions src/components/Editor/Properties/PropertyTitleTimePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
@change="changeEnd"
@change-timezone="changeEndTimezone" />
</div>
<TimePicker :initial-date="startDate" />
<div v-if="isReadOnly"
class="property-title-time-picker__time-pickers property-title-time-picker__time-pickers--readonly">
<div class="property-title-time-picker-read-only-wrapper property-title-time-picker-read-only-wrapper--start-date">
Expand Down Expand Up @@ -68,6 +69,7 @@
<script>
import moment from '@nextcloud/moment'
import DatePicker from '../../Shared/DatePicker.vue'
import TimePicker from '../../Shared/TimePicker.vue'
import IconTimezone from 'vue-material-design-icons/Web.vue'
import CalendarIcon from 'vue-material-design-icons/Calendar.vue'
import { NcCheckboxRadioSwitch } from '@nextcloud/vue'
Expand All @@ -78,6 +80,7 @@ export default {
name: 'PropertyTitleTimePicker',
components: {
DatePicker,
TimePicker,
IconTimezone,
CalendarIcon,
NcCheckboxRadioSwitch,
Expand Down Expand Up @@ -280,3 +283,9 @@ export default {
},
}
</script>

<style scoped>
:deep(.button-vue--icon-only), :deep(.button-vue__icon) {
width: 7rem !important;
}
</style>
69 changes: 37 additions & 32 deletions src/components/Shared/TimePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,54 @@
-->

<template>
<DateTimePicker ::clearable="false"
:first-day-of-week="firstDay"
:format="format"
:lang="lang"
:minute-step="5"
:show-second="false"
type="time"
:use12h="showAmPm"
:value="date"
v-bind="$attrs"
v-on="$listeners"
@change="change" />
<NcActions>
<template #icon>
<NcTextField :value.sync="date">
<template #trailing-button-icon>
<ClockOutline/>

Check failure on line 11 in src/components/Shared/TimePicker.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Expected a space before '/>', but not found
</template>
</NcTextField>
</template>
<NcActionButton v-for="time in timeList" :key="time" @click="change(parse(time))">
<template #icon></template>
{{ time }}
</NcActionButton>
</NcActions>
</template>

<script>
import { NcDateTimePicker as DateTimePicker } from '@nextcloud/vue'
import { NcActions, NcTextField, NcActionButton } from '@nextcloud/vue'
import ClockOutline from 'vue-material-design-icons/ClockOutline.vue'
import moment from '@nextcloud/moment'
import { mapState } from 'pinia'
import {
getFirstDay,
} from '@nextcloud/l10n'
import { getLangConfigForVue2DatePicker } from '../../utils/localization.js'
import useSettingsStore from '../../store/settings.js'
export default {
name: 'TimePicker',
components: {
DateTimePicker,
NcActions,
NcTextField,
NcActionButton,
ClockOutline,
},
props: {
date: {
initialDate: {

Check warning on line 38 in src/components/Shared/TimePicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Shared/TimePicker.vue#L38

Added line #L38 was not covered by tests
type: Date,
required: true,
},
},
data() {
return {
firstDay: getFirstDay() === 0 ? 7 : getFirstDay(),
format: {
stringify: this.stringify,
parse: this.parse,
},
date: '',

Check warning on line 45 in src/components/Shared/TimePicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Shared/TimePicker.vue#L45

Added line #L45 was not covered by tests
}
},
mounted() {
this.date = this.stringify(this.initialDate)

Check warning on line 49 in src/components/Shared/TimePicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Shared/TimePicker.vue#L49

Added line #L49 was not covered by tests
},
computed: {
...mapState(useSettingsStore, {
locale: 'momentLocale',
}),
/**
* Returns the lang config for vue2-datepicker
*
* @return {object}
*/
lang() {
return getLangConfigForVue2DatePicker(this.locale)
},
/**
* Whether or not to offer am/pm in the timepicker
*
Expand All @@ -71,6 +63,18 @@ export default {
return timeFormat.indexOf('a') !== -1
},
timeList() {
const times = []
let currentTime = moment(this.initialDate)

Check warning on line 69 in src/components/Shared/TimePicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Shared/TimePicker.vue#L68-L69

Added lines #L68 - L69 were not covered by tests
for (let i = 0; i < 10; i++) {
times.push(currentTime.format('LT'))
currentTime = currentTime.add(15, 'minutes')
}
return times
},

Check warning on line 77 in src/components/Shared/TimePicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Shared/TimePicker.vue#L77

Added line #L77 was not covered by tests
},
methods: {
/**
Expand All @@ -79,6 +83,7 @@ export default {
* @param {Date} date The new Date object
*/
change(date) {
this.date = this.stringify(date)

Check warning on line 86 in src/components/Shared/TimePicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Shared/TimePicker.vue#L86

Added line #L86 was not covered by tests
this.$emit('change', date)
},
/**
Expand Down

0 comments on commit 36c58c1

Please sign in to comment.