tauri-app: initial tests
Some checks failed
record-daemon / Build, check and test (push) Failing after 53s
Some checks failed
record-daemon / Build, check and test (push) Failing after 53s
This commit is contained in:
@@ -1,160 +1,41 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
const greetMsg = ref("");
|
||||
const name = ref("");
|
||||
|
||||
async function greet() {
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
greetMsg.value = await invoke("greet", { name: name.value });
|
||||
}
|
||||
import GameHistory from "./components/GameHistory.vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="container">
|
||||
<h1>Welcome to Tauri + Vue</h1>
|
||||
|
||||
<div class="row">
|
||||
<a href="https://vitejs.dev" target="_blank">
|
||||
<img src="/vite.svg" class="logo vite" alt="Vite logo" />
|
||||
</a>
|
||||
<a href="https://tauri.app" target="_blank">
|
||||
<img src="/tauri.svg" class="logo tauri" alt="Tauri logo" />
|
||||
</a>
|
||||
<a href="https://vuejs.org/" target="_blank">
|
||||
<img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
|
||||
</a>
|
||||
</div>
|
||||
<p>Click on the Tauri, Vite, and Vue logos to learn more.</p>
|
||||
|
||||
<form class="row" @submit.prevent="greet">
|
||||
<input id="greet-input" v-model="name" placeholder="Enter a name..." />
|
||||
<button type="submit">Greet</button>
|
||||
</form>
|
||||
<p>{{ greetMsg }}</p>
|
||||
</main>
|
||||
<GameHistory />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.logo.vite:hover {
|
||||
filter: drop-shadow(0 0 2em #747bff);
|
||||
}
|
||||
|
||||
.logo.vue:hover {
|
||||
filter: drop-shadow(0 0 2em #249b73);
|
||||
}
|
||||
|
||||
</style>
|
||||
<style>
|
||||
:root {
|
||||
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
font-weight: 400;
|
||||
/* Global styles */
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
color: #0f0f0f;
|
||||
background-color: #f6f6f6;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
body {
|
||||
font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
||||
Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
.container {
|
||||
margin: 0;
|
||||
padding-top: 10vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: 0.75s;
|
||||
::-webkit-scrollbar-track {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.logo.tauri:hover {
|
||||
filter: drop-shadow(0 0 2em #24c8db);
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
input,
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
color: #0f0f0f;
|
||||
background-color: #ffffff;
|
||||
transition: border-color 0.25s;
|
||||
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
border-color: #396cd8;
|
||||
}
|
||||
button:active {
|
||||
border-color: #396cd8;
|
||||
background-color: #e8e8e8;
|
||||
}
|
||||
|
||||
input,
|
||||
button {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
#greet-input {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
color: #f6f6f6;
|
||||
background-color: #2f2f2f;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #24c8db;
|
||||
}
|
||||
|
||||
input,
|
||||
button {
|
||||
color: #ffffff;
|
||||
background-color: #0f0f0f98;
|
||||
}
|
||||
button:active {
|
||||
background-color: #0f0f0f69;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
</style>
|
||||
|
||||
456
tauri-app/src/components/GameHistory.vue
Normal file
456
tauri-app/src/components/GameHistory.vue
Normal file
@@ -0,0 +1,456 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from "vue";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import type { GameHistoryItem } from "../types/timeline";
|
||||
import { formatRelativeTime } from "../types/timeline";
|
||||
|
||||
const games = ref<GameHistoryItem[]>([]);
|
||||
const loading = ref(true);
|
||||
const error = ref<string | null>(null);
|
||||
const selectedGame = ref<GameHistoryItem | null>(null);
|
||||
|
||||
async function loadGameHistory() {
|
||||
try {
|
||||
loading.value = true;
|
||||
error.value = null;
|
||||
games.value = await invoke<GameHistoryItem[]>("get_game_history");
|
||||
} catch (e) {
|
||||
error.value = `Failed to load game history: ${e}`;
|
||||
console.error("Failed to load game history:", e);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function selectGame(game: GameHistoryItem) {
|
||||
selectedGame.value = game;
|
||||
}
|
||||
|
||||
function closeDetail() {
|
||||
selectedGame.value = null;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadGameHistory();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="game-history">
|
||||
<header class="header">
|
||||
<h1>League Recorder</h1>
|
||||
<p class="subtitle">Game History</p>
|
||||
</header>
|
||||
|
||||
<!-- Loading State -->
|
||||
<div v-if="loading" class="loading">
|
||||
<div class="spinner"></div>
|
||||
<p>Loading game history...</p>
|
||||
</div>
|
||||
|
||||
<!-- Error State -->
|
||||
<div v-else-if="error" class="error">
|
||||
<p>{{ error }}</p>
|
||||
<button @click="loadGameHistory">Retry</button>
|
||||
</div>
|
||||
|
||||
<!-- Empty State -->
|
||||
<div v-else-if="games.length === 0" class="empty">
|
||||
<div class="empty-icon">🎮</div>
|
||||
<h2>No Games Recorded</h2>
|
||||
<p>Start playing to see your game history here.</p>
|
||||
</div>
|
||||
|
||||
<!-- Game List -->
|
||||
<div v-else class="game-list">
|
||||
<div
|
||||
v-for="game in games"
|
||||
:key="game.id"
|
||||
class="game-card"
|
||||
:class="{ victory: game.result === 'Victory', defeat: game.result === 'Defeat' }"
|
||||
@click="selectGame(game)"
|
||||
>
|
||||
<div class="game-result-badge" v-if="game.result">
|
||||
{{ game.result }}
|
||||
</div>
|
||||
|
||||
<div class="game-main">
|
||||
<div class="game-champion" v-if="game.champion">
|
||||
{{ game.champion }}
|
||||
</div>
|
||||
<div class="game-champion unknown" v-else>
|
||||
Unknown Champion
|
||||
</div>
|
||||
|
||||
<div class="game-duration">
|
||||
{{ game.duration_formatted }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="game-meta">
|
||||
<span class="game-time">{{ formatRelativeTime(game.start_time) }}</span>
|
||||
<span class="game-events">{{ game.event_count }} events</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Game Detail Modal -->
|
||||
<div v-if="selectedGame" class="modal-overlay" @click.self="closeDetail">
|
||||
<div class="modal">
|
||||
<button class="modal-close" @click="closeDetail">×</button>
|
||||
|
||||
<div class="modal-header">
|
||||
<h2>Game Details</h2>
|
||||
<div class="modal-result" :class="selectedGame.result?.toLowerCase()">
|
||||
{{ selectedGame.result || 'Unknown Result' }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Champion:</span>
|
||||
<span class="detail-value">{{ selectedGame.champion || 'Unknown' }}</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Duration:</span>
|
||||
<span class="detail-value">{{ selectedGame.duration_formatted }}</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Started:</span>
|
||||
<span class="detail-value">{{ new Date(selectedGame.start_time).toLocaleString() }}</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Events:</span>
|
||||
<span class="detail-value">{{ selectedGame.event_count }}</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-row" v-if="selectedGame.video_path">
|
||||
<span class="detail-label">Video:</span>
|
||||
<span class="detail-value video-path">{{ selectedGame.video_path }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-actions">
|
||||
<button class="btn-secondary" @click="closeDetail">Close</button>
|
||||
<button class="btn-primary" v-if="selectedGame.video_path">
|
||||
Open Video
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.game-history {
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
|
||||
color: #fff;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.5rem;
|
||||
margin: 0;
|
||||
background: linear-gradient(90deg, #00d4ff, #7b2cbf);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: #888;
|
||||
margin: 0.5rem 0 0 0;
|
||||
}
|
||||
|
||||
.loading {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 50vh;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 3px solid #333;
|
||||
border-top-color: #00d4ff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.error {
|
||||
text-align: center;
|
||||
padding: 2rem;
|
||||
color: #ff6b6b;
|
||||
}
|
||||
|
||||
.error button {
|
||||
margin-top: 1rem;
|
||||
padding: 0.5rem 1rem;
|
||||
background: #ff6b6b;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.empty {
|
||||
text-align: center;
|
||||
padding: 4rem 2rem;
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 4rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.empty h2 {
|
||||
margin: 0 0 0.5rem 0;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.empty p {
|
||||
color: #888;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.game-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||
gap: 1rem;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.game-card {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 12px;
|
||||
padding: 1.25rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.game-card:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.game-card.victory {
|
||||
border-left: 4px solid #4ade80;
|
||||
}
|
||||
|
||||
.game-card.defeat {
|
||||
border-left: 4px solid #f87171;
|
||||
}
|
||||
|
||||
.game-result-badge {
|
||||
position: absolute;
|
||||
top: 0.75rem;
|
||||
right: 0.75rem;
|
||||
font-size: 0.7rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.game-card.victory .game-result-badge {
|
||||
background: rgba(74, 222, 128, 0.2);
|
||||
color: #4ade80;
|
||||
}
|
||||
|
||||
.game-card.defeat .game-result-badge {
|
||||
background: rgba(248, 113, 113, 0.2);
|
||||
color: #f87171;
|
||||
}
|
||||
|
||||
.game-main {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.game-champion {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.game-champion.unknown {
|
||||
color: #888;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.game-duration {
|
||||
font-size: 1.1rem;
|
||||
font-family: monospace;
|
||||
color: #00d4ff;
|
||||
}
|
||||
|
||||
.game-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 0.85rem;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
/* Modal Styles */
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.modal {
|
||||
background: #1a1a2e;
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
max-width: 500px;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
position: absolute;
|
||||
top: 1rem;
|
||||
right: 1rem;
|
||||
background: none;
|
||||
border: none;
|
||||
color: #888;
|
||||
font-size: 1.5rem;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.modal-close:hover {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.modal-header h2 {
|
||||
margin: 0;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.modal-result {
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
padding: 0.25rem 0.75rem;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.modal-result.victory {
|
||||
background: rgba(74, 222, 128, 0.2);
|
||||
color: #4ade80;
|
||||
}
|
||||
|
||||
.modal-result.defeat {
|
||||
background: rgba(248, 113, 113, 0.2);
|
||||
color: #f87171;
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.detail-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 0.75rem 0;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.detail-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.detail-label {
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.detail-value {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.video-path {
|
||||
font-size: 0.85rem;
|
||||
color: #00d4ff;
|
||||
max-width: 250px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.btn-primary,
|
||||
.btn-secondary {
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 8px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: linear-gradient(90deg, #00d4ff, #7b2cbf);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
opacity: 0.9;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
}
|
||||
</style>
|
||||
154
tauri-app/src/types/timeline.ts
Normal file
154
tauri-app/src/types/timeline.ts
Normal file
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* TypeScript types for timeline data from the record-daemon.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A timestamped event in the timeline.
|
||||
*/
|
||||
export interface TimestampedEvent {
|
||||
/** Video timestamp (offset from recording start) in seconds. */
|
||||
video_timestamp: number;
|
||||
/** Game timestamp (in-game time) in seconds. */
|
||||
game_timestamp: number | null;
|
||||
/** Real-world timestamp (ISO 8601). */
|
||||
timestamp: string;
|
||||
/** Event type name. */
|
||||
event_type: string;
|
||||
/** Human-readable description. */
|
||||
description: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A timeline of events for a recording.
|
||||
*/
|
||||
export interface Timeline {
|
||||
/** Recording ID (UUID). */
|
||||
recording_id: string;
|
||||
/** Recording start time (ISO 8601). */
|
||||
start_time: string;
|
||||
/** Recording end time (ISO 8601). */
|
||||
end_time: string | null;
|
||||
/** Total duration in seconds. */
|
||||
duration_secs: number;
|
||||
/** Events in the timeline. */
|
||||
events: TimestampedEvent[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Game history item for display in the UI.
|
||||
*/
|
||||
export interface GameHistoryItem {
|
||||
/** Recording ID (UUID). */
|
||||
id: string;
|
||||
/** Game start time (ISO 8601). */
|
||||
start_time: string;
|
||||
/** Game end time (ISO 8601). */
|
||||
end_time: string | null;
|
||||
/** Duration in seconds. */
|
||||
duration_secs: number;
|
||||
/** Formatted duration string (e.g., "32:15"). */
|
||||
duration_formatted: string;
|
||||
/** Number of events. */
|
||||
event_count: number;
|
||||
/** Champion played (if available). */
|
||||
champion: string | null;
|
||||
/** Game result (Victory/Defeat, if available). */
|
||||
result: string | null;
|
||||
/** Video file path. */
|
||||
video_path: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event type definitions for styling.
|
||||
*/
|
||||
export type EventCategory =
|
||||
| "kill"
|
||||
| "death"
|
||||
| "objective"
|
||||
| "game"
|
||||
| "phase"
|
||||
| "unknown";
|
||||
|
||||
/**
|
||||
* Get the category of an event for styling purposes.
|
||||
*/
|
||||
export function getEventCategory(eventType: string): EventCategory {
|
||||
switch (eventType.toLowerCase()) {
|
||||
case "kill":
|
||||
return "kill";
|
||||
case "death":
|
||||
return "death";
|
||||
case "objective":
|
||||
return "objective";
|
||||
case "gameend":
|
||||
case "gamestart":
|
||||
case "matchfound":
|
||||
return "game";
|
||||
case "phasechange":
|
||||
return "phase";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a human-readable label for an event type.
|
||||
*/
|
||||
export function getEventLabel(eventType: string): string {
|
||||
switch (eventType.toLowerCase()) {
|
||||
case "kill":
|
||||
return "Kill";
|
||||
case "death":
|
||||
return "Death";
|
||||
case "objective":
|
||||
return "Objective";
|
||||
case "gameend":
|
||||
return "Game End";
|
||||
case "gamestart":
|
||||
return "Game Start";
|
||||
case "matchfound":
|
||||
return "Match Found";
|
||||
case "phasechange":
|
||||
return "Phase Change";
|
||||
default:
|
||||
return eventType;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a date string for display.
|
||||
*/
|
||||
export function formatDateTime(isoString: string): string {
|
||||
const date = new Date(isoString);
|
||||
return date.toLocaleString(undefined, {
|
||||
year: "numeric",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a relative time (e.g., "2 hours ago").
|
||||
*/
|
||||
export function formatRelativeTime(isoString: string): string {
|
||||
const date = new Date(isoString);
|
||||
const now = new Date();
|
||||
const diffMs = now.getTime() - date.getTime();
|
||||
const diffMins = Math.floor(diffMs / 60000);
|
||||
const diffHours = Math.floor(diffMins / 60);
|
||||
const diffDays = Math.floor(diffHours / 24);
|
||||
|
||||
if (diffDays > 7) {
|
||||
return formatDateTime(isoString);
|
||||
} else if (diffDays > 0) {
|
||||
return `${diffDays} day${diffDays > 1 ? "s" : ""} ago`;
|
||||
} else if (diffHours > 0) {
|
||||
return `${diffHours} hour${diffHours > 1 ? "s" : ""} ago`;
|
||||
} else if (diffMins > 0) {
|
||||
return `${diffMins} minute${diffMins > 1 ? "s" : ""} ago`;
|
||||
} else {
|
||||
return "Just now";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user