added timestamps to messages

This commit is contained in:
2025-12-15 17:33:13 +01:00
parent 0714088d4b
commit 5c1f5ab16b
5 changed files with 41 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
import { initAuth } from '../stores/auth.ts' import { initAuth } from '../stores/auth.ts'
const BASE_URL = 'http://192.168.1.183:8081' const BASE_URL = 'http://localhost:8080'
export async function apiFetch<T>( export async function apiFetch<T>(
path: string, path: string,

View File

@@ -6,7 +6,7 @@ defineProps<{ messages: Message[] }>()
<template> <template>
<ul> <ul>
<li v-for="(m, i) in messages" :key="i" class="message"> <li v-for="(m, i) in messages" :key="i" class="message">
<div class="sender">{{ m.sender }}</div> <div class="sender">{{ m.sender }} <span class="timestamp">{{ m.sent_at }}</span></div>
<div class="message-content">{{ m.content }}</div> <div class="message-content">{{ m.content }}</div>
</li> </li>
</ul> </ul>
@@ -20,14 +20,25 @@ ul {
} }
.message { .message {
margin-bottom: 1rem; margin-bottom: 0.5rem;
background-color: rgba(0, 0, 0, 0.2);
padding: 10px;
border-radius: var(--radius);
} }
.sender { .sender {
font-weight: bold; font-weight: bold;
font-size: 1.1rem;
margin-bottom: 0.25rem; margin-bottom: 0.25rem;
} }
.sender .timestamp {
font-weight: normal;
opacity: 0.7;
font-size: 0.85rem;
margin-left: 0.5rem;
}
.message-content { .message-content {
padding-left: 1rem; padding-left: 1rem;
white-space: pre-wrap; white-space: pre-wrap;

View File

@@ -1,5 +1,5 @@
import { createRouter, createWebHistory } from 'vue-router' import { createRouter, createWebHistory } from 'vue-router'
import { initAuth } from '../stores/auth.ts' import { initAuth, validateToken } from '../stores/auth.ts'
import LoginPage from '../pages/LoginPage.vue' import LoginPage from '../pages/LoginPage.vue'
import RoomsPage from '../pages/RoomsPage.vue' import RoomsPage from '../pages/RoomsPage.vue'
@@ -16,9 +16,15 @@ const router = createRouter({
router.beforeEach(async (to) => { router.beforeEach(async (to) => {
const auth = await initAuth() const auth = await initAuth()
if (!auth.isAuthenticated && to.path !== '/login') { if (!auth.isAuthenticated && to.path !== '/login') {
return '/login' return '/login'
} }
if (auth.isAuthenticated) {
const valid = await validateToken()
if (!valid) return '/login'
}
}) })
export default router export default router

View File

@@ -6,7 +6,7 @@ let store: Store | null = null
async function getStore() { async function getStore() {
if (!store) { if (!store) {
store = await load('store.json', { autoSave: false }) store = await load('store.json')
} }
return store return store
} }
@@ -39,3 +39,21 @@ export async function logout() {
await s.save() await s.save()
return { token: null, uuid: null, isAuthenticated: false } return { token: null, uuid: null, isAuthenticated: false }
} }
export async function validateToken(): Promise<boolean> {
const auth = await initAuth()
if (!auth.token) return false
try {
await apiFetch('/validate-token', {
method: 'GET',
})
return true
} catch (e) {
console.log(e);
await logout()
return false
}
}

View File

@@ -13,5 +13,6 @@ export interface Message {
sender: string sender: string
message_type: 'text' message_type: 'text'
content: string content: string
sent_at: string
} }