mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-06-04 20:05:38 +08:00
refactor: move rename and delete sessions to modules
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import type React from 'react';
|
||||
import type { TFunction } from 'i18next';
|
||||
|
||||
import { api } from '../../../utils/api';
|
||||
import type { Project, ProjectSession, LLMProvider } from '../../../types/app';
|
||||
import type {
|
||||
@@ -340,21 +340,6 @@ export function useSidebarController({
|
||||
};
|
||||
}, [searchFilter, searchMode]);
|
||||
|
||||
const handleTouchClick = useCallback(
|
||||
(callback: () => void) =>
|
||||
(event: React.TouchEvent<HTMLElement>) => {
|
||||
const target = event.target as HTMLElement;
|
||||
if (target.closest('.overflow-y-auto') || target.closest('[data-scroll-container]')) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
callback();
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
// All sidebar state keys (expanded, starred, loading, etc.) use the DB
|
||||
// `projectId` as their identifier after the migration.
|
||||
const toggleProject = useCallback((projectId: string) => {
|
||||
@@ -522,8 +507,8 @@ export function useSidebarController({
|
||||
);
|
||||
|
||||
const showDeleteSessionConfirmation = useCallback(
|
||||
// `projectId` (not the legacy folder-encoded name) is what the DELETE
|
||||
// /api/projects/:projectId/sessions/:sessionId endpoint expects.
|
||||
// Kept with project/provider arguments for component wiring compatibility;
|
||||
// deletion now uses only `sessionId` via /api/providers/sessions/:sessionId.
|
||||
(
|
||||
projectId: string,
|
||||
sessionId: string,
|
||||
@@ -540,19 +525,11 @@ export function useSidebarController({
|
||||
return;
|
||||
}
|
||||
|
||||
const { projectId, sessionId, provider } = sessionDeleteConfirmation;
|
||||
const { sessionId } = sessionDeleteConfirmation;
|
||||
setSessionDeleteConfirmation(null);
|
||||
|
||||
try {
|
||||
let response;
|
||||
if (provider === 'codex') {
|
||||
response = await api.deleteCodexSession(sessionId);
|
||||
} else if (provider === 'gemini') {
|
||||
response = await api.deleteGeminiSession(sessionId);
|
||||
} else {
|
||||
// Claude sessions are owned by the DB project row; pass projectId.
|
||||
response = await api.deleteSession(projectId, sessionId);
|
||||
}
|
||||
const response = await api.deleteSession(sessionId);
|
||||
|
||||
if (response.ok) {
|
||||
onSessionDelete?.(sessionId);
|
||||
@@ -634,9 +611,9 @@ export function useSidebarController({
|
||||
}, [onRefresh]);
|
||||
|
||||
const updateSessionSummary = useCallback(
|
||||
// `_projectId` is unused by the rename endpoint but preserved in the
|
||||
// callback signature so existing wiring from sidebar components works.
|
||||
async (_projectId: string, sessionId: string, summary: string, provider: LLMProvider) => {
|
||||
// `_projectId` and `_provider` are preserved for compatibility with
|
||||
// existing sidebar callback signatures; backend rename only needs sessionId.
|
||||
async (_projectId: string, sessionId: string, summary: string, _provider: LLMProvider) => {
|
||||
const trimmed = summary.trim();
|
||||
if (!trimmed) {
|
||||
setEditingSession(null);
|
||||
@@ -644,7 +621,7 @@ export function useSidebarController({
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const response = await api.renameSession(sessionId, trimmed, provider);
|
||||
const response = await api.renameSession(sessionId, trimmed);
|
||||
if (response.ok) {
|
||||
await onRefresh();
|
||||
} else {
|
||||
|
||||
@@ -11,8 +11,8 @@ export type DeleteProjectConfirmation = {
|
||||
sessionCount: number;
|
||||
};
|
||||
|
||||
// Delete confirmation payload; `projectId` is the DB primary key used by the
|
||||
// DELETE /api/projects/:projectId/sessions/:sessionId endpoint.
|
||||
// Delete confirmation payload used by sidebar UX. `projectId`/`provider` are
|
||||
// kept for wiring compatibility, while API deletion now keys only by sessionId.
|
||||
export type SessionDeleteConfirmation = {
|
||||
projectId: string;
|
||||
sessionId: string;
|
||||
|
||||
@@ -187,7 +187,7 @@ i18n
|
||||
fallbackLng: 'en',
|
||||
|
||||
// Enable debug mode in development (logs missing keys to console)
|
||||
debug: import.meta.env.DEV,
|
||||
debug: false,
|
||||
|
||||
// Namespaces - load only what's needed
|
||||
ns: ['common', 'settings', 'auth', 'sidebar', 'chat', 'codeEditor', 'tasks'],
|
||||
|
||||
@@ -76,22 +76,14 @@ export const api = {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ displayName }),
|
||||
}),
|
||||
deleteSession: (projectId, sessionId) =>
|
||||
authenticatedFetch(`/api/projects/${projectId}/sessions/${sessionId}`, {
|
||||
deleteSession: (sessionId) =>
|
||||
authenticatedFetch(`/api/providers/sessions/${sessionId}`, {
|
||||
method: 'DELETE',
|
||||
}),
|
||||
renameSession: (sessionId, summary, provider) =>
|
||||
authenticatedFetch(`/api/sessions/${sessionId}/rename`, {
|
||||
renameSession: (sessionId, summary) =>
|
||||
authenticatedFetch(`/api/providers/sessions/${sessionId}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ summary, provider }),
|
||||
}),
|
||||
deleteCodexSession: (sessionId) =>
|
||||
authenticatedFetch(`/api/codex/sessions/${sessionId}`, {
|
||||
method: 'DELETE',
|
||||
}),
|
||||
deleteGeminiSession: (sessionId) =>
|
||||
authenticatedFetch(`/api/gemini/sessions/${sessionId}`, {
|
||||
method: 'DELETE',
|
||||
body: JSON.stringify({ summary }),
|
||||
}),
|
||||
// `hardDelete` => server `?force=true` (remove DB row + Claude *.jsonl + sessions rows for path).
|
||||
deleteProject: (projectId, hardDelete = false) => {
|
||||
|
||||
Reference in New Issue
Block a user