Skip to content

Commit 0ac8f76

Browse files
authored
re query settings on component load and ui change (#440)
* re query settings on component load and ui change * 1.2.9
1 parent 0a0efd7 commit 0ac8f76

File tree

4 files changed

+52
-42
lines changed

4 files changed

+52
-42
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@types/mozilla-readability": "^0.2.0",
2424
"@types/turndown": "^5.0.1"
2525
},
26-
"version": "1.2.8",
26+
"version": "1.2.9",
2727
"samepage": {
2828
"extends": "node_modules/roamjs-components/package.json"
2929
}

src/components/SettingsTable.tsx

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import { OnloadArgs } from "roamjs-components/types";
1010
import { Feature } from "../index";
1111

1212
const SettingsTable =
13-
(
14-
FEATURES: Feature[],
15-
initialSettings: { [key: string]: boolean },
16-
extensionAPI: OnloadArgs["extensionAPI"]
17-
) =>
18-
() => {
13+
(FEATURES: Feature[], extensionAPI: OnloadArgs["extensionAPI"]) => () => {
14+
const initialSettings: { [key: string]: boolean } = {};
15+
FEATURES.forEach(({ id }) => {
16+
const flag = extensionAPI.settings.get(id);
17+
initialSettings[id] = !!flag;
18+
});
1919
const [featureToggleSettings, setFeatureToggleSettings] =
2020
useState(initialSettings);
2121

@@ -53,6 +53,8 @@ const SettingsTable =
5353
>
5454
<thead>
5555
<tr style={{ ...thBorder }}>
56+
<th style={{ ...settingsStyle, ...noBorder }}>Enabled</th>
57+
<th style={{ ...featureStyle, ...noBorder }}>Feature</th>
5658
<th
5759
style={{
5860
...settingsStyle,
@@ -62,10 +64,8 @@ const SettingsTable =
6264
>
6365
Info
6466
</th>
65-
<th style={{ ...featureStyle, ...noBorder }}>Feature</th>
66-
<th style={{ ...settingsStyle, ...noBorder }}>Documentation</th>
6767
{/* <th style={{ ...settingsStyle }}>Settings</th> */}
68-
<th style={{ ...settingsStyle, ...noBorder }}>Enabled</th>
68+
<th style={{ ...settingsStyle, ...noBorder }}>Documentation</th>
6969
</tr>
7070
</thead>
7171
<tbody>
@@ -80,6 +80,36 @@ const SettingsTable =
8080
}}
8181
>
8282
<td
83+
aria-label="On/Off Switch"
84+
style={{ ...settingsStyle, ...noBorder }}
85+
>
86+
<Switch
87+
checked={featureToggleSettings[id]}
88+
onChange={(e) => {
89+
const updatedSettings = {
90+
...featureToggleSettings,
91+
[id]: (e.target as HTMLInputElement).checked,
92+
};
93+
setFeatureToggleSettings(updatedSettings);
94+
extensionAPI.settings.set(
95+
id,
96+
(e.target as HTMLInputElement).checked
97+
);
98+
module.toggleFeature(
99+
(e.target as HTMLInputElement).checked,
100+
extensionAPI
101+
);
102+
}}
103+
/>
104+
</td>
105+
<td
106+
aria-label="Feature Name"
107+
style={{ ...featureStyle, ...noBorder }}
108+
>
109+
<span>{name}</span>
110+
</td>
111+
<td
112+
aria-label="Info button"
83113
style={{
84114
...settingsStyle,
85115
...noBorder,
@@ -112,19 +142,9 @@ const SettingsTable =
112142
<Button icon="info-sign" />
113143
</Popover>
114144
</td>
115-
<td style={{ ...featureStyle, ...noBorder }}>
116-
<span>{name}</span>
117-
</td>
118-
<td style={{ ...settingsStyle, ...noBorder }}>
119-
<AnchorButton
120-
intent="primary"
121-
icon="document-open"
122-
href={`https://github.com/RoamJs/workbench/blob/main/docs/${docs}`}
123-
/>
124-
</td>
125145
{/* placeholder for when settings migrated to API */}
126146
{/* https://github.com/RoamJS/workbench/issues/402 */}
127-
{/* <td style={{ ...settingsStyle, ...cellsBorder }}>
147+
{/* <td aria-label="Settings button" style={{ ...settingsStyle, ...cellsBorder }}>
128148
{settings ? (
129149
<Button
130150
intent="primary"
@@ -135,24 +155,14 @@ const SettingsTable =
135155
/>
136156
) : null}
137157
</td> */}
138-
<td style={{ ...settingsStyle, ...noBorder }}>
139-
<Switch
140-
checked={featureToggleSettings[id]}
141-
onChange={(e) => {
142-
const updatedSettings = {
143-
...featureToggleSettings,
144-
[id]: (e.target as HTMLInputElement).checked,
145-
};
146-
setFeatureToggleSettings(updatedSettings);
147-
extensionAPI.settings.set(
148-
id,
149-
(e.target as HTMLInputElement).checked
150-
);
151-
module.toggleFeature(
152-
(e.target as HTMLInputElement).checked,
153-
extensionAPI
154-
);
155-
}}
158+
<td
159+
aria-label="Docs Button"
160+
style={{ ...settingsStyle, ...noBorder }}
161+
>
162+
<AnchorButton
163+
intent="primary"
164+
icon="document-open"
165+
href={`https://github.com/RoamJs/workbench/blob/main/docs/${docs}`}
156166
/>
157167
</td>
158168
</tr>

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export default runExtension(async ({ extensionAPI, extension }) => {
202202
name: "WorkBench Features",
203203
action: {
204204
type: "reactComponent",
205-
component: SettingsTable(FEATURES, initialSettings, extensionAPI),
205+
component: SettingsTable(FEATURES, extensionAPI),
206206
},
207207
},
208208
],

0 commit comments

Comments
 (0)