refactor: 🎨 Refactor notes, event system and timelines

This commit is contained in:
Jesse Wierzbinski 2024-04-27 19:02:27 -10:00
parent 7461478170
commit 0f214b6a17
No known key found for this signature in database
18 changed files with 266 additions and 188 deletions

View file

@ -32,10 +32,6 @@ const props = defineProps<{
instance: Instance;
}>();
const emits = defineEmits<{
send: [];
}>();
const submitting = ref(false);
const tokenData = useTokenData();
const client = useMegalodon(tokenData);
@ -43,29 +39,29 @@ const client = useMegalodon(tokenData);
const send = async () => {
submitting.value = true;
await fetch(
new URL("/api/v1/statuses", client.value?.baseUrl ?? "").toString(),
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${tokenData.value?.access_token}`,
},
body: JSON.stringify({
status: content.value,
content_type: "text/markdown",
}),
fetch(new URL("/api/v1/statuses", client.value?.baseUrl ?? "").toString(), {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${tokenData.value?.access_token}`,
},
).then((res) => {
if (!res.ok) {
throw new Error("Failed to send status");
}
body: JSON.stringify({
status: content.value,
content_type: "text/markdown",
}),
})
.then(async (res) => {
if (!res.ok) {
throw new Error("Failed to send status");
}
content.value = "";
submitting.value = false;
});
emits("send");
content.value = "";
submitting.value = false;
useEvent("composer:send", await res.json());
})
.finally(() => {
useEvent("composer:close");
});
};
const characterLimit = computed(

View file

@ -1,6 +1,6 @@
<template>
<HeadlessTransitionRoot as="template" :show="open">
<HeadlessDialog as="div" class="relative z-50" @close="emits('close')">
<HeadlessDialog as="div" class="relative z-50" @close="useEvent('composer:close')">
<HeadlessTransitionChild as="template" enter="ease-out duration-300" enter-from="opacity-0"
enter-to="opacity-100" leave="ease-in duration-200" leave-from="opacity-100" leave-to="opacity-0">
<div class="fixed inset-0 bg-black/70 transition-opacity" />
@ -15,7 +15,7 @@
leave-to="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95">
<HeadlessDialogPanel
class="relative transform overflow-hidden rounded-lg bg-dark-700 ring-1 ring-white/10 text-left shadow-xl transition-all sm:my-8 w-full max-w-xl">
<Composer v-if="instance" :instance="instance" @send="emits('close')" />
<Composer v-if="instance" :instance="instance" />
</HeadlessDialogPanel>
</HeadlessTransitionChild>
</div>
@ -25,14 +25,13 @@
</template>
<script lang="ts" setup>
const props = defineProps<{
open: boolean;
}>();
const open = ref(false);
useListen("composer:open", () => {
open.value = true;
});
useListen("composer:close", () => {
open.value = false;
});
const client = useMegalodon();
const instance = useInstance(client);
const emits = defineEmits<{
close: [];
}>();
</script>