|
1 | 1 | import { Component } from "solid-js" |
2 | 2 | import { useLocal } from "@/context/local" |
3 | | -import { useDialog } from "@/context/dialog" |
4 | 3 | import { popularProviders } from "@/hooks/use-providers" |
5 | 4 | import { Dialog } from "@opencode-ai/ui/dialog" |
6 | 5 | import { List } from "@opencode-ai/ui/list" |
7 | 6 | import { Switch } from "@opencode-ai/ui/switch" |
8 | 7 |
|
9 | 8 | export const DialogManageModels: Component = () => { |
10 | 9 | const local = useLocal() |
11 | | - const dialog = useDialog() |
12 | | - |
13 | 10 | return ( |
14 | | - <Dialog |
15 | | - modal |
16 | | - defaultOpen |
17 | | - onOpenChange={(open) => { |
18 | | - if (!open) { |
19 | | - dialog.clear() |
20 | | - } |
21 | | - }} |
22 | | - > |
23 | | - <Dialog.Header> |
24 | | - <Dialog.Title>Manage models</Dialog.Title> |
25 | | - <Dialog.CloseButton tabIndex={-1} /> |
26 | | - </Dialog.Header> |
27 | | - <Dialog.Description>Customize which models appear in the model selector.</Dialog.Description> |
28 | | - <Dialog.Body> |
29 | | - <List |
30 | | - class="px-2.5" |
31 | | - search={{ placeholder: "Search models", autofocus: true }} |
32 | | - emptyMessage="No model results" |
33 | | - key={(x) => `${x?.provider?.id}:${x?.id}`} |
34 | | - items={local.model.list()} |
35 | | - filterKeys={["provider.name", "name", "id"]} |
36 | | - sortBy={(a, b) => a.name.localeCompare(b.name)} |
37 | | - groupBy={(x) => x.provider.name} |
38 | | - sortGroupsBy={(a, b) => { |
39 | | - const aProvider = a.items[0].provider.id |
40 | | - const bProvider = b.items[0].provider.id |
41 | | - if (popularProviders.includes(aProvider) && !popularProviders.includes(bProvider)) return -1 |
42 | | - if (!popularProviders.includes(aProvider) && popularProviders.includes(bProvider)) return 1 |
43 | | - return popularProviders.indexOf(aProvider) - popularProviders.indexOf(bProvider) |
44 | | - }} |
45 | | - onSelect={(x) => { |
46 | | - if (!x) return |
47 | | - local.model.setVisibility({ modelID: x.id, providerID: x.provider.id }, !x.visible) |
48 | | - }} |
49 | | - > |
50 | | - {(i) => ( |
51 | | - <div class="w-full flex items-center justify-between gap-x-2.5"> |
52 | | - <span>{i.name}</span> |
53 | | - <Switch |
54 | | - checked={!!i.visible} |
55 | | - onChange={(checked) => { |
56 | | - local.model.setVisibility({ modelID: i.id, providerID: i.provider.id }, checked) |
57 | | - }} |
58 | | - /> |
59 | | - </div> |
60 | | - )} |
61 | | - </List> |
62 | | - </Dialog.Body> |
| 11 | + <Dialog title="Manage models" description="Customize which models appear in the model selector."> |
| 12 | + <List |
| 13 | + class="px-2.5" |
| 14 | + search={{ placeholder: "Search models", autofocus: true }} |
| 15 | + emptyMessage="No model results" |
| 16 | + key={(x) => `${x?.provider?.id}:${x?.id}`} |
| 17 | + items={local.model.list()} |
| 18 | + filterKeys={["provider.name", "name", "id"]} |
| 19 | + sortBy={(a, b) => a.name.localeCompare(b.name)} |
| 20 | + groupBy={(x) => x.provider.name} |
| 21 | + sortGroupsBy={(a, b) => { |
| 22 | + const aProvider = a.items[0].provider.id |
| 23 | + const bProvider = b.items[0].provider.id |
| 24 | + if (popularProviders.includes(aProvider) && !popularProviders.includes(bProvider)) return -1 |
| 25 | + if (!popularProviders.includes(aProvider) && popularProviders.includes(bProvider)) return 1 |
| 26 | + return popularProviders.indexOf(aProvider) - popularProviders.indexOf(bProvider) |
| 27 | + }} |
| 28 | + onSelect={(x) => { |
| 29 | + if (!x) return |
| 30 | + local.model.setVisibility({ modelID: x.id, providerID: x.provider.id }, !x.visible) |
| 31 | + }} |
| 32 | + > |
| 33 | + {(i) => ( |
| 34 | + <div class="w-full flex items-center justify-between gap-x-2.5"> |
| 35 | + <span>{i.name}</span> |
| 36 | + <Switch |
| 37 | + checked={!!i.visible} |
| 38 | + onChange={(checked) => { |
| 39 | + local.model.setVisibility({ modelID: i.id, providerID: i.provider.id }, checked) |
| 40 | + }} |
| 41 | + /> |
| 42 | + </div> |
| 43 | + )} |
| 44 | + </List> |
63 | 45 | </Dialog> |
64 | 46 | ) |
65 | 47 | } |
0 commit comments