Skip to content

Commit 41f2c36

Browse files
author
linyuan.yang
committed
chat view
1 parent bb6b5ae commit 41f2c36

5 files changed

Lines changed: 285 additions & 18 deletions

File tree

‎packages/chat-ui/src/components/ChatView.vue‎

Lines changed: 222 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import type {
99
} from '../types'
1010
import { MessageRole, ChatEventType, MessageKind } from '../types'
1111
import type { IChatTransport, CommandInfo } from '../transport'
12-
import { resolveLabels } from '../labels'
12+
import { resolveLabels, tpl } from '../labels'
1313
import { useCompactProvider } from '../composables/useCompact'
1414
import SessionBar from './SessionBar.vue'
1515
import ConfigToolbar from './ConfigToolbar.vue'
1616
import StatusBar from './StatusBar.vue'
1717
import ChatArea from './ChatArea.vue'
1818
import PathPickerModal from './PathPickerModal.vue'
1919
import WorkbenchPanel from './WorkbenchPanel.vue'
20-
import { useConfirm } from 'sbot-ui'
20+
import { SButton, SInput, SModal, useConfirm } from 'sbot-ui'
2121
2222
const props = withDefaults(defineProps<{
2323
transport: IChatTransport
@@ -63,6 +63,7 @@ const contentEl = ref<HTMLElement | null>(null)
6363
const isCompact = useCompactProvider(rootEl)
6464
const sidebarOpen = ref(false)
6565
const settingsOpen = ref(false)
66+
const compactMenuOpen = ref(false)
6667
const rightPanelOpen = ref(loadRightPanelOpenState())
6768
const rightPanelWidth = ref(420)
6869
const rightPanelResizing = ref(false)
@@ -71,6 +72,9 @@ const sessionBarResizing = ref(false)
7172
const sessionSearch = ref('')
7273
const sessionHighlightIndex = ref(0)
7374
const sessionSearchInputEl = ref<HTMLInputElement | null>(null)
75+
const renameDialogVisible = ref(false)
76+
const renameDraft = ref('')
77+
const renameInputEl = ref<InstanceType<typeof SInput> | null>(null)
7478
7579
// ── Derived ──
7680
@@ -243,12 +247,14 @@ function selectSession(id: string) {
243247
244248
function setSidebarOpen(open: boolean) {
245249
sidebarOpen.value = open
250+
if (open) compactMenuOpen.value = false
246251
}
247252
248253
function toggleSidebar() {
249254
sidebarOpen.value = !sidebarOpen.value
250255
if (sidebarOpen.value) {
251256
settingsOpen.value = false
257+
compactMenuOpen.value = false
252258
resetSessionSearch()
253259
nextTick(() => sessionSearchInputEl.value?.focus())
254260
}
@@ -300,7 +306,69 @@ function onSessionSearchKeydown(e: KeyboardEvent) {
300306
301307
function toggleSettings() {
302308
settingsOpen.value = !settingsOpen.value
303-
if (settingsOpen.value) sidebarOpen.value = false
309+
if (settingsOpen.value) {
310+
sidebarOpen.value = false
311+
compactMenuOpen.value = false
312+
}
313+
}
314+
315+
function toggleCompactMenu() {
316+
compactMenuOpen.value = !compactMenuOpen.value
317+
if (compactMenuOpen.value) {
318+
sidebarOpen.value = false
319+
settingsOpen.value = false
320+
}
321+
}
322+
323+
function closeRenameDialog() {
324+
renameDialogVisible.value = false
325+
}
326+
327+
function openRenameDialog() {
328+
const session = activeSession.value
329+
if (!session) return
330+
compactMenuOpen.value = false
331+
renameDraft.value = session.name || ''
332+
renameDialogVisible.value = true
333+
nextTick(() => {
334+
const root = (renameInputEl.value as any)?.$el as HTMLElement | undefined
335+
const input = root instanceof HTMLInputElement ? root : root?.querySelector('input')
336+
input?.focus()
337+
input?.select()
338+
})
339+
}
340+
341+
async function submitRenameDialog() {
342+
const session = activeSession.value
343+
const name = renameDraft.value.trim()
344+
if (!session || !name) return
345+
if (name !== (session.name || '')) {
346+
await onRenameSession(session.id, name)
347+
}
348+
closeRenameDialog()
349+
}
350+
351+
async function deleteActiveSessionFromMenu() {
352+
const session = activeSession.value
353+
if (!session) return
354+
compactMenuOpen.value = false
355+
const label = session.name || L.value.untitledSession
356+
if (await confirm(tpl(L.value.confirmDeleteSession, { name: label }), {
357+
danger: true,
358+
cancelText: L.value.cancel,
359+
})) {
360+
await onDeleteSession(session.id)
361+
}
362+
}
363+
364+
function onRenameDialogKeydown(e: KeyboardEvent) {
365+
if (e.key === 'Enter' && !e.isComposing) {
366+
e.preventDefault()
367+
void submitRenameDialog()
368+
} else if (e.key === 'Escape') {
369+
e.preventDefault()
370+
closeRenameDialog()
371+
}
304372
}
305373
306374
function setRightPanelOpen(open: boolean, persist = true) {
@@ -313,6 +381,7 @@ function toggleRightPanel() {
313381
if (rightPanelOpen.value && (isCompact.value || props.alwaysCompact)) {
314382
sidebarOpen.value = false
315383
settingsOpen.value = false
384+
compactMenuOpen.value = false
316385
}
317386
}
318387
@@ -462,6 +531,7 @@ async function createNewSession() {
462531
activeProfileId.value = res.id
463532
sidebarOpen.value = false
464533
settingsOpen.value = false
534+
compactMenuOpen.value = false
465535
} catch (e) {
466536
console.error('[ChatView] createSession', e)
467537
}
@@ -649,21 +719,27 @@ function saveRightPanelOpenState(open: boolean): void {
649719

650720
<template>
651721
<div ref="rootEl" class="chatui-root" :class="{ 'chatui-compact': isCompact || alwaysCompact, 'chatui-session-resizing': sessionBarResizing }">
652-
<!-- Compact mode (narrow screen or alwaysCompact): hamburger + drawer -->
722+
<!-- Compact mode (narrow screen or alwaysCompact): title opens the session drawer -->
653723
<template v-if="isCompact || alwaysCompact">
654724
<div class="chatui-compact-header">
655-
<span class="chatui-compact-title">{{ activeSession?.name || L.untitledSession }}</span>
725+
<button
726+
type="button"
727+
class="chatui-compact-title"
728+
:class="{ 'chatui-compact-title--active': sidebarOpen }"
729+
:title="L.sessionList"
730+
@click="toggleSidebar"
731+
>{{ activeSession?.name || L.untitledSession }}</button>
656732
<div class="chatui-compact-actions">
657733
<button
658734
class="chatui-compact-action"
659-
:class="{ 'chatui-compact-action--active': sidebarOpen }"
660-
:title="L.sessionList"
661-
@click="toggleSidebar"
735+
:class="{ 'chatui-compact-action--active': compactMenuOpen }"
736+
:title="L.sessionActions"
737+
@click="toggleCompactMenu"
662738
>
663-
<svg width="16" height="16" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round">
664-
<path d="M5 6h10"/>
665-
<path d="M5 10h10"/>
666-
<path d="M5 14h10"/>
739+
<svg width="16" height="16" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
740+
<circle cx="5" cy="10" r="1.4"/>
741+
<circle cx="10" cy="10" r="1.4"/>
742+
<circle cx="15" cy="10" r="1.4"/>
667743
</svg>
668744
</button>
669745
<button
@@ -686,6 +762,38 @@ function saveRightPanelOpenState(open: boolean): void {
686762
</button>
687763
</div>
688764
</div>
765+
<div v-if="compactMenuOpen" class="chatui-compact-menu-backdrop" @click="compactMenuOpen = false">
766+
<div class="chatui-compact-menu" @click.stop>
767+
<button
768+
type="button"
769+
class="chatui-compact-menu-item"
770+
:disabled="!activeSession"
771+
@click="openRenameDialog"
772+
>
773+
<svg width="15" height="15" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
774+
<path d="M11.5 4.5 15.5 8.5"/>
775+
<path d="M5 15l1.1-4.1 7.3-7.3a1.4 1.4 0 0 1 2 0l1 1a1.4 1.4 0 0 1 0 2l-7.3 7.3L5 15Z"/>
776+
<path d="M4 17h12"/>
777+
</svg>
778+
<span>{{ L.renameSession }}</span>
779+
</button>
780+
<button
781+
type="button"
782+
class="chatui-compact-menu-item chatui-compact-menu-item--danger"
783+
:disabled="!activeSession"
784+
@click="deleteActiveSessionFromMenu"
785+
>
786+
<svg width="15" height="15" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
787+
<path d="M4 6h12"/>
788+
<path d="M8 6V4.8A1.8 1.8 0 0 1 9.8 3h.4A1.8 1.8 0 0 1 12 4.8V6"/>
789+
<path d="m7 8 .4 7"/>
790+
<path d="m13 8-.4 7"/>
791+
<path d="M6 6l.7 10A1.5 1.5 0 0 0 8.2 17h3.6a1.5 1.5 0 0 0 1.5-1.4L14 6"/>
792+
</svg>
793+
<span>{{ L.deleteSession }}</span>
794+
</button>
795+
</div>
796+
</div>
689797
<Transition name="chatui-drawer">
690798
<div v-if="sidebarOpen" class="chatui-compact-popover-backdrop" @click="setSidebarOpen(false)">
691799
<div class="chatui-compact-popover chatui-session-popover" @click.stop>
@@ -716,6 +824,8 @@ function saveRightPanelOpenState(open: boolean): void {
716824
:highlighted-profile-id="highlightedProfileId"
717825
:labels="labels"
718826
:show-header="false"
827+
:show-delete="false"
828+
created-at-layout="inline"
719829
:empty-message="sessionSearch ? L.sessionNoMatch : undefined"
720830
@select="(id: string) => { selectSession(id); setSidebarOpen(false) }"
721831
@delete="onDeleteSession"
@@ -888,6 +998,27 @@ function saveRightPanelOpenState(open: boolean): void {
888998
:labels="labels"
889999
@confirm="onPathConfirmed"
8901000
/>
1001+
<SModal
1002+
:visible="renameDialogVisible"
1003+
:title="L.renameSession"
1004+
width="sm"
1005+
class="chatui-rename-dialog"
1006+
:close-on-overlay="false"
1007+
@close="closeRenameDialog"
1008+
>
1009+
<div class="chatui-rename-hint">{{ L.renameSessionHint }}</div>
1010+
<SInput
1011+
ref="renameInputEl"
1012+
v-model="renameDraft"
1013+
:placeholder="L.sessionNamePlaceholder"
1014+
autofocus
1015+
@keydown="onRenameDialogKeydown"
1016+
/>
1017+
<template #footer>
1018+
<SButton type="outline" @click="closeRenameDialog">{{ L.cancel }}</SButton>
1019+
<SButton :disabled="!renameDraft.trim()" @click="submitRenameDialog">{{ L.save }}</SButton>
1020+
</template>
1021+
</SModal>
8911022
</div>
8921023
</template>
8931024

@@ -1071,12 +1202,29 @@ function saveRightPanelOpenState(open: boolean): void {
10711202
border-bottom: 1px solid var(--chatui-border);
10721203
background: var(--chatui-bg-surface);
10731204
flex-shrink: 0;
1205+
position: relative;
10741206
}
10751207
.chatui-compact-title {
1208+
height: 26px;
1209+
padding: 0 6px;
1210+
margin-left: -6px;
1211+
border: none;
1212+
border-radius: 5px;
1213+
background: transparent;
1214+
font: inherit;
10761215
font-size: 13px; font-weight: 600; color: var(--chatui-fg);
10771216
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
1217+
text-align: left;
10781218
min-width: 0;
10791219
flex: 1;
1220+
cursor: pointer;
1221+
transition: background 0.15s, color 0.15s;
1222+
}
1223+
.chatui-compact-title:hover {
1224+
background: var(--chatui-bg-hover);
1225+
}
1226+
.chatui-compact-title--active {
1227+
background: var(--chatui-bg-active);
10801228
}
10811229
.chatui-compact-actions {
10821230
display: inline-flex; align-items: center; gap: 4px;
@@ -1099,6 +1247,68 @@ function saveRightPanelOpenState(open: boolean): void {
10991247
background: var(--chatui-bg-active);
11001248
color: var(--chatui-fg);
11011249
}
1250+
.chatui-compact-menu-backdrop {
1251+
position: absolute;
1252+
top: var(--chatui-compact-header-height);
1253+
left: 0; right: 0; bottom: 0;
1254+
z-index: 98;
1255+
}
1256+
.chatui-compact-menu {
1257+
position: absolute;
1258+
top: 6px;
1259+
right: 8px;
1260+
min-width: 168px;
1261+
padding: 6px;
1262+
border: 1px solid var(--chatui-border);
1263+
border-radius: 8px;
1264+
background: var(--chatui-bg-surface);
1265+
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
1266+
}
1267+
.chatui-compact-menu-item {
1268+
width: 100%;
1269+
height: 32px;
1270+
display: flex;
1271+
align-items: center;
1272+
gap: 8px;
1273+
padding: 0 8px;
1274+
border: none;
1275+
border-radius: 6px;
1276+
background: transparent;
1277+
color: var(--chatui-fg);
1278+
font: inherit;
1279+
font-size: 12px;
1280+
text-align: left;
1281+
cursor: pointer;
1282+
}
1283+
.chatui-compact-menu-item:hover:not(:disabled) {
1284+
background: var(--chatui-bg-hover);
1285+
}
1286+
.chatui-compact-menu-item:disabled {
1287+
opacity: 0.45;
1288+
cursor: not-allowed;
1289+
}
1290+
.chatui-compact-menu-item svg {
1291+
flex-shrink: 0;
1292+
color: var(--chatui-fg-secondary);
1293+
}
1294+
.chatui-compact-menu-item--danger {
1295+
color: var(--chatui-btn-danger);
1296+
}
1297+
.chatui-compact-menu-item--danger svg {
1298+
color: currentColor;
1299+
}
1300+
.chatui-compact-menu-item--danger:hover:not(:disabled) {
1301+
background: color-mix(in srgb, var(--chatui-btn-danger) 14%, transparent);
1302+
}
1303+
.chatui-rename-dialog :deep(.s-modal-body) {
1304+
display: flex;
1305+
flex-direction: column;
1306+
gap: 10px;
1307+
}
1308+
.chatui-rename-hint {
1309+
font-size: 12px;
1310+
color: var(--chatui-fg-secondary);
1311+
}
11021312
11031313
/* Compact popovers */
11041314
.chatui-compact-popover-backdrop {

0 commit comments

Comments
 (0)