Skip to content

Commit 46452dd

Browse files
Fix: Single quote on Attribute
1 parent 62e557c commit 46452dd

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

static/js/search.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ export function showSearchPage() {
2727
</div>
2828
<div id="search-results"></div>
2929
</div>`;
30+
document.getElementById('search-results').addEventListener('click', (e) => {
31+
const result = e.target.closest('.search-result[data-project]');
32+
if (!result) return;
33+
const project = result.getAttribute('data-project');
34+
const sessionId = result.getAttribute('data-session-id');
35+
window.location.hash = `#project/${encodeURIComponent(project)}/${encodeURIComponent(sessionId)}`;
36+
});
3037
document.getElementById('search-input').focus();
3138
}
3239

@@ -56,7 +63,7 @@ export async function doSearch() {
5663
html += '<div class="search-results">';
5764

5865
for (const r of results) {
59-
html += `<div class="search-result" onclick="window.location.hash='#project/${encodeURIComponent(r.project)}/${encodeURIComponent(r.session_id)}'">
66+
html += `<div class="search-result" data-project="${esc(r.project)}" data-session-id="${esc(r.session_id)}">
6067
<div><strong>${esc(r.title)}</strong> <span class="text-muted text-sm">${esc(r.project)} &bull; ${esc(r.role)}</span></div>
6168
<div class="snippet">...${esc(r.snippet)}...</div>
6269
</div>`;

static/js/sessions.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { state } from './shared/state.js';
44
import { esc, truncate, formatDate, formatTs, smoothSet, loadingBar, showToast, closeSidebar, setHamburgerVisible } from './shared/utils.js';
55
import { renderMarkdown, cleanContent } from './shared/markdown.js';
66
import { setWorkspaceMode } from './shared/theme.js';
7+
import { downloadSession } from './export.js';
78

89
// ==================== Workspace (split layout) ====================
910

@@ -54,7 +55,7 @@ export async function showWorkspace(projectName, selectedSessionId) {
5455
const errorClass = s.error ? ' sidebar-item-error' : '';
5556
const errorDetail = s.error_detail ? `<div class="error-detail">${esc(s.error_detail)}</div>` : '';
5657
const modelBadge = models ? `<span style="font-size:0.65rem;opacity:0.6;display:block;margin-top:1px">${esc(models)}</span>` : '';
57-
sidebar += `<button class="sidebar-item${isActive}${errorClass}" onclick="selectSession(${JSON.stringify(projectName)},${JSON.stringify(s.id)})" id="sidebar-${esc(s.id)}">
58+
sidebar += `<button type="button" class="sidebar-item${isActive}${errorClass}" data-project="${esc(projectName)}" data-session-id="${esc(s.id)}" id="sidebar-${esc(s.id)}">
5859
<div class="sidebar-item-title">${esc(title)}</div>
5960
${errorDetail}
6061
<div class="sidebar-item-time">${esc(ts)}${modelBadge}</div>
@@ -81,6 +82,7 @@ export async function showWorkspace(projectName, selectedSessionId) {
8182
</div>
8283
</div>`;
8384
smoothSet(content, html);
85+
bindSidebarSessionClicks();
8486
loadingBar.done();
8587

8688
if (selectedSessionId) {
@@ -94,6 +96,30 @@ export async function showWorkspace(projectName, selectedSessionId) {
9496
}
9597
}
9698

99+
function bindSidebarSessionClicks() {
100+
const sidebar = document.getElementById('sidebar');
101+
if (!sidebar) return;
102+
sidebar.addEventListener('click', (e) => {
103+
const btn = e.target.closest('button.sidebar-item[data-session-id]');
104+
if (!btn) return;
105+
const project = btn.getAttribute('data-project');
106+
const sessionId = btn.getAttribute('data-session-id');
107+
if (project == null || sessionId == null) return;
108+
selectSession(project, sessionId);
109+
});
110+
}
111+
112+
function bindWorkspaceDownloadClick(wsActions) {
113+
const btn = wsActions.querySelector('[data-download-session]');
114+
if (!btn) return;
115+
btn.addEventListener('click', () => {
116+
const project = btn.getAttribute('data-download-project');
117+
const sessionId = btn.getAttribute('data-download-session');
118+
if (project == null || sessionId == null) return;
119+
downloadSession(project, sessionId);
120+
});
121+
}
122+
97123
export function selectSession(projectName, sessionId) {
98124
closeSidebar();
99125
window.location.hash = `#project/${encodeURIComponent(projectName)}/${encodeURIComponent(sessionId)}`;
@@ -151,11 +177,12 @@ export async function loadSession(projectName, sessionId) {
151177
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
152178
Copy All
153179
</button>
154-
<button class="btn btn-outline btn-sm" onclick="downloadSession(${JSON.stringify(projectName)},${JSON.stringify(sessionId)})">
180+
<button type="button" class="btn btn-outline btn-sm" data-download-project="${esc(projectName)}" data-download-session="${esc(sessionId)}">
155181
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
156182
Download
157183
</button>
158184
</div>`;
185+
bindWorkspaceDownloadClick(wsActions);
159186
}
160187

161188
html += `<div class="card">

0 commit comments

Comments
 (0)