|
1 | | -import { Show, For, Switch, Match } from "solid-js"; |
| 1 | +import { Show, For, createMemo } from "solid-js"; |
2 | 2 | import { ConfigurationTooltip } from "./configuration-tooltip"; |
3 | 3 | import { Flags } from "./configuration-value/flags"; |
| 4 | +import { TauriConfig } from "~/lib/tauri/config/tauri-conf"; |
4 | 5 |
|
5 | | -type ConfigurationValue = |
6 | | - | ConfigurationRecord |
7 | | - | string |
8 | | - | [] |
9 | | - | boolean |
10 | | - | null |
11 | | - | undefined |
12 | | - | unknown; |
13 | | - |
14 | | -/* eslint-disable-next-line @typescript-eslint/no-empty-interface */ |
15 | | -interface ConfigurationRecord extends Record<string, ConfigurationValue> {} |
| 6 | +type ConfigurationValue = TauriConfig[keyof TauriConfig]; |
16 | 7 |
|
17 | 8 | interface ConfigurationValueProps { |
18 | 9 | parentKey: string; |
19 | 10 | key: string; |
20 | 11 | value: ConfigurationValue; |
21 | 12 | } |
22 | 13 |
|
23 | | -interface TextConfigurationValueProps extends ConfigurationValueProps { |
| 14 | +type TextConfigurationValueProps = Omit<ConfigurationValueProps, "value"> & { |
24 | 15 | value: string | boolean; |
25 | | -} |
| 16 | +}; |
26 | 17 |
|
27 | 18 | interface ArrayConfigurationValueProps extends ConfigurationValueProps { |
28 | | - value: []; |
| 19 | + value: ConfigurationValue[]; |
29 | 20 | } |
30 | 21 |
|
31 | 22 | interface ObjectConfigurationValueProps extends ConfigurationValueProps { |
32 | | - value: ConfigurationRecord; |
| 23 | + value: Omit<ConfigurationValue, "undefined">; |
33 | 24 | } |
34 | 25 |
|
35 | 26 | export function ConfigurationValue(props: ConfigurationValueProps) { |
36 | | - return ( |
37 | | - <Switch |
38 | | - fallback={<TextValue {...(props as TextConfigurationValueProps)} />} |
39 | | - > |
40 | | - <Match |
41 | | - when={ |
42 | | - typeof props.value === "string" || typeof props.value === "boolean" |
43 | | - } |
44 | | - > |
45 | | - <TextValue {...(props as TextConfigurationValueProps)} /> |
46 | | - </Match> |
47 | | - <Match when={Array.isArray(props.value)}> |
48 | | - <ArrayValue {...(props as ArrayConfigurationValueProps)} /> |
49 | | - </Match> |
50 | | - <Match when={typeof props.value === "object" && props.value !== null}> |
51 | | - <ObjectValue {...(props as ObjectConfigurationValueProps)} /> |
52 | | - </Match> |
53 | | - </Switch> |
54 | | - ); |
| 27 | + const selectedTemplate = createMemo(() => { |
| 28 | + if (typeof props.value === "string" || typeof props.value === "boolean") |
| 29 | + return <TextValue {...props} value={props.value} />; |
| 30 | + |
| 31 | + if (Array.isArray(props.value)) |
| 32 | + return <ArrayValue {...props} value={props.value} />; |
| 33 | + |
| 34 | + if (typeof props.value === "object" && props.value) |
| 35 | + return <ObjectValue {...props} value={props.value} />; |
| 36 | + |
| 37 | + return <TextValue {...props} value={String(props.value)} />; |
| 38 | + }); |
| 39 | + |
| 40 | + return <>{selectedTemplate()}</>; |
55 | 41 | } |
56 | 42 |
|
57 | 43 | function TextValue(props: TextConfigurationValueProps) { |
@@ -84,7 +70,7 @@ function ObjectValue(props: ObjectConfigurationValueProps) { |
84 | 70 | <ConfigurationTooltip parentKey={props.parentKey} key={props.key} /> |
85 | 71 | </h2> |
86 | 72 | <ul class="flex flex-col"> |
87 | | - <For each={Object.entries(props.value)}> |
| 73 | + <For each={Object.entries<ConfigurationValue>(props.value)}> |
88 | 74 | {([childKey, value]) => ( |
89 | 75 | <li> |
90 | 76 | <ConfigurationValue |
|
0 commit comments