2024-04-27 09:04:02 +02:00
|
|
|
<template>
|
2024-06-05 02:03:15 +02:00
|
|
|
<div v-if="respondingTo" class="mb-4">
|
|
|
|
|
<OverlayScrollbarsComponent :defer="true" class="max-h-72 overflow-y-auto">
|
|
|
|
|
<LazySocialElementsNotesNote :note="respondingTo" :small="true" :disabled="true"
|
|
|
|
|
class="!rounded-none !bg-pink-500/10" />
|
|
|
|
|
</OverlayScrollbarsComponent>
|
|
|
|
|
</div>
|
2024-06-06 03:35:09 +02:00
|
|
|
<div class="px-6 pb-4 pt-5">
|
2024-06-05 02:03:15 +02:00
|
|
|
<div class="pb-2 relative">
|
2024-05-12 06:34:03 +02:00
|
|
|
<textarea :disabled="submitting" ref="textarea" v-model="content" :placeholder="chosenSplash"
|
2024-06-06 03:35:09 +02:00
|
|
|
@paste="handlePaste"
|
2024-04-27 09:04:02 +02:00
|
|
|
class="resize-none min-h-48 prose prose-invert max-h-[70dvh] w-full p-0 focus:!ring-0 !ring-none !border-none !outline-none placeholder:text-zinc-500 bg-transparent appearance-none focus:!border-none focus:!outline-none disabled:cursor-not-allowed"></textarea>
|
|
|
|
|
<div
|
|
|
|
|
:class="['absolute bottom-0 right-0 p-2 text-gray-400 font-semibold text-xs', remainingCharacters < 0 && 'text-red-500']">
|
|
|
|
|
{{ remainingCharacters }}
|
|
|
|
|
</div>
|
2024-05-17 08:25:59 +02:00
|
|
|
<ComposerEmojiSuggestbox :currently-typing-emoji="currentlyBeingTypedEmoji"
|
|
|
|
|
@autocomplete="autocompleteEmoji" />
|
2024-04-27 09:04:02 +02:00
|
|
|
</div>
|
2024-05-12 06:34:03 +02:00
|
|
|
<!-- Content warning textbox -->
|
2024-05-13 05:44:32 +02:00
|
|
|
<div v-if="cw" class="mb-4">
|
2024-05-13 05:19:53 +02:00
|
|
|
<input type="text" v-model="cwContent" placeholder="Add a content warning"
|
2024-05-12 06:34:03 +02:00
|
|
|
class="w-full p-2 mt-1 text-sm prose prose-invert bg-dark-900 rounded focus:!ring-0 !ring-none !border-none !outline-none placeholder:text-zinc-500 appearance-none focus:!border-none focus:!outline-none" />
|
|
|
|
|
</div>
|
2024-06-06 03:35:09 +02:00
|
|
|
<ComposerFileUploader v-model:files="files" ref="uploader" />
|
2024-04-27 09:04:02 +02:00
|
|
|
<div class="flex flex-row gap-1 border-white/20">
|
2024-05-12 06:34:03 +02:00
|
|
|
<ComposerButton title="Mention someone">
|
2024-05-12 11:04:00 +02:00
|
|
|
<iconify-icon height="1.5rem" width="1.5rem" icon="tabler:at" aria-hidden="true" />
|
2024-05-12 06:34:03 +02:00
|
|
|
</ComposerButton>
|
|
|
|
|
<ComposerButton title="Toggle Markdown" @click="markdown = !markdown" :toggled="markdown">
|
2024-05-12 11:04:00 +02:00
|
|
|
<iconify-icon width="1.25rem" height="1.25rem"
|
|
|
|
|
:icon="markdown ? 'tabler:markdown' : 'tabler:markdown-off'" aria-hidden="true" />
|
2024-05-12 06:34:03 +02:00
|
|
|
</ComposerButton>
|
|
|
|
|
<ComposerButton title="Use a custom emoji">
|
2024-05-12 11:04:00 +02:00
|
|
|
<iconify-icon width="1.25rem" height="1.25rem" icon="tabler:mood-smile" aria-hidden="true" />
|
2024-05-12 06:34:03 +02:00
|
|
|
</ComposerButton>
|
2024-06-06 03:35:09 +02:00
|
|
|
<ComposerButton title="Add media" @click="openFilePicker">
|
2024-05-12 11:04:00 +02:00
|
|
|
<iconify-icon width="1.25rem" height="1.25rem" icon="tabler:photo-up" aria-hidden="true" />
|
2024-05-12 06:34:03 +02:00
|
|
|
</ComposerButton>
|
2024-06-06 03:35:09 +02:00
|
|
|
<ComposerButton title="Add a file" @click="openFilePicker">
|
2024-05-12 11:04:00 +02:00
|
|
|
<iconify-icon width="1.25rem" height="1.25rem" icon="tabler:file-upload" aria-hidden="true" />
|
2024-05-12 06:34:03 +02:00
|
|
|
</ComposerButton>
|
2024-05-13 05:44:32 +02:00
|
|
|
<ComposerButton title="Add content warning" @click="cw = !cw" :toggled="cw">
|
2024-05-12 11:04:00 +02:00
|
|
|
<iconify-icon width="1.25rem" height="1.25rem" icon="tabler:rating-18-plus" aria-hidden="true" />
|
2024-05-12 06:34:03 +02:00
|
|
|
</ComposerButton>
|
2024-04-27 09:04:02 +02:00
|
|
|
<ButtonsPrimary :loading="submitting" @click="send" class="ml-auto rounded-full">
|
|
|
|
|
<span>Send!</span>
|
|
|
|
|
</ButtonsPrimary>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-05-17 08:25:59 +02:00
|
|
|
import { char, createRegExp, exactly } from "magic-regexp";
|
2024-06-06 03:35:09 +02:00
|
|
|
import { nanoid } from "nanoid";
|
2024-04-27 09:04:02 +02:00
|
|
|
import type { Instance } from "~/types/mastodon/instance";
|
2024-04-28 08:35:26 +02:00
|
|
|
import type { Status } from "~/types/mastodon/status";
|
2024-05-12 05:42:24 +02:00
|
|
|
import { OverlayScrollbarsComponent } from "#imports";
|
2024-06-06 03:35:09 +02:00
|
|
|
import type FileUploader from "./file-uploader.vue";
|
2024-04-27 09:04:02 +02:00
|
|
|
|
2024-04-28 08:35:26 +02:00
|
|
|
const textarea = ref<HTMLTextAreaElement | undefined>(undefined);
|
2024-06-06 03:35:09 +02:00
|
|
|
const uploader = ref<InstanceType<typeof FileUploader> | undefined>(undefined);
|
2024-04-28 08:35:26 +02:00
|
|
|
const { input: content } = useTextareaAutosize({
|
|
|
|
|
element: textarea,
|
|
|
|
|
});
|
2024-05-12 06:34:03 +02:00
|
|
|
const { Control_Enter, Command_Enter, Control_Alt } = useMagicKeys();
|
2024-04-28 08:35:26 +02:00
|
|
|
const respondingTo = ref<Status | null>(null);
|
|
|
|
|
const respondingType = ref<"reply" | "quote" | null>(null);
|
2024-04-28 09:54:13 +02:00
|
|
|
const me = useMe();
|
2024-05-13 05:44:32 +02:00
|
|
|
const cw = ref(false);
|
2024-05-13 05:19:53 +02:00
|
|
|
const cwContent = ref("");
|
2024-05-12 06:34:03 +02:00
|
|
|
const markdown = ref(true);
|
|
|
|
|
|
|
|
|
|
const splashes = useConfig().COMPOSER_SPLASHES;
|
|
|
|
|
const chosenSplash = ref(splashes[Math.floor(Math.random() * splashes.length)]);
|
2024-05-17 08:25:59 +02:00
|
|
|
const currentlyBeingTypedEmoji = computed(() => {
|
|
|
|
|
const match = content.value?.match(partiallyTypedEmojiValidator);
|
|
|
|
|
return match ? match.at(-1)?.replace(":", "") ?? "" : null;
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-06 03:35:09 +02:00
|
|
|
const openFilePicker = () => {
|
|
|
|
|
uploader.value?.openFilePicker();
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-17 08:25:59 +02:00
|
|
|
const autocompleteEmoji = (emoji: string) => {
|
|
|
|
|
// Replace the end of the string with the emoji
|
|
|
|
|
content.value = content.value?.replace(
|
|
|
|
|
createRegExp(
|
|
|
|
|
exactly(":"),
|
|
|
|
|
exactly(currentlyBeingTypedEmoji.value ?? "").notBefore(char),
|
|
|
|
|
),
|
|
|
|
|
`:${emoji}:`,
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-06 03:35:09 +02:00
|
|
|
const files = ref<
|
|
|
|
|
{
|
|
|
|
|
id: string;
|
|
|
|
|
file: File;
|
|
|
|
|
progress: number;
|
|
|
|
|
api_id?: string;
|
|
|
|
|
}[]
|
|
|
|
|
>([]);
|
|
|
|
|
|
|
|
|
|
const handlePaste = (event: ClipboardEvent) => {
|
|
|
|
|
if (event.clipboardData) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
const items = Array.from(event.clipboardData.items);
|
|
|
|
|
const newFiles = items
|
|
|
|
|
.filter((item) => item.kind === "file")
|
|
|
|
|
.map((item) => item.getAsFile())
|
|
|
|
|
.filter((file): file is File => file !== null);
|
|
|
|
|
if (newFiles.length > 0) {
|
|
|
|
|
files.value.push(
|
|
|
|
|
...newFiles.map((file) => ({
|
|
|
|
|
id: nanoid(),
|
|
|
|
|
file,
|
|
|
|
|
progress: 0,
|
|
|
|
|
})),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-12 06:34:03 +02:00
|
|
|
watch(Control_Alt, () => {
|
|
|
|
|
chosenSplash.value = splashes[Math.floor(Math.random() * splashes.length)];
|
|
|
|
|
});
|
2024-06-06 03:35:09 +02:00
|
|
|
|
2024-04-28 08:35:26 +02:00
|
|
|
onMounted(() => {
|
|
|
|
|
useListen("composer:reply", (note: Status) => {
|
|
|
|
|
respondingTo.value = note;
|
|
|
|
|
respondingType.value = "reply";
|
2024-04-28 09:54:13 +02:00
|
|
|
if (note.account.id !== me.value?.id)
|
|
|
|
|
content.value = `@${note.account.acct} `;
|
2024-04-28 08:35:26 +02:00
|
|
|
textarea.value?.focus();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
useListen("composer:quote", (note: Status) => {
|
|
|
|
|
respondingTo.value = note;
|
|
|
|
|
respondingType.value = "quote";
|
2024-04-28 09:54:13 +02:00
|
|
|
if (note.account.id !== me.value?.id)
|
|
|
|
|
content.value = `@${note.account.acct} `;
|
2024-04-28 08:35:26 +02:00
|
|
|
textarea.value?.focus();
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-04-27 09:04:02 +02:00
|
|
|
|
|
|
|
|
watchEffect(() => {
|
|
|
|
|
if (Control_Enter.value || Command_Enter.value) {
|
|
|
|
|
send();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
instance: Instance;
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
const submitting = ref(false);
|
|
|
|
|
const tokenData = useTokenData();
|
|
|
|
|
const client = useMegalodon(tokenData);
|
|
|
|
|
|
|
|
|
|
const send = async () => {
|
|
|
|
|
submitting.value = true;
|
|
|
|
|
|
2024-04-28 07:02:27 +02:00
|
|
|
fetch(new URL("/api/v1/statuses", client.value?.baseUrl ?? "").toString(), {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
Authorization: `Bearer ${tokenData.value?.access_token}`,
|
2024-04-27 09:04:02 +02:00
|
|
|
},
|
2024-04-28 07:02:27 +02:00
|
|
|
body: JSON.stringify({
|
2024-06-06 03:35:09 +02:00
|
|
|
status: content.value?.trim() ?? "",
|
2024-05-12 06:34:03 +02:00
|
|
|
content_type: markdown.value ? "text/markdown" : "text/plain",
|
2024-04-28 08:35:26 +02:00
|
|
|
in_reply_to_id:
|
|
|
|
|
respondingType.value === "reply"
|
|
|
|
|
? respondingTo.value?.id
|
|
|
|
|
: null,
|
|
|
|
|
quote_id:
|
|
|
|
|
respondingType.value === "quote"
|
|
|
|
|
? respondingTo.value?.id
|
|
|
|
|
: null,
|
2024-05-13 05:44:32 +02:00
|
|
|
spoiler_text: cw.value ? cwContent.value.trim() : undefined,
|
|
|
|
|
sensitive: cw.value,
|
2024-06-06 03:35:09 +02:00
|
|
|
media_ids: files.value
|
|
|
|
|
.filter((file) => !!file.api_id)
|
|
|
|
|
.map((file) => file.api_id),
|
2024-04-28 07:02:27 +02:00
|
|
|
}),
|
|
|
|
|
})
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
throw new Error("Failed to send status");
|
|
|
|
|
}
|
2024-04-27 09:04:02 +02:00
|
|
|
|
2024-04-28 07:02:27 +02:00
|
|
|
content.value = "";
|
|
|
|
|
submitting.value = false;
|
|
|
|
|
useEvent("composer:send", await res.json());
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
useEvent("composer:close");
|
|
|
|
|
});
|
2024-04-27 09:04:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const characterLimit = computed(
|
|
|
|
|
() => props.instance?.configuration.statuses.max_characters ?? 0,
|
|
|
|
|
);
|
|
|
|
|
const remainingCharacters = computed(
|
|
|
|
|
() => characterLimit.value - (content.value?.length ?? 0),
|
|
|
|
|
);
|
|
|
|
|
</script>
|