refactor: ♻️ Simplify Note code with a provide/inject pattern
Some checks failed
CodeQL / Analyze (javascript) (push) Failing after 1s
Deploy to GitHub Pages / build (push) Failing after 0s
Deploy to GitHub Pages / deploy (push) Has been skipped
Docker / build (push) Failing after 0s
Mirror to Codeberg / Mirror (push) Failing after 0s

This commit is contained in:
Jesse Wierzbinski 2026-01-09 23:10:45 +01:00
parent b23ed66401
commit f5918cc7f9
No known key found for this signature in database
12 changed files with 140 additions and 199 deletions

View file

@ -1,7 +1,7 @@
<template>
<div class="flex flex-col gap-1">
<p class="text-sm leading-6 wrap-anywhere">
{{ contentWarning || m.sour_seemly_bird_hike() }}
{{ note.spoiler_text || m.sour_seemly_bird_hike() }}
</p>
<Button
@click="hidden = !hidden"
@ -11,9 +11,7 @@
>
{{ hidden ? m.bald_direct_turtle_win() :
m.known_flaky_cockroach_dash() }}
{{ characterCount > 0 ? ` (${characterCount} characters` : "" }}
{{ attachmentCount > 0 ? `${characterCount > 0 ? " · " : " ("}${attachmentCount} file(s)` : "" }}
{{ (characterCount > 0 || attachmentCount > 0) ? ")" : "" }}
{{ constructText() }}
</Button>
</div>
</template>
@ -21,14 +19,33 @@
<script lang="ts" setup>
import * as m from "~~/paraglide/messages.js";
import { Button } from "../ui/button";
import { key } from "./provider";
const { contentWarning, characterCount, attachmentCount } = defineProps<{
contentWarning?: string;
characterCount: number;
attachmentCount: number;
}>();
// biome-ignore lint/style/noNonNullAssertion: We want an error if not provided
const { note } = inject(key)!;
const attachmentCount = note.media_attachments.length;
const characterCount = note.text?.length || 0;
const hidden = defineModel<boolean>({
default: true,
});
const constructText = () => {
const parts: string[] = [];
if (characterCount > 0) {
parts.push(
`${characterCount} character${characterCount === 1 ? "" : "s"}`,
);
}
if (attachmentCount > 0) {
parts.push(
`${attachmentCount} file${attachmentCount === 1 ? "" : "s"}`,
);
}
return parts.length > 0 ? ` (${parts.join(" · ")})` : "";
};
</script>