Skip to content

Commit d620455

Browse files
committed
app: deduplicate allServers list
1 parent 568eccb commit d620455

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

packages/app/src/components/dialog-select-server.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ export function DialogSelectServer() {
427427
}
428428
>
429429
{(i) => {
430+
const key = ServerConnection.key(i)
430431
return (
431432
<div class="flex items-center gap-3 min-w-0 flex-1 group/item">
432433
<Show
@@ -446,8 +447,8 @@ export function DialogSelectServer() {
446447
>
447448
<ServerRow
448449
conn={i}
449-
status={store.status[ServerConnection.key(i)]}
450-
dimmed={store.status[ServerConnection.key(i)]?.healthy === false}
450+
status={store.status[key]}
451+
dimmed={store.status[key]?.healthy === false}
451452
class="flex items-center gap-3 px-4 min-w-0 flex-1"
452453
badge={
453454
<Show when={defaultUrl() === i.http.url}>
@@ -460,7 +461,7 @@ export function DialogSelectServer() {
460461
</Show>
461462
<Show when={store.editServer.id !== i.http.url}>
462463
<div class="flex items-center justify-center gap-5 pl-4">
463-
<Show when={current() === i}>
464+
<Show when={ServerConnection.key(current()) === key}>
464465
<p class="text-text-weak text-12-regular">{language.t("dialog.server.current")}</p>
465466
</Show>
466467

packages/app/src/context/server.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,19 @@ export const { use: useServer, provider: ServerProvider } = createSimpleContext(
102102
}),
103103
)
104104

105-
const allServers = createMemo(
106-
(): Array<ServerConnection.Any> => [
105+
const allServers = createMemo((): Array<ServerConnection.Any> => {
106+
const servers = [
107107
...(props.servers ?? []),
108108
...store.list.map((value) => ({
109109
type: "http" as const,
110110
http: typeof value === "string" ? { url: value } : value,
111111
})),
112-
],
113-
)
112+
]
113+
114+
const deduped = new Map(servers.map((conn) => [ServerConnection.key(conn), conn]))
115+
116+
return [...deduped.values()]
117+
})
114118

115119
const [state, setState] = createStore({
116120
active: props.defaultServer,

0 commit comments

Comments
 (0)