mirror of
https://github.com/versia-pub/frontend.git
synced 2025-12-06 08:28:20 +01:00
refactor: 🎨 Refactor notes, event system and timelines
This commit is contained in:
parent
7461478170
commit
0f214b6a17
|
|
@ -32,10 +32,6 @@ const props = defineProps<{
|
||||||
instance: Instance;
|
instance: Instance;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emits = defineEmits<{
|
|
||||||
send: [];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const submitting = ref(false);
|
const submitting = ref(false);
|
||||||
const tokenData = useTokenData();
|
const tokenData = useTokenData();
|
||||||
const client = useMegalodon(tokenData);
|
const client = useMegalodon(tokenData);
|
||||||
|
|
@ -43,9 +39,7 @@ const client = useMegalodon(tokenData);
|
||||||
const send = async () => {
|
const send = async () => {
|
||||||
submitting.value = true;
|
submitting.value = true;
|
||||||
|
|
||||||
await fetch(
|
fetch(new URL("/api/v1/statuses", client.value?.baseUrl ?? "").toString(), {
|
||||||
new URL("/api/v1/statuses", client.value?.baseUrl ?? "").toString(),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -55,17 +49,19 @@ const send = async () => {
|
||||||
status: content.value,
|
status: content.value,
|
||||||
content_type: "text/markdown",
|
content_type: "text/markdown",
|
||||||
}),
|
}),
|
||||||
},
|
})
|
||||||
).then((res) => {
|
.then(async (res) => {
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error("Failed to send status");
|
throw new Error("Failed to send status");
|
||||||
}
|
}
|
||||||
|
|
||||||
content.value = "";
|
content.value = "";
|
||||||
submitting.value = false;
|
submitting.value = false;
|
||||||
|
useEvent("composer:send", await res.json());
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
useEvent("composer:close");
|
||||||
});
|
});
|
||||||
|
|
||||||
emits("send");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const characterLimit = computed(
|
const characterLimit = computed(
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<HeadlessTransitionRoot as="template" :show="open">
|
<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"
|
<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">
|
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" />
|
<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">
|
leave-to="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95">
|
||||||
<HeadlessDialogPanel
|
<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">
|
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>
|
</HeadlessDialogPanel>
|
||||||
</HeadlessTransitionChild>
|
</HeadlessTransitionChild>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -25,14 +25,13 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
const props = defineProps<{
|
const open = ref(false);
|
||||||
open: boolean;
|
useListen("composer:open", () => {
|
||||||
}>();
|
open.value = true;
|
||||||
|
});
|
||||||
|
useListen("composer:close", () => {
|
||||||
|
open.value = false;
|
||||||
|
});
|
||||||
const client = useMegalodon();
|
const client = useMegalodon();
|
||||||
const instance = useInstance(client);
|
const instance = useInstance(client);
|
||||||
|
|
||||||
const emits = defineEmits<{
|
|
||||||
close: [];
|
|
||||||
}>();
|
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -47,7 +47,6 @@
|
||||||
</ButtonsBase>
|
</ButtonsBase>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
<ComposerModal :open="composerOpen" @close="composerOpen = false" />
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
|
@ -64,7 +63,6 @@ const timelines = ref([
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const composerOpen = ref(false);
|
|
||||||
const loadingAuth = ref(false);
|
const loadingAuth = ref(false);
|
||||||
|
|
||||||
const appData = useAppData();
|
const appData = useAppData();
|
||||||
|
|
@ -72,7 +70,7 @@ const tokenData = useTokenData();
|
||||||
const client = useMegalodon();
|
const client = useMegalodon();
|
||||||
|
|
||||||
const compose = () => {
|
const compose = () => {
|
||||||
composerOpen.value = true;
|
useEvent("composer:open");
|
||||||
};
|
};
|
||||||
|
|
||||||
const signIn = async () => {
|
const signIn = async () => {
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,27 @@
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="first:rounded-t last:rounded-b ring-1 ring-white/5 p-6 flex flex-col bg-dark-800 hover:bg-dark-700 duration-200">
|
class="first:rounded-t last:rounded-b ring-1 ring-white/5 p-6 flex flex-col bg-dark-800 hover:bg-dark-700 duration-200">
|
||||||
<div v-if="props.note?.reblog" class="mb-4 flex flex-row gap-2 items-center text-pink-500">
|
<div v-if="reblog" class="mb-4 flex flex-row gap-2 items-center text-pink-500">
|
||||||
<Skeleton :enabled="!props.note" shape="rect" class="!h-6" :min-width="40" :max-width="100" width-unit="%">
|
<Skeleton :enabled="!loaded" shape="rect" class="!h-6" :min-width="40" :max-width="100" width-unit="%">
|
||||||
<Icon name="tabler:repeat" class="h-6 w-6" aria-hidden="true" />
|
<Icon name="tabler:repeat" class="h-6 w-6" aria-hidden="true" />
|
||||||
<img v-if="props.note?.account.avatar" :src="props.note?.account.avatar"
|
<img v-if="reblog.avatar" :src="reblog.avatar" :alt="`${reblog.acct}'s avatar'`"
|
||||||
:alt="`${props.note?.account.acct}'s avatar'`" class="h-6 w-6 rounded ring-1 ring-white/10" />
|
class="h-6 w-6 rounded ring-1 ring-white/10" />
|
||||||
<span><strong v-html="eventualReblogAccountName"></strong> reblogged</span>
|
<span><strong v-html="reblogDisplayName"></strong> reblogged</span>
|
||||||
</Skeleton>
|
</Skeleton>
|
||||||
</div>
|
</div>
|
||||||
<SocialElementsNotesHeader :note="note" :small="small" />
|
<SocialElementsNotesHeader :note="note" :small="small" />
|
||||||
<div v-if="!noteClosed">
|
<div v-if="!collapsed">
|
||||||
<NuxtLink :href="noteUrl" class="mt-6 block relative">
|
<NuxtLink :href="url" class="mt-6 block relative">
|
||||||
<Skeleton :enabled="true" v-if="!note" :min-width="50" :max-width="100" width-unit="%" shape="rect"
|
<Skeleton :enabled="!loaded" :min-width="50" :max-width="100" width-unit="%" shape="rect"
|
||||||
type="content">
|
type="content">
|
||||||
</Skeleton>
|
<div v-if="content"
|
||||||
<div v-else-if="content"
|
|
||||||
:class="['prose prose-invert duration-200 !max-w-full break-words prose-a:no-underline content']"
|
:class="['prose prose-invert duration-200 !max-w-full break-words prose-a:no-underline content']"
|
||||||
v-html="content">
|
v-html="content">
|
||||||
</div>
|
</div>
|
||||||
|
</Skeleton>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<div v-if="attachments.length > 0" class="[&:not(:first-child)]:mt-6">
|
<div v-if="note && note.media_attachments.length > 0" class="[&:not(:first-child)]:mt-6">
|
||||||
<SocialElementsNotesAttachment v-for="attachment of attachments" :key="attachment.id"
|
<SocialElementsNotesAttachment v-for="attachment of note.media_attachments" :key="attachment.id"
|
||||||
:attachment="attachment" />
|
:attachment="attachment" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
<!-- Spoiler text is it's specified -->
|
<!-- Spoiler text is it's specified -->
|
||||||
<span v-if="note?.spoiler_text" class="mt-2 break-all">{{ note.spoiler_text
|
<span v-if="note?.spoiler_text" class="mt-2 break-all">{{ note.spoiler_text
|
||||||
}}</span>
|
}}</span>
|
||||||
<ButtonsSecondary @click="noteClosed = false" class="mt-4">Show content</ButtonsSecondary>
|
<ButtonsSecondary @click="collapsed = false" class="mt-4">Show content</ButtonsSecondary>
|
||||||
</div>
|
</div>
|
||||||
<Skeleton class="!h-10 w-full mt-6" :enabled="true" v-if="!note && !small"></Skeleton>
|
<Skeleton class="!h-10 w-full mt-6" :enabled="true" v-if="!note && !small"></Skeleton>
|
||||||
<div v-else-if="!small"
|
<div v-else-if="!small"
|
||||||
|
|
@ -70,12 +70,12 @@
|
||||||
</ButtonsDropdownElement>
|
</ButtonsDropdownElement>
|
||||||
</HeadlessMenuItem>
|
</HeadlessMenuItem>
|
||||||
<HeadlessMenuItem>
|
<HeadlessMenuItem>
|
||||||
<ButtonsDropdownElement @click="note && copy(note.uri)" icon="tabler:link" class="w-full">
|
<ButtonsDropdownElement @click="copy(url)" icon="tabler:link" class="w-full">
|
||||||
Copy Link
|
Copy Link
|
||||||
</ButtonsDropdownElement>
|
</ButtonsDropdownElement>
|
||||||
</HeadlessMenuItem>
|
</HeadlessMenuItem>
|
||||||
<HeadlessMenuItem>
|
<HeadlessMenuItem>
|
||||||
<ButtonsDropdownElement @click="note && deleteNote()" icon="tabler:backspace"
|
<ButtonsDropdownElement @click="remove" icon="tabler:backspace"
|
||||||
class="w-full border-r-2 border-red-500">
|
class="w-full border-r-2 border-red-500">
|
||||||
Delete
|
Delete
|
||||||
</ButtonsDropdownElement>
|
</ButtonsDropdownElement>
|
||||||
|
|
@ -95,55 +95,30 @@ const props = defineProps<{
|
||||||
small?: boolean;
|
small?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emits = defineEmits<{
|
|
||||||
delete: [];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
// Handle reblogs
|
|
||||||
const note = computed(() => props.note?.reblog ?? props.note);
|
|
||||||
const noteClosed = ref(
|
|
||||||
note.value?.sensitive || !!note.value?.spoiler_text || false,
|
|
||||||
);
|
|
||||||
|
|
||||||
const { copy } = useClipboard();
|
|
||||||
const tokenData = useTokenData();
|
const tokenData = useTokenData();
|
||||||
const client = useMegalodon(tokenData);
|
const client = useMegalodon(tokenData);
|
||||||
const mentions = await useResolveMentions(
|
const {
|
||||||
note.value?.mentions ?? [],
|
loaded,
|
||||||
client.value,
|
note,
|
||||||
);
|
remove,
|
||||||
const eventualReblogAccountName = props.note?.reblog
|
content,
|
||||||
? useParsedContent(
|
shouldHide,
|
||||||
props.note?.account.display_name,
|
url,
|
||||||
props.note?.account.emojis,
|
reblog,
|
||||||
mentions.value,
|
reblogDisplayName,
|
||||||
).value
|
} = useNoteData(ref(props.note), client);
|
||||||
: null;
|
|
||||||
const content =
|
console.log(props.note?.account.display_name ?? "");
|
||||||
note.value && process.client
|
|
||||||
? useParsedContent(
|
const collapsed = ref(shouldHide.value);
|
||||||
note.value.content,
|
|
||||||
note.value.emojis,
|
const { copy } = useClipboard();
|
||||||
mentions.value,
|
|
||||||
)
|
|
||||||
: "";
|
|
||||||
const numberFormat = (number = 0) =>
|
const numberFormat = (number = 0) =>
|
||||||
new Intl.NumberFormat(undefined, {
|
new Intl.NumberFormat(undefined, {
|
||||||
notation: "compact",
|
notation: "compact",
|
||||||
compactDisplay: "short",
|
compactDisplay: "short",
|
||||||
maximumFractionDigits: 1,
|
maximumFractionDigits: 1,
|
||||||
}).format(number);
|
}).format(number);
|
||||||
const attachments = note.value?.media_attachments ?? [];
|
|
||||||
const noteUrl = note.value && `/@${note.value.account.acct}/${note.value.id}`;
|
|
||||||
|
|
||||||
const deleteNote = async () => {
|
|
||||||
const result = await client.value?.deleteStatus(note.value?.id ?? "");
|
|
||||||
|
|
||||||
if (result?.data) {
|
|
||||||
console.log("Status deleted", result.data);
|
|
||||||
emits("delete");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@
|
||||||
<Icon :name="icon" class="h-6 w-6 text-gray-200" aria-hidden="true" />
|
<Icon :name="icon" class="h-6 w-6 text-gray-200" aria-hidden="true" />
|
||||||
<img v-if="notification?.account?.avatar" :src="notification?.account.avatar"
|
<img v-if="notification?.account?.avatar" :src="notification?.account.avatar"
|
||||||
:alt="`${notification?.account.acct}'s avatar'`" class="h-6 w-6 rounded ring-1 ring-white/10" />
|
:alt="`${notification?.account.acct}'s avatar'`" class="h-6 w-6 rounded ring-1 ring-white/10" />
|
||||||
<span class="text-gray-200"><strong v-html="accountName"></strong> {{ text }}</span>
|
<span class="text-gray-200"><strong v-html="accountName"></strong> {{ text
|
||||||
|
}}</span>
|
||||||
</Skeleton>
|
</Skeleton>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -29,7 +30,6 @@ const props = defineProps<{
|
||||||
const accountName = useParsedContent(
|
const accountName = useParsedContent(
|
||||||
props.notification?.account?.display_name ?? "",
|
props.notification?.account?.display_name ?? "",
|
||||||
props.notification?.account?.emojis ?? [],
|
props.notification?.account?.emojis ?? [],
|
||||||
[],
|
|
||||||
);
|
);
|
||||||
const text = computed(() => {
|
const text = computed(() => {
|
||||||
if (!props.notification) return "";
|
if (!props.notification) return "";
|
||||||
|
|
|
||||||
|
|
@ -119,22 +119,15 @@ watch(
|
||||||
useParsedContent(
|
useParsedContent(
|
||||||
props.account?.note ?? "",
|
props.account?.note ?? "",
|
||||||
props.account?.emojis ?? [],
|
props.account?.emojis ?? [],
|
||||||
[],
|
|
||||||
).value ?? "";
|
).value ?? "";
|
||||||
parsedFields.value =
|
parsedFields.value =
|
||||||
props.account?.fields.map((field) => ({
|
props.account?.fields.map((field) => ({
|
||||||
name:
|
name:
|
||||||
useParsedContent(
|
useParsedContent(field.name, props.account?.emojis ?? [])
|
||||||
field.name,
|
.value ?? "",
|
||||||
props.account?.emojis ?? [],
|
|
||||||
[],
|
|
||||||
).value ?? "",
|
|
||||||
value:
|
value:
|
||||||
useParsedContent(
|
useParsedContent(field.value, props.account?.emojis ?? [])
|
||||||
field.value,
|
.value ?? "",
|
||||||
props.account?.emojis ?? [],
|
|
||||||
[],
|
|
||||||
).value ?? "",
|
|
||||||
})) ?? [];
|
})) ?? [];
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<TimelinesTimeline :timeline="timeline" :load-next="loadNext" :load-prev="loadPrev" @delete="noteDelete" />
|
<TimelinesTimeline :timeline="timeline" :load-next="loadNext" :load-prev="loadPrev" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
|
@ -15,7 +15,7 @@ const { timeline, loadNext, loadPrev } = useAccountTimeline(
|
||||||
timelineParameters,
|
timelineParameters,
|
||||||
);
|
);
|
||||||
|
|
||||||
const noteDelete = async (id: string) => {
|
useListen("note:delete", ({ id }) => {
|
||||||
timeline.value = timeline.value.filter((note) => note.id !== id);
|
timeline.value = timeline.value.filter((note) => note.id !== id);
|
||||||
};
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<TimelinesTimeline :timeline="timeline" :load-next="loadNext" :load-prev="loadPrev" @delete="noteDelete" />
|
<TimelinesTimeline :timeline="timeline" :load-next="loadNext" :load-prev="loadPrev" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
|
@ -10,7 +10,7 @@ const { timeline, loadNext, loadPrev } = useLocalTimeline(
|
||||||
timelineParameters,
|
timelineParameters,
|
||||||
);
|
);
|
||||||
|
|
||||||
const noteDelete = async (id: string) => {
|
useListen("note:delete", ({ id }) => {
|
||||||
timeline.value = timeline.value.filter((note) => note.id !== id);
|
timeline.value = timeline.value.filter((note) => note.id !== id);
|
||||||
};
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<TimelinesTimeline :timeline="timeline" :load-next="loadNext" :load-prev="loadPrev" @delete="noteDelete" />
|
<TimelinesTimeline :timeline="timeline" :load-next="loadNext" :load-prev="loadPrev" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
|
@ -10,7 +10,7 @@ const { timeline, loadNext, loadPrev } = usePublicTimeline(
|
||||||
timelineParameters,
|
timelineParameters,
|
||||||
);
|
);
|
||||||
|
|
||||||
const noteDelete = async (id: string) => {
|
useListen("note:delete", ({ id }) => {
|
||||||
timeline.value = timeline.value.filter((note) => note.id !== id);
|
timeline.value = timeline.value.filter((note) => note.id !== id);
|
||||||
};
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -2,8 +2,7 @@
|
||||||
<ClientOnly>
|
<ClientOnly>
|
||||||
<TransitionGroup leave-active-class="ease-in duration-200" leave-from-class="scale-100 opacity-100"
|
<TransitionGroup leave-active-class="ease-in duration-200" leave-from-class="scale-100 opacity-100"
|
||||||
leave-to-class="opacity-0 scale-90">
|
leave-to-class="opacity-0 scale-90">
|
||||||
<SocialElementsNotesNote @delete="emits('delete', note.id)" v-for="note of timeline" :key="note.id"
|
<SocialElementsNotesNote v-for="note of timeline" :key="note.id" :note="note" />
|
||||||
:note="note" />
|
|
||||||
</TransitionGroup>
|
</TransitionGroup>
|
||||||
<span ref="skeleton"></span>
|
<span ref="skeleton"></span>
|
||||||
<SocialElementsNotesNote v-for="index of 5" v-if="!hasReachedEnd" :skeleton="true" />
|
<SocialElementsNotesNote v-for="index of 5" v-if="!hasReachedEnd" :skeleton="true" />
|
||||||
|
|
@ -25,10 +24,6 @@ const props = defineProps<{
|
||||||
loadPrev: () => Promise<void>;
|
loadPrev: () => Promise<void>;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emits = defineEmits<{
|
|
||||||
delete: [id: string];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const isLoading = ref(true);
|
const isLoading = ref(true);
|
||||||
|
|
||||||
const hasReachedEnd = ref(false);
|
const hasReachedEnd = ref(false);
|
||||||
|
|
@ -47,10 +42,14 @@ onMounted(() => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useListen("composer:send", () => {
|
||||||
|
props.loadPrev();
|
||||||
|
});
|
||||||
|
|
||||||
// Every 5 seconds, load newer posts (prev)
|
// Every 5 seconds, load newer posts (prev)
|
||||||
useIntervalFn(() => {
|
useIntervalFn(() => {
|
||||||
props.loadPrev();
|
props.loadPrev();
|
||||||
}, 5000);
|
}, 10000);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.timeline,
|
() => props.timeline,
|
||||||
|
|
|
||||||
16
composables/EventBus.ts
Normal file
16
composables/EventBus.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
import mitt from "mitt";
|
||||||
|
import type { Status } from "~/types/mastodon/status";
|
||||||
|
|
||||||
|
type ApplicationEvents = {
|
||||||
|
"note:reply": Status;
|
||||||
|
"note:delete": Status;
|
||||||
|
"note:edit": Status;
|
||||||
|
"composer:open": undefined;
|
||||||
|
"composer:send": Status;
|
||||||
|
"composer:close": undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
const emitter = mitt<ApplicationEvents>();
|
||||||
|
|
||||||
|
export const useEvent = emitter.emit;
|
||||||
|
export const useListen = emitter.on;
|
||||||
66
composables/NoteData.ts
Normal file
66
composables/NoteData.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
import type { Mastodon } from "megalodon";
|
||||||
|
import type { Status } from "~/types/mastodon/status";
|
||||||
|
|
||||||
|
export const useNoteData = (
|
||||||
|
noteProp: MaybeRef<Status | undefined>,
|
||||||
|
client: Ref<Mastodon | null>,
|
||||||
|
) => {
|
||||||
|
const renderedNote = computed(
|
||||||
|
() => toValue(noteProp)?.reblog ?? toValue(noteProp),
|
||||||
|
);
|
||||||
|
const isReblog = computed(() => !!toValue(noteProp)?.reblog);
|
||||||
|
const shouldHide = computed(
|
||||||
|
() =>
|
||||||
|
renderedNote.value?.sensitive ||
|
||||||
|
!!renderedNote.value?.spoiler_text ||
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
const mentions = useResolveMentions(
|
||||||
|
renderedNote.value?.mentions ?? [],
|
||||||
|
client.value,
|
||||||
|
);
|
||||||
|
const content = useParsedContent(
|
||||||
|
renderedNote.value?.content ?? "",
|
||||||
|
renderedNote.value?.emojis ?? [],
|
||||||
|
mentions,
|
||||||
|
);
|
||||||
|
const loaded = computed(() => content.value !== null);
|
||||||
|
|
||||||
|
const reblogDisplayName = useParsedContent(
|
||||||
|
renderedNote.value?.account.display_name ?? "",
|
||||||
|
renderedNote.value?.account.emojis ?? [],
|
||||||
|
);
|
||||||
|
const reblog = computed(() =>
|
||||||
|
isReblog.value && renderedNote.value
|
||||||
|
? {
|
||||||
|
avatar: renderedNote.value.account.avatar,
|
||||||
|
acct: renderedNote.value.account.acct,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
);
|
||||||
|
|
||||||
|
const url = computed(
|
||||||
|
() => `/@${renderedNote.value?.account.acct}/${renderedNote.value?.id}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const remove = async () => {
|
||||||
|
const result = await client.value?.deleteStatus(
|
||||||
|
renderedNote.value?.id ?? "",
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result?.data) {
|
||||||
|
useEvent("note:delete", result.data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
loaded,
|
||||||
|
note: renderedNote,
|
||||||
|
content,
|
||||||
|
reblog,
|
||||||
|
reblogDisplayName,
|
||||||
|
shouldHide,
|
||||||
|
url,
|
||||||
|
remove,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
@ -12,11 +12,13 @@ import MentionComponent from "../components/social-elements/notes/mention.vue";
|
||||||
export const useParsedContent = (
|
export const useParsedContent = (
|
||||||
content: string,
|
content: string,
|
||||||
emojis: Emoji[],
|
emojis: Emoji[],
|
||||||
mentions: Account[],
|
mentions: MaybeRef<Account[]> = ref([]),
|
||||||
): Ref<string | null> => {
|
): Ref<string | null> => {
|
||||||
const result = ref(null as string | null);
|
const result = ref(null as string | null);
|
||||||
|
|
||||||
(async () => {
|
watch(
|
||||||
|
mentions,
|
||||||
|
async () => {
|
||||||
const contentHtml = document.createElement("div");
|
const contentHtml = document.createElement("div");
|
||||||
contentHtml.innerHTML = content;
|
contentHtml.innerHTML = content;
|
||||||
|
|
||||||
|
|
@ -27,7 +29,9 @@ export const useParsedContent = (
|
||||||
paragraph.innerHTML = paragraph.innerHTML.replace(
|
paragraph.innerHTML = paragraph.innerHTML.replace(
|
||||||
/:([a-z0-9_-]+):/g,
|
/:([a-z0-9_-]+):/g,
|
||||||
(match, emoji) => {
|
(match, emoji) => {
|
||||||
const emojiData = emojis.find((e) => e.shortcode === emoji);
|
const emojiData = emojis.find(
|
||||||
|
(e) => e.shortcode === emoji,
|
||||||
|
);
|
||||||
if (!emojiData) {
|
if (!emojiData) {
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
@ -46,7 +50,7 @@ export const useParsedContent = (
|
||||||
const links = contentHtml.querySelectorAll("a");
|
const links = contentHtml.querySelectorAll("a");
|
||||||
|
|
||||||
for (const link of links) {
|
for (const link of links) {
|
||||||
const mention = mentions.find(
|
const mention = toValue(mentions).find(
|
||||||
(m) => link.textContent === `@${m.acct}`,
|
(m) => link.textContent === `@${m.acct}`,
|
||||||
);
|
);
|
||||||
if (!mention) {
|
if (!mention) {
|
||||||
|
|
@ -69,7 +73,9 @@ export const useParsedContent = (
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const newCode = (await getShikiHighlighter()).highlight(code, {
|
const newCode = (await getShikiHighlighter()).highlight(code, {
|
||||||
lang: codeBlock.getAttribute("class")?.replace("language-", ""),
|
lang: codeBlock
|
||||||
|
.getAttribute("class")
|
||||||
|
?.replace("language-", ""),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Replace parent pre tag with highlighted code
|
// Replace parent pre tag with highlighted code
|
||||||
|
|
@ -81,7 +87,9 @@ export const useParsedContent = (
|
||||||
}
|
}
|
||||||
|
|
||||||
result.value = contentHtml.innerHTML;
|
result.value = contentHtml.innerHTML;
|
||||||
})();
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,24 @@ import type { Mastodon } from "megalodon";
|
||||||
import type { Account } from "~/types/mastodon/account";
|
import type { Account } from "~/types/mastodon/account";
|
||||||
import type { Mention } from "~/types/mastodon/mention";
|
import type { Mention } from "~/types/mastodon/mention";
|
||||||
|
|
||||||
export const useResolveMentions = async (
|
export const useResolveMentions = (
|
||||||
mentions: Mention[],
|
mentions: Mention[],
|
||||||
client: Mastodon | null,
|
client: Mastodon | null,
|
||||||
): Promise<Ref<Account[]>> => {
|
): Ref<Account[]> => {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
return ref([]);
|
return ref([]);
|
||||||
}
|
}
|
||||||
return ref(
|
|
||||||
await Promise.all(
|
const output = ref<Account[]>([]);
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
output.value = await Promise.all(
|
||||||
mentions.map(async (mention) => {
|
mentions.map(async (mention) => {
|
||||||
const response = await client.getAccount(mention.id);
|
const response = await client.getAccount(mention.id);
|
||||||
return response.data;
|
return response.data;
|
||||||
}),
|
}),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
})();
|
||||||
|
|
||||||
|
return output;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@
|
||||||
</aside>
|
</aside>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<ComposerModal />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|
@ -71,4 +72,12 @@ useServerSeoMeta({
|
||||||
colorScheme: "dark",
|
colorScheme: "dark",
|
||||||
referrer: "no-referrer",
|
referrer: "no-referrer",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { n } = useMagicKeys();
|
||||||
|
|
||||||
|
watchEffect(() => {
|
||||||
|
if (n.value) {
|
||||||
|
useEvent("composer:open");
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -10,6 +10,7 @@ export default defineNuxtConfig({
|
||||||
"@vee-validate/nuxt",
|
"@vee-validate/nuxt",
|
||||||
"nuxt-shiki",
|
"nuxt-shiki",
|
||||||
],
|
],
|
||||||
|
|
||||||
app: {
|
app: {
|
||||||
head: {
|
head: {
|
||||||
link: [
|
link: [
|
||||||
|
|
@ -22,6 +23,7 @@ export default defineNuxtConfig({
|
||||||
htmlAttrs: { lang: "en-us" },
|
htmlAttrs: { lang: "en-us" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
shiki: {
|
shiki: {
|
||||||
defaultTheme: "rose-pine",
|
defaultTheme: "rose-pine",
|
||||||
bundledLangs: [
|
bundledLangs: [
|
||||||
|
|
@ -40,6 +42,7 @@ export default defineNuxtConfig({
|
||||||
"yaml",
|
"yaml",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
nitro: {
|
nitro: {
|
||||||
preset: "bun",
|
preset: "bun",
|
||||||
minify: true,
|
minify: true,
|
||||||
|
|
@ -51,12 +54,15 @@ export default defineNuxtConfig({
|
||||||
gzip: false,
|
gzip: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
schemaOrg: {
|
schemaOrg: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
ogImage: {
|
ogImage: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
vite: {
|
vite: {
|
||||||
define: {
|
define: {
|
||||||
__VERSION__: JSON.stringify("0.4"),
|
__VERSION__: JSON.stringify("0.4"),
|
||||||
|
|
@ -69,6 +75,7 @@ export default defineNuxtConfig({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
veeValidate: {
|
veeValidate: {
|
||||||
autoImports: true,
|
autoImports: true,
|
||||||
componentNames: {
|
componentNames: {
|
||||||
|
|
@ -78,6 +85,7 @@ export default defineNuxtConfig({
|
||||||
ErrorMessage: "VeeErrorMessage",
|
ErrorMessage: "VeeErrorMessage",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
runtimeConfig: {
|
runtimeConfig: {
|
||||||
public: {
|
public: {
|
||||||
language: "en-US",
|
language: "en-US",
|
||||||
|
|
@ -87,7 +95,12 @@ export default defineNuxtConfig({
|
||||||
apiHost: "https://social.lysand.org",
|
apiHost: "https://social.lysand.org",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
site: {
|
site: {
|
||||||
url: "https://social.lysand.org",
|
url: "https://social.lysand.org",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
devtools: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
"c12": "^1.10.0",
|
"c12": "^1.10.0",
|
||||||
"html-to-text": "^9.0.5",
|
"html-to-text": "^9.0.5",
|
||||||
"megalodon": "^10.0.0",
|
"megalodon": "^10.0.0",
|
||||||
|
"mitt": "^3.0.1",
|
||||||
"nuxt": "^3.11.2",
|
"nuxt": "^3.11.2",
|
||||||
"nuxt-headlessui": "^1.2.0",
|
"nuxt-headlessui": "^1.2.0",
|
||||||
"nuxt-icon": "^0.6.10",
|
"nuxt-icon": "^0.6.10",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue