π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[ensu] add rename in chatsidebar for desktop
aaqilb9b15f4b7790
diff --git a/web/apps/ensu/src/components/chat/ChatDialogs.tsx b/web/apps/ensu/src/components/chat/ChatDialogs.tsxindex 5fc4e3d85a..d8a472021a 100644--- a/web/apps/ensu/src/components/chat/ChatDialogs.tsx+++ b/web/apps/ensu/src/components/chat/ChatDialogs.tsx@@ -75,6 +75,11 @@ export interface ChatDialogsProps {openModelSettings: () => void;openSystemPromptSettings: () => void;isSmall: boolean;+ renameSessionId: string | null;+ renameSessionTitle: string;+ setRenameSessionTitle: (title: string) => void;+ handleCancelRenameSession: () => void;+ handleConfirmRenameSession: () => void | Promise<void>;deleteSessionId: string | null;deleteSessionLabel: string;handleCancelDeleteSession: () => void;@@ -122,6 +127,11 @@ export const ChatDialogs = memo(openModelSettings,openSystemPromptSettings,isSmall,+ renameSessionId,+ renameSessionTitle,+ setRenameSessionTitle,+ handleCancelRenameSession,+ handleConfirmRenameSession,deleteSessionId,deleteSessionLabel,handleCancelDeleteSession,@@ -627,6 +637,53 @@ export const ChatDialogs = memo(</DialogActions></Dialog>+ <Dialog+ open={Boolean(renameSessionId)}+ onClose={handleCancelRenameSession}+ fullScreen={isSmall}+ maxWidth="xs"+ fullWidth+ slotProps={{ paper: { sx: dialogPaperSx } }}+ >+ <DialogTitle sx={dialogTitleSx}>Rename chat</DialogTitle>+ <DialogContent>+ <TextField+ value={renameSessionTitle}+ onChange={(event) =>+ setRenameSessionTitle(event.target.value)+ }+ autoFocus+ fullWidth+ label="Chat name"+ slotProps={{ htmlInput: { maxLength: 40 } }}+ onKeyDown={(event) => {+ if (+ event.key === "Enter" &&+ !event.nativeEvent.isComposing+ ) {+ void handleConfirmRenameSession();+ }+ }}+ />+ </DialogContent>+ <DialogActions sx={{ px: 3, pb: 3 }}>+ <Button+ onClick={handleCancelRenameSession}+ color="secondary"+ >+ Cancel+ </Button>+ <Button+ variant="contained"+ color="accent"+ disabled={!renameSessionTitle.trim()}+ onClick={() => void handleConfirmRenameSession()}+ >+ Rename+ </Button>+ </DialogActions>+ </Dialog>+<Dialogopen={Boolean(deleteSessionId)}onClose={handleCancelDeleteSession}diff --git a/web/apps/ensu/src/components/chat/ChatSidebar.tsx b/web/apps/ensu/src/components/chat/ChatSidebar.tsxindex 26e5bce9fc..2e0360037d 100644--- a/web/apps/ensu/src/components/chat/ChatSidebar.tsx+++ b/web/apps/ensu/src/components/chat/ChatSidebar.tsx@@ -4,6 +4,7 @@ import {ArrowRight01Icon,Cancel01Icon,Delete01Icon,+ Edit01Icon,PlusSignIcon,Search01Icon,} from "@hugeicons/core-free-icons";@@ -42,6 +43,7 @@ export interface ChatSidebarProps {groupedSessions: Array<[string, ChatSession[]]>;currentSessionId?: string;handleSelectSession: (sessionId: string) => void;+ requestRenameSession: (session: ChatSession) => void;requestDeleteSession: (sessionId: string) => void;openSettingsModal: () => void;}@@ -65,6 +67,7 @@ export const ChatSidebar = memo(groupedSessions,currentSessionId,handleSelectSession,+ requestRenameSession,requestDeleteSession,openSettingsModal,}: ChatSidebarProps) => (@@ -346,6 +349,19 @@ export const ChatSidebar = memo("Nothing here"}</Typography></Box>+ <IconButton+ aria-label="Rename chat"+ sx={actionButtonSx}+ onClick={(event) => {+ event.stopPropagation();+ requestRenameSession(session);+ }}+ >+ <HugeiconsIcon+ icon={Edit01Icon}+ {...actionIconProps}+ />+ </IconButton><IconButtonaria-label="Delete chat"sx={actionButtonSx}diff --git a/web/apps/ensu/src/pages/chat.tsx b/web/apps/ensu/src/pages/chat.tsxindex 9f8700e749..438b4b3cb0 100644--- a/web/apps/ensu/src/pages/chat.tsx+++ b/web/apps/ensu/src/pages/chat.tsx@@ -650,6 +650,8 @@ const Page: React.FC = () => {>("checking");const [modelGateError, setModelGateError] = useState<string | null>(null);const [isTauriRuntime, setIsTauriRuntime] = useState(false);+ const [renameSessionId, setRenameSessionId] = useState<string | null>(null);+ const [renameSessionTitle, setRenameSessionTitle] = useState("");const [deleteSessionId, setDeleteSessionId] = useState<string | null>(null);const allowMmproj = isTauriRuntime;@@ -664,6 +666,9 @@ const Page: React.FC = () => {previousSelection?: string | null;} | null>(null);const sessionSummaryInFlightRef = useRef(false);+ const manuallyRenamedSessionIdsRef = useRef(new Set<string>());+ const pendingSessionRenamesRef = useRef(new Set<string>());+ const sessionTitleUpdatesRef = useRef(new Map<string, Promise<void>>());const inputRef = useRef<HTMLTextAreaElement | null>(null);const attachmentPreviewUrlsRef = useRef<Record<string, string>>({});const pendingPreviewUrlsRef = useRef<Record<string, string>>({});@@ -1853,6 +1858,30 @@ const Page: React.FC = () => {[],);+ const persistSessionTitle = useCallback(+ (sessionUuid: string, title: string, key: string) => {+ const previous = sessionTitleUpdatesRef.current.get(sessionUuid);+ const task = (previous?.catch(() => {}) ?? Promise.resolve()).then(+ async () => {+ await updateSessionTitle(sessionUuid, title, key);+ updateSessionTitleInState(sessionUuid, title);+ },+ );+ sessionTitleUpdatesRef.current.set(sessionUuid, task);+ void task+ .finally(() => {+ if (+ sessionTitleUpdatesRef.current.get(sessionUuid) === task+ ) {+ sessionTitleUpdatesRef.current.delete(sessionUuid);+ }+ })+ .catch(() => {});+ return task;+ },+ [updateSessionTitleInState],+ );+const maybeGenerateSessionTitle = useCallback(async ({sessionUuid,@@ -1899,20 +1928,17 @@ const Page: React.FC = () => {? sessionTitleFromText(summarySeed, fallbackTitle): fallbackTitle;- await updateSessionTitle(sessionUuid, title, chatKey);- updateSessionTitleInState(sessionUuid, title);+ if (manuallyRenamedSessionIdsRef.current.has(sessionUuid)) {+ return;+ }+ await persistSessionTitle(sessionUuid, title, chatKey);} catch (error) {log.error("Failed to generate session title", error);} finally {sessionSummaryInFlightRef.current = false;}},- [- chatKey,- generateSessionSummary,- trimToWords,- updateSessionTitleInState,- ],+ [chatKey, generateSessionSummary, persistSessionTitle, trimToWords],);const preloadModelIfAvailable = useCallback(async () => {@@ -2236,6 +2262,7 @@ const Page: React.FC = () => {const removeSessionFromState = useCallback((sessionId: string) => {+ manuallyRenamedSessionIdsRef.current.delete(sessionId);setSessions((prev) =>prev.filter((session) => session.sessionUuid !== sessionId),);@@ -2289,6 +2316,45 @@ const Page: React.FC = () => {setDeleteSessionId(sessionId);}, []);+ const requestRenameSession = useCallback((session: ChatSession) => {+ if (pendingSessionRenamesRef.current.has(session.sessionUuid)) return;+ setRenameSessionId(session.sessionUuid);+ setRenameSessionTitle(session.title?.trim() || "New chat");+ }, []);++ const handleCancelRenameSession = useCallback(() => {+ setRenameSessionId(null);+ setRenameSessionTitle("");+ }, []);++ const handleConfirmRenameSession = useCallback(async () => {+ if (!chatKey || !renameSessionId || !renameSessionTitle.trim()) return;+ if (pendingSessionRenamesRef.current.has(renameSessionId)) return;+ pendingSessionRenamesRef.current.add(renameSessionId);+ const title = sessionTitleFromText(renameSessionTitle);+ const wasManuallyRenamed =+ manuallyRenamedSessionIdsRef.current.has(renameSessionId);+ manuallyRenamedSessionIdsRef.current.add(renameSessionId);+ handleCancelRenameSession();+ try {+ await persistSessionTitle(renameSessionId, title, chatKey);+ } catch (error) {+ if (!wasManuallyRenamed) {+ manuallyRenamedSessionIdsRef.current.delete(renameSessionId);+ }+ onGenericError(error);+ } finally {+ pendingSessionRenamesRef.current.delete(renameSessionId);+ }+ }, [+ chatKey,+ handleCancelRenameSession,+ onGenericError,+ persistSessionTitle,+ renameSessionId,+ renameSessionTitle,+ ]);+const handleConfirmDeleteSession = useCallback(async () => {if (!deleteSessionId) return;try {@@ -3890,6 +3956,7 @@ const Page: React.FC = () => {groupedSessions={groupedSessions}currentSessionId={currentSessionId}handleSelectSession={handleSelectSession}+ requestRenameSession={requestRenameSession}requestDeleteSession={requestDeleteSession}openSettingsModal={openSettingsModal}/>@@ -4171,6 +4238,11 @@ const Page: React.FC = () => {openModelSettings={openModelSettings}openSystemPromptSettings={openSystemPromptSettings}isSmall={isSmall}+ renameSessionId={renameSessionId}+ renameSessionTitle={renameSessionTitle}+ setRenameSessionTitle={setRenameSessionTitle}+ handleCancelRenameSession={handleCancelRenameSession}+ handleConfirmRenameSession={handleConfirmRenameSession}deleteSessionId={deleteSessionId}deleteSessionLabel={deleteSessionLabel}handleCancelDeleteSession={handleCancelDeleteSession}