summaryrefslogtreecommitdiff
path: root/packages/frontend/src/components/MkScheduleEditor.vue
blob: 1a6d5fd82dd002805d576e4b4082f5b692c2a025 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<div style="padding: 8px 16px;">
	<section>
		<MkInput v-model="atDate" small type="date" class="input">
			<template #label>{{ i18n.ts.postOn }}</template>
		</MkInput>
		<MkInput v-model="atTime" small type="time" class="input">
			<template #label>{{ i18n.ts._poll.deadlineTime }}</template>
		</MkInput>
	</section>
</div>
</template>

<script lang="ts" setup>
import { onMounted, ref, watch } from 'vue';
import moment from 'moment';
import MkInput from '@/components/MkInput.vue';
import { formatDateTimeString } from '@/utility/format-time-string.js';
import { addTime } from '@/utility/time.js';
import { i18n } from '@/i18n.js';

const props = defineProps<{
  modelValue: {
		scheduledAt: number | null;
  };
}>();

const emit = defineEmits<{
  (ev: 'update:modelValue', v: {
		scheduledAt: number | null;
  }): void;
}>();

const atDate = ref(formatDateTimeString(addTime(new Date(), 1, 'day'), 'yyyy-MM-dd'));
const atTime = ref('00:00');

if (props.modelValue.scheduledAt) {
	const date = new Date(props.modelValue.scheduledAt);
	atDate.value = formatDateTimeString(date, 'yyyy-MM-dd');
	atTime.value = formatDateTimeString(date, 'HH:mm');
}

function get() {
	const calcAt = () => {
		return moment(`${ atDate.value } ${ atTime.value }`).utc().valueOf();
	};

	return { scheduledAt: calcAt() };
}

watch([
	atDate,
	atTime,
], () => emit('update:modelValue', get()), {
	deep: true,
});

onMounted(() => {
	emit('update:modelValue', get());
});
</script>