diff --git a/components/publish/PublishWidget.vue b/components/publish/PublishWidget.vue index bd1aa953..dc2213d7 100644 --- a/components/publish/PublishWidget.vue +++ b/components/publish/PublishWidget.vue @@ -131,14 +131,19 @@ const expiresInOptions = computed(() => [ const expiresInDefaultOptionIndex = 2 const scheduledTime = ref('') -watchEffect(() => { - draft.value.params.scheduledAt = scheduledTime.value +const now = useNow({ interval: 1000 }) +const minimumScheduledTime = computed(() => getMinimumScheduledTime(now.value)) + +const isValidScheduledTime = computed(() => { + if (scheduledTime.value === '') + return true + + const scheduledTimeDate = new Date(scheduledTime.value) + return minimumScheduledTime.value.getTime() <= scheduledTimeDate.getTime() }) -const now = useNow({ interval: 1000 }) -const minimumScheduledTime = ref() watchEffect(() => { - minimumScheduledTime.value = getMinimumScheduledTime(now.value) + draft.value.params.scheduledAt = scheduledTime.value }) // Calculate the minimum scheduled time. @@ -146,13 +151,16 @@ watchEffect(() => { // but if the specified scheduled time is less than 5 minutes, Mastodon will // send the post immediately. // To prevent this, we add a buffer and round up the minutes. -function getMinimumScheduledTime(now: Date): string { +function getMinimumScheduledTime(now: Date): Date { const bufferInSec = 5 + 5 * 60 // + 5 minutes and 5 seconds const nowInSec = Math.floor(now.getTime() / 1000) const bufferedTimeInSec = Math.ceil((nowInSec + bufferInSec) / 60) * 60 - const minimumScheduledTime = new Date(bufferedTimeInSec * 1000) - return minimumScheduledTime.toISOString().slice(0, 16) + return new Date(bufferedTimeInSec * 1000) +} + +function getDatetimeInputFormat(time: Date) { + return time.toISOString().slice(0, 16) } const characterCount = computed(() => { @@ -326,9 +334,9 @@ function stopQuestionMarkPropagation(e: KeyboardEvent) {
{{ scheduledTime ? $t('state.schedule_failed') : $t('state.publish_failed') }}
-