Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions apps/desktop/src/lib/trpc/routers/workspaces/procedures/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const createStatusProcedures = () => {
patch: z.object({
name: z.string().optional(),
preserveUnnamedStatus: z.boolean().optional(),
isUnnamed: z.boolean().optional(),
}),
}),
)
Expand All @@ -75,12 +76,18 @@ export const createStatusProcedures = () => {
);
}

const resolveIsUnnamed = () => {
if (input.patch.isUnnamed !== undefined) return input.patch.isUnnamed;
if (input.patch.name !== undefined && !input.patch.preserveUnnamedStatus)
return false;
return undefined;
};

const isUnnamed = resolveIsUnnamed();

touchWorkspace(input.id, {
...(input.patch.name !== undefined && {
name: input.patch.name,
// Only mark as named if not preserving unnamed status
...(input.patch.preserveUnnamedStatus ? {} : { isUnnamed: false }),
}),
...(input.patch.name !== undefined && { name: input.patch.name }),
...(isUnnamed !== undefined && { isUnnamed }),
});

return { success: true };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ function WorkspaceSettingsPage() {
id: workspaceId,
});

const rename = useWorkspaceRename(workspace?.id ?? "", workspace?.name ?? "");
const rename = useWorkspaceRename(
workspace?.id ?? "",
workspace?.name ?? "",
workspace?.branch ?? "",
);

// Workspace is guaranteed to exist here because loader handles 404s
if (!workspace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function WorkspaceListItem({
const matchRoute = useMatchRoute();
const reorderWorkspaces = useReorderWorkspaces();
const [hasHovered, setHasHovered] = useState(false);
const rename = useWorkspaceRename(id, name);
const rename = useWorkspaceRename(id, name, branch);
const tabs = useTabsStore((s) => s.tabs);
const panes = useTabsStore((s) => s.panes);
const clearWorkspaceAttentionStatus = useTabsStore(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { useEffect, useRef, useState } from "react";
import { useUpdateWorkspace } from "renderer/react-query/workspaces/useUpdateWorkspace";

export function useWorkspaceRename(workspaceId: string, workspaceName: string) {
export function useWorkspaceRename(
workspaceId: string,
workspaceName: string,
branch: string,
) {
const [isRenaming, setIsRenaming] = useState(false);
const [renameValue, setRenameValue] = useState(workspaceName);
const inputRef = useRef<HTMLInputElement | null>(null);
const updateWorkspace = useUpdateWorkspace();

// Select input text when rename mode is activated
useEffect(() => {
if (isRenaming && inputRef.current) {
inputRef.current.select();
}
}, [isRenaming]);

// Sync rename value when workspace name changes
useEffect(() => {
setRenameValue(workspaceName);
}, [workspaceName]);
Expand All @@ -25,7 +27,15 @@ export function useWorkspaceRename(workspaceId: string, workspaceName: string) {

const submitRename = () => {
const trimmedValue = renameValue.trim();
if (trimmedValue && trimmedValue !== workspaceName) {
const isCleared = !trimmedValue;

if (isCleared) {
updateWorkspace.mutate({
id: workspaceId,
patch: { name: branch, isUnnamed: true },
});
setRenameValue(branch);
} else if (trimmedValue !== workspaceName) {
updateWorkspace.mutate({
id: workspaceId,
patch: { name: trimmedValue },
Expand Down
Loading