From aef24b65c7962e689567a177a32c373f7a49c019 Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Wed, 20 Aug 2025 22:51:14 +0900 Subject: [PATCH] feat: set initial scheduled post time and handle local-to-UTC conversion --- app/components/publish/PublishWidget.vue | 77 ++++++++++++++++++++---- 1 file changed, 65 insertions(+), 12 deletions(-) diff --git a/app/components/publish/PublishWidget.vue b/app/components/publish/PublishWidget.vue index 0244ba4f..86aeee2b 100644 --- a/app/components/publish/PublishWidget.vue +++ b/app/components/publish/PublishWidget.vue @@ -54,7 +54,16 @@ const { dropZoneRef, } = useUploadMediaAttachment(draft) -const { shouldExpanded, isExpanded, isSending, isPublishDisabled, publishDraft, failedMessages, preferredLanguage, publishSpoilerText } = usePublish( +const { + shouldExpanded, + isExpanded, + isSending, + isPublishDisabled, + publishDraft, + failedMessages, + preferredLanguage, + publishSpoilerText, +} = usePublish( { draftItem: draft, ...{ expanded: toRef(() => expanded), isUploading, initialDraft: initial, isPartOfThread: false }, @@ -145,6 +154,32 @@ const isValidScheduledTime = computed(() => { return minimumScheduledTime.value.getTime() <= scheduledTimeDate.getTime() }) +const initialDateTime = computed(() => { + const t = new Date(minimumScheduledTime.value.getTime()) + t.setHours(t.getHours() + 1) + t.setMinutes(0) + t.setSeconds(0) + t.setMilliseconds(0) + return t +}) + +watchEffect(() => { + // Convert the local datetime string from the input to a UTC ISO string for the API + if (scheduledTime.value) { + const localDate = new Date(scheduledTime.value) + draft.value.params.scheduledAt = localDate.toISOString() + } + else { + draft.value.params.scheduledAt = '' + } +}) + +function setInitialScheduledTime() { + if (scheduledTime.value === '') { + scheduledTime.value = getDatetimeInputFormat(initialDateTime.value) + } +} + watchEffect(() => { draft.value.params.scheduledAt = scheduledTime.value }) @@ -163,7 +198,15 @@ function getMinimumScheduledTime(now: Date): Date { } function getDatetimeInputFormat(time: Date) { - return time.toISOString().slice(0, 16) + // Returns string in 'YYYY-MM-DDTHH:MM' format using local time components + // This is the format expected by the element. + const year = time.getFullYear() + const month = (time.getMonth() + 1).toString().padStart(2, '0') + const day = time.getDate().toString().padStart(2, '0') + const hours = time.getHours().toString().padStart(2, '0') + const minutes = time.getMinutes().toString().padStart(2, '0') + + return `${year}-${month}-${day}T${hours}:${minutes}` } const characterCount = computed(() => { @@ -220,6 +263,7 @@ async function handlePaste(evt: ClipboardEvent) { function insertEmoji(name: string) { editor.value?.chain().focus().insertEmoji(name).run() } + function insertCustomEmoji(image: any) { editor.value?.chain().focus().insertCustomEmoji(image).run() } @@ -393,9 +437,13 @@ const detectLanguage = useDebounceFn(async () => { - +