From 8def7af70172c37b43f49d006cf32c60a298ca64 Mon Sep 17 00:00:00 2001 From: ssmucny Date: Thu, 20 Apr 2023 22:01:36 -0400 Subject: [PATCH] Add form to create events in UI --- .../frontend/src/components/MkEventEditor.vue | 183 ++++++++++++++++++ .../frontend/src/components/MkPostForm.vue | 39 +++- 2 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 packages/frontend/src/components/MkEventEditor.vue diff --git a/packages/frontend/src/components/MkEventEditor.vue b/packages/frontend/src/components/MkEventEditor.vue new file mode 100644 index 0000000000..ec7ee1cb2d --- /dev/null +++ b/packages/frontend/src/components/MkEventEditor.vue @@ -0,0 +1,183 @@ + + + + + diff --git a/packages/frontend/src/components/MkPostForm.vue b/packages/frontend/src/components/MkPostForm.vue index 42a3748d9a..16db1f0e20 100644 --- a/packages/frontend/src/components/MkPostForm.vue +++ b/packages/frontend/src/components/MkPostForm.vue @@ -49,6 +49,7 @@
{{ i18n.ts.quoteAttached }}
+
{{ i18n.ts.recipient }}
@@ -75,6 +76,7 @@
+ @@ -103,6 +105,7 @@ import MkNoteSimple from '@/components/MkNoteSimple.vue'; import MkNotePreview from '@/components/MkNotePreview.vue'; import XPostFormAttaches from '@/components/MkPostFormAttaches.vue'; import MkPollEditor from '@/components/MkPollEditor.vue'; +import MkEventEditor from '@/components/MkEventEditor.vue'; import { host, url } from '@/config'; import { erase, unique } from '@/scripts/array'; import { extractMentions } from '@/scripts/extract-mentions'; @@ -165,6 +168,12 @@ let poll = $ref<{ expiresAt: string | null; expiredAfter: string | null; } | null>(null); +let event = $ref<{ + title: string; + start: string; + end: string | null; + metadata: Record; +} | null>(null); let useCw = $ref(false); let showPreview = $ref(false); let cw = $ref(null); @@ -235,7 +244,7 @@ const maxTextLength = $computed((): number => { const canPost = $computed((): boolean => { return !posting && !posted && - (1 <= textLength || 1 <= files.length || !!poll || !!props.renote) && + (1 <= textLength || 1 <= files.length || !!poll || !!props.renote || !!event) && (textLength <= maxTextLength) && (!poll || poll.choices.length >= 2); }); @@ -331,6 +340,7 @@ function watchForDraft() { watch($$(useCw), () => saveDraft()); watch($$(cw), () => saveDraft()); watch($$(poll), () => saveDraft()); + watch($$(event), () => saveDraft()); watch($$(files), () => saveDraft(), { deep: true }); watch($$(visibility), () => saveDraft()); watch($$(localOnly), () => saveDraft()); @@ -375,6 +385,19 @@ function togglePoll() { } } +function toggleEvent() { + if (event) { + event = null; + } else { + event = { + title: '', + start: (new Date()).toString(), + end: null, + metadata: {}, + }; + } +} + function addTag(tag: string) { insertTextAtCursor(textareaEl, ` #${tag} `); } @@ -513,6 +536,7 @@ function clear() { text = ''; files = []; poll = null; + event = null; quoteId = null; } @@ -626,6 +650,7 @@ function saveDraft() { localOnly: localOnly, files: files, poll: poll, + event: event, }, }; @@ -687,6 +712,7 @@ async function post(ev?: MouseEvent) { renoteId: props.renote ? props.renote.id : quoteId ? quoteId : undefined, channelId: props.channel ? props.channel.id : undefined, poll: poll, + event: event, cw: useCw ? cw ?? '' : undefined, localOnly: localOnly, visibility: visibility, @@ -847,6 +873,9 @@ onMounted(() => { if (draft.data.poll) { poll = draft.data.poll; } + if (draft.data.event) { + event = draft.data.event; + } } } @@ -865,6 +894,14 @@ onMounted(() => { expiredAfter: init.poll.expiredAfter, }; } + if (init.event) { + event = { + title: init.event.title, + start: init.event.start, + end: init.event.end, + metadata: init.event.metadata, + }; + } visibility = init.visibility; localOnly = init.localOnly; quoteId = init.renote ? init.renote.id : null;