mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-06-05 18:21:28 +02:00
feat: tab names
This commit is contained in:
@@ -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,
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user