polishing
This commit is contained in:
@@ -32,7 +32,7 @@ const props = withDefaults(
|
||||
display_name: string | null;
|
||||
} | null;
|
||||
}>;
|
||||
dynamicId: number;
|
||||
dynamicId: string;
|
||||
initialMessages: {
|
||||
data: Array<any>;
|
||||
next_page_url: string | null;
|
||||
@@ -92,6 +92,7 @@ useEcho(`chats.${props.chat.id}`, 'MessageSent', (e: any) => {
|
||||
|
||||
function formatTimestamp(isoString: string): { full: string; time: string } {
|
||||
const date = new Date(isoString);
|
||||
|
||||
return {
|
||||
full: date.toLocaleString(),
|
||||
time: date.toLocaleTimeString([], {
|
||||
@@ -108,6 +109,7 @@ const participantsById = computed(() => {
|
||||
return list.reduce(
|
||||
(acc, p) => {
|
||||
acc[p.id] = p;
|
||||
|
||||
return acc;
|
||||
},
|
||||
{} as Record<
|
||||
@@ -133,12 +135,15 @@ function parseMessageContent(message: {
|
||||
const userRegex = /<user:(\d+)>/g;
|
||||
content = content.replace(userRegex, (match, userId) => {
|
||||
const user = participantsById.value[Number(userId)];
|
||||
|
||||
if (user) {
|
||||
const url = route('dynamics.users.show', [props.dynamicId, Number(userId)]);
|
||||
|
||||
return `<a href="${url}" class="c-chat__user-link font-semibold text-blue-500 hover:underline">${
|
||||
user.pivot?.display_name ?? user.name
|
||||
}</a>`;
|
||||
}
|
||||
|
||||
return `User #${userId}`;
|
||||
});
|
||||
|
||||
@@ -183,6 +188,7 @@ function parseMessageContent(message: {
|
||||
|
||||
function handleFileChange(event: Event) {
|
||||
const files = (event.target as HTMLInputElement).files;
|
||||
|
||||
if (files) {
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
form.media.push(files[i]);
|
||||
@@ -200,6 +206,7 @@ function isOwnMessage(messageUserId: number | null): boolean {
|
||||
if (messageUserId === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return currentUser.value && currentUser.value.id === messageUserId;
|
||||
}
|
||||
|
||||
@@ -207,6 +214,7 @@ function submit() {
|
||||
form.post(route('chats.messages.store', props.chat.id), {
|
||||
onSuccess: () => {
|
||||
form.reset();
|
||||
|
||||
if (fileInput.value) {
|
||||
fileInput.value.value = '';
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ import { Link } from '@inertiajs/vue3';
|
||||
import { route } from 'ziggy-js';
|
||||
|
||||
defineProps<{
|
||||
dynamicId: number;
|
||||
dynamicId: string;
|
||||
ledgers: Array<{
|
||||
id: number;
|
||||
id: string;
|
||||
name: string;
|
||||
score: number;
|
||||
alignment: string;
|
||||
|
||||
@@ -3,9 +3,9 @@ import { Link } from '@inertiajs/vue3';
|
||||
import { route } from 'ziggy-js';
|
||||
|
||||
defineProps<{
|
||||
dynamicId: number;
|
||||
dynamicId: string;
|
||||
participants: Array<{
|
||||
id: number;
|
||||
id: string;
|
||||
name: string;
|
||||
pivot: {
|
||||
display_name: string | null;
|
||||
|
||||
Reference in New Issue
Block a user