Files
dredgegram/resources/js/pages/Messages/Show.vue
T
dredgy 3ce70b3701
linter / quality (push) Canceled after 0s
tests / ci (8.3) (push) Canceled after 0s
tests / ci (8.4) (push) Canceled after 0s
tests / ci (8.5) (push) Canceled after 0s
Initial Commit
2026-08-28 23:30:01 +10:00

120 lines
3.1 KiB
Vue

<script setup lang="ts">
import { ref, onMounted, computed } from 'vue';
import { Link } from '@inertiajs/vue3';
import AppLayout from '@/layouts/AppLayout.vue';
import MessageBubble from '@/components/dredge/Messages/MessageBubble.vue';
import type { ThreadDetail } from '@/types/dredge.types';
defineOptions({
layout: AppLayout,
});
const props = defineProps<{
threadId: string;
}>();
const ME = 'generictravelphotos';
const thread = ref<ThreadDetail | null>(null);
const loading = ref(true);
const error = ref<string | null>(null);
const threadName = computed(() => {
if (!thread.value) return '';
if (thread.value.thread_title) return thread.value.thread_title;
return thread.value.participants.map((p) => p.username).join(', ') || 'Unknown';
});
async function fetchThread() {
loading.value = true;
error.value = null;
try {
const response = await fetch(`/api/threads/${props.threadId}`);
if (!response.ok) {
throw new Error('Failed to load thread');
}
thread.value = await response.json();
} catch (e) {
error.value = 'Could not load this conversation.';
} finally {
loading.value = false;
}
}
function avatarFor(username: string | null): string | null {
if (!thread.value || !username) return null;
return thread.value.participants.find((p) => p.username === username)?.profile_pic_url ?? null;
}
onMounted(fetchThread);
</script>
<template>
<section class="thread">
<header class="thread__header">
<Link href="/messages" class="thread__back" aria-label="Back to messages">
<span class="mdi mdi-arrow-left"></span>
</Link>
<span class="thread__title">{{ threadName }}</span>
</header>
<p v-if="loading" class="thread__status">Loading conversation</p>
<p v-else-if="error" class="thread__status" role="alert">{{ error }}</p>
<div v-else class="thread__messages">
<MessageBubble
v-for="message in thread!.messages"
:key="message.id"
:message="message"
:is-own="message.username === ME"
:avatar-src="avatarFor(message.username)"
/>
</div>
</section>
</template>
<style scoped>
.thread {
display: flex;
flex-direction: column;
gap: 1rem;
}
.thread__header {
display: flex;
align-items: center;
gap: 0.75rem;
padding-bottom: 0.5rem;
border-bottom: 1px solid var(--line);
}
.thread__back {
display: flex;
align-items: center;
justify-content: center;
width: 2.2rem;
height: 2.2rem;
border-radius: 50%;
color: inherit;
text-decoration: none;
}
.thread__back:hover {
background: var(--panel);
}
.thread__title {
font-weight: 600;
font-size: 1rem;
}
.thread__status {
color: var(--sediment-dim);
}
.thread__messages {
display: flex;
flex-direction: column;
/* Slightly taller than a plain bubble gap so a floating reaction pill
on one bubble doesn't collide with the row below it. */
gap: 0.9rem;
}
</style>