refactor(desktop): tidy session-color pass (#67671)

- sessionColorFor: drop the no-op `?? undefined` (the map read is already
  string | undefined).
- sessionProjectColor: fix a now-stale doc line — a rootless (no cwd AND no
  git_repo_root) row returns null, not any cwd-less row (repo-root-only rows
  resolve since the grouped-but-grey fix).
- ProjectMenu.applyAppearance: await instead of a .then block; flatten the
  auto-branch's nested ternary.
This commit is contained in:
brooklyn! 2026-07-19 16:37:53 -04:00 committed by GitHub
parent 3345b3cdfd
commit 1b17015f7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 13 deletions

View file

@ -112,13 +112,11 @@ export function ProjectMenu({
// Appearance writes route through the adopt-aware helper: an auto project is
// materialized on its first change (its id then changes), so close the picker
// when that happens to avoid a second write double-creating from a stale node.
const applyAppearance = (patch: { color?: null | string; icon?: null | string }) => {
void setProjectAppearance(project, patch).then(adopted => {
if (adopted) {
setAppearanceOpen(false)
}
})
// on adopt to stop a second write double-creating from a now-stale node.
const applyAppearance = async (patch: { color?: null | string; icon?: null | string }) => {
if (await setProjectAppearance(project, patch)) {
setAppearanceOpen(false)
}
}
// Set color / pick an icon — shown for explicit projects and for auto ones
@ -168,12 +166,12 @@ export function ProjectMenu({
// Inherited (auto) repos can still be themed — the change adopts the
// repo as a real project. Rename / add-folder / set-active stay out
// until then (they need the materialized record).
project.path ? (
project.path && (
<>
{appearanceItem}
<DropdownMenuSeparator />
</>
) : null
)
) : (
<>
<DropdownMenuItem onSelect={() => openProjectRename(target)}>
@ -224,7 +222,7 @@ export function ProjectMenu({
<ColorSwatches
clearIcon="circle-slash"
clearLabel={p.noColor}
onChange={color => applyAppearance({ color })}
onChange={color => void applyAppearance({ color })}
swatches={PROFILE_SWATCHES}
value={project.color ?? null}
/>
@ -239,7 +237,7 @@ export function ProjectMenu({
project.icon === name && 'bg-(--ui-control-active-background) text-foreground'
)}
key={name}
onClick={() => applyAppearance({ icon: project.icon === name ? null : name })}
onClick={() => void applyAppearance({ icon: project.icon === name ? null : name })}
style={project.icon === name && project.color ? { color: project.color } : undefined}
type="button"
>

View file

@ -409,7 +409,7 @@ export function liveSessionProjectId(session: SessionInfo, explicitProjects: Pro
* unless the user set one, so a session only tints when it belongs to a colored
* project (inheritance is opt-in by coloring the project). Reuses
* {@link liveSessionProjectId} so the color follows the SAME membership the
* sidebar groups by; returns null for cwd-less / kanban / out-of-tree rows and
* sidebar groups by; returns null for rootless / kanban / out-of-tree rows and
* for sessions under an uncolored (or auto) project.
*/
export function sessionProjectColor(session: SessionInfo, projects: ProjectInfo[]): null | string {

View file

@ -32,5 +32,5 @@ export const $sessionColorById = computed([$sessions, $projects], (sessions, pro
// The color for a single session object (the tabs already hold the SessionInfo
// they render, so they resolve through the same map the sidebar reads).
export function sessionColorFor(session: null | SessionInfo | undefined): string | undefined {
return session ? ($sessionColorById.get()[session.id] ?? undefined) : undefined
return session ? $sessionColorById.get()[session.id] : undefined
}