2024-04-27 09:04:02 +02:00
|
|
|
<template>
|
2024-06-06 05:48:12 +02:00
|
|
|
<div v-if="respondingTo" class="mb-4" role="region" aria-label="Responding to">
|
2024-06-05 02:03:15 +02:00
|
|
|
<OverlayScrollbarsComponent :defer="true" class="max-h-72 overflow-y-auto">
|
2024-06-29 05:05:50 +02:00
|
|
|
<Note :element="respondingTo" :small="true" :disabled="true" class="!rounded-none !bg-primary-500/10" />
|
2024-06-05 02:03:15 +02:00
|
|
|
</OverlayScrollbarsComponent>
|
|
|
|
|
</div>
|
2024-06-06 03:35:09 +02:00
|
|
|
<div class="px-6 pb-4 pt-5">
|
2024-06-21 04:09:09 +02:00
|
|
|
<RichTextboxInput v-model:model-content="content" @paste="handlePaste" :disabled="loading"
|
2024-06-19 08:16:28 +02:00
|
|
|
:placeholder="chosenSplash" :max-characters="characterLimit" class="focus:!ring-0 max-h-[70dvh]" />
|
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-07-22 01:23:29 +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"
|
2024-06-06 05:48:12 +02:00
|
|
|
aria-label="Content warning" />
|
2024-05-12 06:34:03 +02:00
|
|
|
</div>
|
2024-06-21 04:09:09 +02:00
|
|
|
<FileUploader 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-06-24 03:21:28 +02:00
|
|
|
<Button title="Mention someone" @click="content = content + '@'">
|
2024-05-12 11:04:00 +02:00
|
|
|
<iconify-icon height="1.5rem" width="1.5rem" icon="tabler:at" aria-hidden="true" />
|
2024-06-21 04:09:09 +02:00
|
|
|
</Button>
|
|
|
|
|
<Button 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-06-21 04:09:09 +02:00
|
|
|
</Button>
|
|
|
|
|
<Button 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-06-21 04:09:09 +02:00
|
|
|
</Button>
|
|
|
|
|
<Button 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-06-21 04:09:09 +02:00
|
|
|
</Button>
|
|
|
|
|
<Button 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-06-21 04:09:09 +02:00
|
|
|
</Button>
|
|
|
|
|
<Button 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-06-21 04:09:09 +02:00
|
|
|
</Button>
|
2024-06-28 02:09:05 +02:00
|
|
|
<ButtonBase theme="primary" :loading="loading" @click="send" class="ml-auto rounded-full"
|
2024-06-06 05:58:20 +02:00
|
|
|
:disabled="!canSubmit || loading">
|
2024-06-28 02:09:05 +02:00
|
|
|
{{
|
2024-06-19 08:16:28 +02:00
|
|
|
respondingType === "edit" ? "Edit!" : "Send!"
|
2024-06-28 02:09:05 +02:00
|
|
|
}}
|
|
|
|
|
</ButtonBase>
|
2024-04-27 09:04:02 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-08-28 00:23:29 +02:00
|
|
|
import type { Instance, Status } from "@versia/client/types";
|
2024-06-06 03:35:09 +02:00
|
|
|
import { nanoid } from "nanoid";
|
2024-06-28 02:09:05 +02:00
|
|
|
import ButtonBase from "~/packages/ui/components/buttons/button.vue";
|
2024-05-12 05:42:24 +02:00
|
|
|
import { OverlayScrollbarsComponent } from "#imports";
|
2024-06-21 04:09:09 +02:00
|
|
|
import RichTextboxInput from "../inputs/rich-textbox-input.vue";
|
|
|
|
|
import Note from "../social-elements/notes/note.vue";
|
|
|
|
|
import Button from "./button.vue";
|
|
|
|
|
// biome-ignore lint/style/useImportType: Biome doesn't see the Vue code
|
|
|
|
|
import FileUploader from "./file-uploader.vue";
|
2024-04-27 09:04:02 +02:00
|
|
|
|
2024-06-06 03:35:09 +02:00
|
|
|
const uploader = ref<InstanceType<typeof FileUploader> | undefined>(undefined);
|
2024-05-12 06:34:03 +02:00
|
|
|
const { Control_Enter, Command_Enter, Control_Alt } = useMagicKeys();
|
2024-06-19 08:16:28 +02:00
|
|
|
const content = ref("");
|
2024-04-28 08:35:26 +02:00
|
|
|
const respondingTo = ref<Status | null>(null);
|
2024-06-06 08:42:44 +02:00
|
|
|
const respondingType = ref<"reply" | "quote" | "edit" | null>(null);
|
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
|
|
|
|
2024-06-06 03:35:09 +02:00
|
|
|
const openFilePicker = () => {
|
|
|
|
|
uploader.value?.openFilePicker();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const files = ref<
|
|
|
|
|
{
|
|
|
|
|
id: string;
|
|
|
|
|
file: File;
|
|
|
|
|
progress: number;
|
|
|
|
|
api_id?: string;
|
2024-06-06 05:48:12 +02:00
|
|
|
alt_text?: string;
|
2024-06-06 03:35:09 +02:00
|
|
|
}[]
|
|
|
|
|
>([]);
|
|
|
|
|
|
|
|
|
|
const handlePaste = (event: ClipboardEvent) => {
|
|
|
|
|
if (event.clipboardData) {
|
|
|
|
|
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) {
|
2024-06-06 05:54:54 +02:00
|
|
|
event.preventDefault();
|
2024-06-06 03:35:09 +02:00
|
|
|
files.value.push(
|
|
|
|
|
...newFiles.map((file) => ({
|
|
|
|
|
id: nanoid(),
|
|
|
|
|
file,
|
|
|
|
|
progress: 0,
|
|
|
|
|
})),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-16 03:42:48 +02:00
|
|
|
watch(Control_Alt as ComputedRef<boolean>, () => {
|
2024-05-12 06:34:03 +02:00
|
|
|
chosenSplash.value = splashes[Math.floor(Math.random() * splashes.length)];
|
|
|
|
|
});
|
2024-06-06 03:35:09 +02:00
|
|
|
|
2024-06-06 05:48:12 +02:00
|
|
|
watch(
|
|
|
|
|
files,
|
|
|
|
|
(newFiles) => {
|
|
|
|
|
// If a file is uploading, set loading to true
|
|
|
|
|
if (newFiles.some((file) => file.progress < 1)) {
|
|
|
|
|
loading.value = true;
|
|
|
|
|
} else {
|
|
|
|
|
loading.value = false;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
deep: true,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2024-04-28 08:35:26 +02:00
|
|
|
onMounted(() => {
|
|
|
|
|
useListen("composer:reply", (note: Status) => {
|
|
|
|
|
respondingTo.value = note;
|
|
|
|
|
respondingType.value = "reply";
|
2024-06-20 02:07:56 +02:00
|
|
|
if (note.account.id !== identity.value?.account.id) {
|
2024-04-28 09:54:13 +02:00
|
|
|
content.value = `@${note.account.acct} `;
|
2024-06-20 02:07:56 +02:00
|
|
|
}
|
2024-04-28 08:35:26 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
useListen("composer:quote", (note: Status) => {
|
|
|
|
|
respondingTo.value = note;
|
|
|
|
|
respondingType.value = "quote";
|
2024-06-20 02:07:56 +02:00
|
|
|
if (note.account.id !== identity.value?.account.id) {
|
2024-04-28 09:54:13 +02:00
|
|
|
content.value = `@${note.account.acct} `;
|
2024-06-20 02:07:56 +02:00
|
|
|
}
|
2024-04-28 08:35:26 +02:00
|
|
|
});
|
2024-06-06 08:42:44 +02:00
|
|
|
|
|
|
|
|
useListen("composer:edit", async (note: Status) => {
|
|
|
|
|
loading.value = true;
|
|
|
|
|
files.value = note.media_attachments.map((file) => ({
|
|
|
|
|
id: nanoid(),
|
|
|
|
|
file: new File([], file.url),
|
|
|
|
|
progress: 1,
|
|
|
|
|
api_id: file.id,
|
|
|
|
|
alt_text: file.description ?? undefined,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// Fetch source
|
2024-06-10 05:24:55 +02:00
|
|
|
const source = await client.value.getStatusSource(note.id);
|
2024-06-06 08:42:44 +02:00
|
|
|
|
|
|
|
|
if (source?.data) {
|
|
|
|
|
respondingTo.value = note;
|
|
|
|
|
respondingType.value = "edit";
|
|
|
|
|
content.value = source.data.text;
|
|
|
|
|
cwContent.value = source.data.spoiler_text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loading.value = false;
|
|
|
|
|
});
|
2024-04-28 08:35:26 +02:00
|
|
|
});
|
2024-04-27 09:04:02 +02:00
|
|
|
|
|
|
|
|
watchEffect(() => {
|
2024-06-16 03:42:48 +02:00
|
|
|
if (Control_Enter?.value || Command_Enter?.value) {
|
2024-04-27 09:04:02 +02:00
|
|
|
send();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
instance: Instance;
|
|
|
|
|
}>();
|
|
|
|
|
|
2024-06-06 05:48:12 +02:00
|
|
|
const loading = ref(false);
|
2024-06-06 05:58:20 +02:00
|
|
|
const canSubmit = computed(
|
|
|
|
|
() =>
|
|
|
|
|
(content.value?.trim().length > 0 || files.value.length > 0) &&
|
|
|
|
|
content.value?.trim().length <= characterLimit.value,
|
|
|
|
|
);
|
2024-04-27 09:04:02 +02:00
|
|
|
|
|
|
|
|
const send = async () => {
|
2024-06-06 05:48:12 +02:00
|
|
|
loading.value = true;
|
2024-06-20 02:07:56 +02:00
|
|
|
if (!(identity.value && client.value)) {
|
2024-06-08 01:09:15 +02:00
|
|
|
throw new Error("Not authenticated");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (respondingType.value === "edit" && respondingTo.value) {
|
|
|
|
|
const response = await client.value.editStatus(respondingTo.value.id, {
|
|
|
|
|
status: content.value?.trim() ?? "",
|
|
|
|
|
content_type: markdown.value ? "text/markdown" : "text/plain",
|
|
|
|
|
spoiler_text: cw.value ? cwContent.value.trim() : undefined,
|
|
|
|
|
sensitive: cw.value,
|
|
|
|
|
media_ids: files.value
|
|
|
|
|
.filter((file) => !!file.api_id)
|
|
|
|
|
.map((file) => file.api_id) as string[],
|
|
|
|
|
});
|
2024-04-27 09:04:02 +02:00
|
|
|
|
2024-06-08 01:09:15 +02:00
|
|
|
if (!response.data) {
|
|
|
|
|
throw new Error("Failed to edit status");
|
|
|
|
|
}
|
2024-06-06 08:42:44 +02:00
|
|
|
|
2024-06-08 01:09:15 +02:00
|
|
|
content.value = "";
|
|
|
|
|
loading.value = false;
|
|
|
|
|
useEvent("composer:send-edit", response.data);
|
|
|
|
|
useEvent("composer:close");
|
2024-06-06 08:42:44 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-08 01:09:15 +02:00
|
|
|
const response = await client.value.postStatus(
|
|
|
|
|
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
|
2024-06-08 01:09:15 +02:00
|
|
|
: undefined,
|
2024-04-28 08:35:26 +02:00
|
|
|
quote_id:
|
|
|
|
|
respondingType.value === "quote"
|
|
|
|
|
? respondingTo.value?.id
|
2024-06-08 01:09:15 +02:00
|
|
|
: undefined,
|
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)
|
2024-06-08 01:09:15 +02:00
|
|
|
.map((file) => file.api_id) as string[],
|
|
|
|
|
},
|
|
|
|
|
);
|
2024-04-27 09:04:02 +02:00
|
|
|
|
2024-06-08 01:09:15 +02:00
|
|
|
if (!response.data) {
|
|
|
|
|
throw new Error("Failed to send status");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content.value = "";
|
|
|
|
|
loading.value = false;
|
|
|
|
|
useEvent("composer:send", response.data as Status);
|
|
|
|
|
useEvent("composer:close");
|
2024-04-27 09:04:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const characterLimit = computed(
|
|
|
|
|
() => props.instance?.configuration.statuses.max_characters ?? 0,
|
|
|
|
|
);
|
|
|
|
|
</script>
|