frontend/app/components/notes/header.vue

77 lines
2.4 KiB
Vue
Raw Normal View History

2024-11-30 02:19:32 +01:00
<template>
2025-12-09 23:26:59 +01:00
<div class="flex items-start justify-between">
<div class="flex items-center gap-3">
<NuxtLink :href="urlAsPath">
<Avatar
:src="note.account.avatar"
:name="note.account.display_name"
/>
2025-12-09 23:26:59 +01:00
</NuxtLink>
<div class="flex flex-col gap-0.5">
<div class="flex items-center gap-1">
<span
class="text-sm font-semibold"
v-render-emojis="note.account.emojis"
>{{ note.account.display_name }}</span
2025-12-09 23:26:59 +01:00
>
</div>
<div
class="flex items-center gap-1 text-muted-foreground text-xs"
2025-12-09 22:32:22 +01:00
>
2025-12-09 23:26:59 +01:00
<span>
@{{ `${username}${instance ? `@${instance}` : ""}` }}
</span>
<span>&middot;</span>
<span>{{ timeAgo }}</span>
</div>
</div>
2024-11-30 02:19:32 +01:00
</div>
<Menu @edit="emit('edit')" @delete="emit('delete')">
2025-12-09 23:26:59 +01:00
<Button variant="ghost" size="icon">
2026-01-09 21:47:12 +01:00
<Ellipsis />
2025-12-09 23:26:59 +01:00
</Button>
</Menu>
</div>
2024-11-30 02:19:32 +01:00
</template>
<script lang="ts" setup>
import type {
UseTimeAgoMessages,
UseTimeAgoUnitNamesDefault,
} from "@vueuse/core";
import { Ellipsis } from "lucide-vue-next";
import Avatar from "../profiles/avatar.vue";
2025-12-09 23:26:59 +01:00
import { Button } from "../ui/button";
import Menu from "./menu.vue";
import { key } from "./provider";
2024-11-30 02:19:32 +01:00
// biome-ignore lint/style/noNonNullAssertion: We want an error if not provided
const { note } = inject(key)!;
2024-11-30 02:19:32 +01:00
const [username, instance] = note.account.acct.split("@");
const digitRegex = /\d/;
const accountUrl = wrapUrl(`/@${note.account.acct}`);
const urlAsPath = new URL(accountUrl).pathname;
const timeAgo = useTimeAgo(note.created_at, {
messages: {
justNow: "now",
past: (n) => (n.match(digitRegex) ? `${n}` : n),
future: (n) => (n.match(digitRegex) ? `in ${n}` : n),
month: (n) => `${n}mo`,
year: (n) => `${n}y`,
day: (n) => `${n}d`,
week: (n) => `${n}w`,
hour: (n) => `${n}h`,
minute: (n) => `${n}m`,
second: (n) => `${n}s`,
invalid: "",
} as UseTimeAgoMessages<UseTimeAgoUnitNamesDefault>,
});
2024-11-30 02:19:32 +01:00
2025-12-09 23:26:59 +01:00
const emit = defineEmits<{
edit: [];
delete: [];
}>();
</script>