mirror of
https://github.com/versia-pub/frontend.git
synced 2026-06-14 15:39:15 +02:00
refactor: ♻️ Simplify Note code with a provide/inject pattern
Some checks failed
Some checks failed
This commit is contained in:
parent
b23ed66401
commit
f5918cc7f9
12 changed files with 140 additions and 199 deletions
|
|
@ -1,51 +1,40 @@
|
|||
<template>
|
||||
<ContentWarning
|
||||
v-if="(sensitive || contentWarning) && preferences.show_content_warning"
|
||||
:content-warning="contentWarning"
|
||||
:character-count="characterCount ?? 0"
|
||||
:attachment-count="attachments.length"
|
||||
v-if="(note.sensitive || note.spoiler_text) && preferences.show_content_warning"
|
||||
v-model="hidden"
|
||||
/>
|
||||
|
||||
<OverflowGuard
|
||||
v-if="content"
|
||||
v-if="note.content"
|
||||
:character-count="characterCount"
|
||||
:class="(hidden && preferences.show_content_warning) && 'hidden'"
|
||||
>
|
||||
<Prose v-html="content" v-render-emojis="emojis"></Prose>
|
||||
<Prose v-html="note.content" v-render-emojis="note.emojis"></Prose>
|
||||
</OverflowGuard>
|
||||
|
||||
<Attachments
|
||||
v-if="attachments.length > 0"
|
||||
:attachments="attachments"
|
||||
v-if="note.media_attachments.length > 0"
|
||||
:attachments="note.media_attachments"
|
||||
:class="(hidden && preferences.show_content_warning) && 'hidden'"
|
||||
/>
|
||||
|
||||
<div v-if="quote" class="mt-4 rounded border overflow-hidden">
|
||||
<Note :note="quote" :hide-actions="true" :small-layout="true" />
|
||||
<div v-if="note.quote" class="mt-4 rounded border overflow-hidden">
|
||||
<Note :note="note.quote" :hide-actions="true" :small-layout="true" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { Attachment, CustomEmoji, Status } from "@versia/client/schemas";
|
||||
import type { z } from "zod";
|
||||
import Attachments from "./attachments.vue";
|
||||
import ContentWarning from "./content-warning.vue";
|
||||
import Note from "./note.vue";
|
||||
import OverflowGuard from "./overflow-guard.vue";
|
||||
import Prose from "./prose.vue";
|
||||
import { key } from "./provider";
|
||||
|
||||
const { content, plainContent, sensitive, contentWarning } = defineProps<{
|
||||
plainContent?: string;
|
||||
content: string;
|
||||
quote?: NonNullable<z.infer<typeof Status.shape.quote>>;
|
||||
emojis: z.infer<typeof CustomEmoji>[];
|
||||
attachments: z.infer<typeof Attachment>[];
|
||||
sensitive: boolean;
|
||||
contentWarning?: string;
|
||||
}>();
|
||||
// biome-ignore lint/style/noNonNullAssertion: We want an error if not provided
|
||||
const { note } = inject(key)!;
|
||||
|
||||
const hidden = ref(sensitive || !!contentWarning);
|
||||
const hidden = ref(note.sensitive || !!note.spoiler_text);
|
||||
|
||||
const characterCount = plainContent?.length;
|
||||
const characterCount = note.text?.length;
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue