@@ -10,12 +10,12 @@ import { OnloadArgs } from "roamjs-components/types";
1010import { Feature } from "../index" ;
1111
1212const 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 >
0 commit comments