-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSessionsHistory.vue
More file actions
88 lines (74 loc) · 3.35 KB
/
Copy pathSessionsHistory.vue
File metadata and controls
88 lines (74 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<template>
<div class="absolute top-0 left-0 transition-transform
duration-200 ease-in-out border-y border-r dark:border-gray-600 z-20
bg-lightNavbar dark:bg-darkNavbar w-96 h-full flex flex-col items-center
overflow-y-auto overflow-x-hidden
"
>
<h3 :class="h3Style">{{ $t('Chat history') }}</h3>
<div class="w-full flex items-center justify-center">
</div>
<div class="w-full border-b border-gray-200 dark:border-gray-700"/>
<div v-for="group in groupedSessions" :key="group.dayKey" class="w-full py-2">
<div class="px-4 pb-2 text-xs font-semibold uppercase tracking-[0.2em] text-gray-500 dark:text-gray-400">
{{ group.label }}
</div>
<button
v-for="session in group.sessions"
:key="session.sessionId"
class=" flex items-center justify-between w-full px-4 py-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors duration-200 ease-in-out text-gray-800 dark:text-gray-200"
:class="{
'bg-lightPrimary/20 hover:bg-lightPrimary/20 dark:bg-darkPrimary/20 dark:hover:bg-darkPrimary/20': agentStore.activeSessionId === session.sessionId,
}"
@click="agentStore.setActiveSession(session.sessionId); agentStore.setSessionHistoryOpen(false);"
>
<p class="truncate">{{ session.title || session.sessionId }}</p>
<div @click.stop="agentStore.deleteSession(session.sessionId)" class="w-7 h-7 p-1 hover:scale-110 hover:bg-gray-200 dark:hover:bg-gray-500 flex items-center justify-center rounded">
<IconPlusOutline class="rotate-45 w-6 h-6"/>
</div>
</button>
</div>
<p
v-if="!groupedSessions || groupedSessions.length === 0"
class="w-full h-full flex items-center justify-center text-gray-800 dark:text-gray-200"
>
{{ $t('There are no previous chat sessions') }}
</p>
</div>
</template>
<script setup lang="ts">
import { Button, Spinner } from '@/afcl'
import { computed } from 'vue';
import { IconPlusOutline } from '@iconify-prerendered/vue-flowbite';
import type { ISessionsListItem } from './types';
import { useAgentStore } from './composables/useAgentStore';
const agentStore = useAgentStore();
const h3Style = "text-gray-800 dark:text-gray-200 font-medium text-xl tracking-widest my-2"
const dayLabelFormatter = new Intl.DateTimeFormat(undefined, { month: 'short', day: 'numeric' });
const dayLabelWithYearFormatter = new Intl.DateTimeFormat(undefined, { month: 'short', day: 'numeric', year: 'numeric' });
const groupedSessions = computed(() => {
const groups = new Map<string, { dayKey: string; label: string; sessions: ISessionsListItem[] }>();
for (const session of agentStore.sessionList) {
const date = new Date(session.timestamp);
const dayKey = getLocalDayKey(date);
const label = date.getFullYear() === new Date().getFullYear()
? dayLabelFormatter.format(date)
: dayLabelWithYearFormatter.format(date);
if (!groups.has(dayKey)) {
groups.set(dayKey, {
dayKey,
label,
sessions: [],
});
}
groups.get(dayKey)!.sessions.push(session);
}
return Array.from(groups.values());
});
function getLocalDayKey(date: Date) {
const year = date.getFullYear();
const month = `${date.getMonth() + 1}`.padStart(2, '0');
const day = `${date.getDate()}`.padStart(2, '0');
return `${year}-${month}-${day}`;
}
</script>