mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-18 13:49:25 -04:00
fix(desktop): group recent projects by server
This commit is contained in:
@@ -102,32 +102,42 @@ export function WindowsAppMenu(props: {
|
||||
if (entry.type === "separator") return <DropdownMenu.Separator />
|
||||
if (entry.dynamic === "recentProjects") {
|
||||
const servers = global.servers.list()
|
||||
const projects = servers.flatMap((server) =>
|
||||
global
|
||||
.ensureServerCtx(server)
|
||||
.projects.recent()
|
||||
.map((project) => ({ server, project })),
|
||||
)
|
||||
const groups = servers
|
||||
.map((server) => ({
|
||||
server,
|
||||
projects: global.ensureServerCtx(server).projects.recent().slice(0, 5),
|
||||
}))
|
||||
.filter((group) => group.projects.length > 0)
|
||||
return (
|
||||
<DesktopMenuSubmenu label={entry.labelKey ? language.t(entry.labelKey) : ""}>
|
||||
<For each={projects}>
|
||||
{(item) => (
|
||||
<DesktopMenuItem
|
||||
label={
|
||||
servers.length > 1
|
||||
? `${displayName(item.project)} — ${serverName(item.server)}`
|
||||
: displayName(item.project)
|
||||
}
|
||||
disabled={false}
|
||||
onSelect={() =>
|
||||
runCommand(
|
||||
desktopRecentProjectCommand(
|
||||
ServerConnection.key(item.server),
|
||||
item.project.worktree,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
<For each={groups}>
|
||||
{(group, index) => (
|
||||
<>
|
||||
<Show when={index() > 0}>
|
||||
<DropdownMenu.Separator />
|
||||
</Show>
|
||||
<Show when={servers.length > 1}>
|
||||
<DropdownMenu.GroupLabel class="desktop-app-menu-heading">
|
||||
{serverName(group.server)}
|
||||
</DropdownMenu.GroupLabel>
|
||||
</Show>
|
||||
<For each={group.projects}>
|
||||
{(project) => (
|
||||
<DesktopMenuItem
|
||||
label={displayName(project)}
|
||||
disabled={false}
|
||||
onSelect={() =>
|
||||
runCommand(
|
||||
desktopRecentProjectCommand(
|
||||
ServerConnection.key(group.server),
|
||||
project.worktree,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</For>
|
||||
</>
|
||||
)}
|
||||
</For>
|
||||
</DesktopMenuSubmenu>
|
||||
|
||||
@@ -47,10 +47,25 @@ function nativeItem(entry: DesktopMenuEntry, deps: Deps): MenuItemConstructorOpt
|
||||
}
|
||||
|
||||
if (entry.dynamic === "recentProjects") {
|
||||
item.submenu = deps.recentProjects().map((project) => ({
|
||||
label: project.server ? `${project.label} — ${project.server}` : project.label,
|
||||
click: () => deps.trigger(project.command),
|
||||
}))
|
||||
const projects = deps.recentProjects()
|
||||
const servers = new Map<string, DesktopRecentProject[]>()
|
||||
projects.forEach((project) => {
|
||||
if (!project.server) return
|
||||
servers.set(project.server, [...(servers.get(project.server) ?? []), project])
|
||||
})
|
||||
item.submenu = servers.size
|
||||
? [...servers.entries()].flatMap(([server, entries], index) => [
|
||||
...(index > 0 ? ([{ type: "separator" as const }] satisfies MenuItemConstructorOptions[]) : []),
|
||||
{ label: server, enabled: false },
|
||||
...entries.slice(0, 5).map((project) => ({
|
||||
label: project.label,
|
||||
click: () => deps.trigger(project.command),
|
||||
})),
|
||||
])
|
||||
: projects.slice(0, 5).map((project) => ({
|
||||
label: project.label,
|
||||
click: () => deps.trigger(project.command),
|
||||
}))
|
||||
item.enabled = item.submenu.length > 0
|
||||
return item
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user