feat: tab names

This commit is contained in:
Alejandro Gómez
2025-12-19 12:49:29 +01:00
parent 812b719ea0
commit 8f80742ef1
5 changed files with 137 additions and 18 deletions

View File

@@ -399,3 +399,37 @@ export const applyPresetLayout = (
return state;
}
};
/**
* Updates the label of an existing workspace.
* Labels are user-friendly names that appear alongside workspace numbers.
*/
export const updateWorkspaceLabel = (
state: GrimoireState,
workspaceId: string,
label: string | undefined,
): GrimoireState => {
const workspace = state.workspaces[workspaceId];
if (!workspace) {
return state; // Workspace doesn't exist, return unchanged
}
// Normalize label: trim and treat empty strings as undefined
const normalizedLabel = label?.trim() || undefined;
// If label hasn't changed, return state unchanged (optimization)
if (workspace.label === normalizedLabel) {
return state;
}
return {
...state,
workspaces: {
...state.workspaces,
[workspaceId]: {
...workspace,
label: normalizedLabel,
},
},
};
};

View File

@@ -272,6 +272,12 @@ export const useGrimoire = () => {
[setState],
);
const updateWorkspaceLabel = useCallback(
(workspaceId: string, label: string | undefined) =>
setState((prev) => Logic.updateWorkspaceLabel(prev, workspaceId, label)),
[setState],
);
return {
state,
locale: state.locale || browserLocale,
@@ -288,5 +294,6 @@ export const useGrimoire = () => {
setActiveAccountRelays,
updateLayoutConfig,
applyPresetLayout,
updateWorkspaceLabel,
};
};