1
1
import { type App , Notice , PluginSettingTab , Setting , moment } from 'obsidian' ;
2
+ import { createRoot , type Root } from 'react-dom/client' ;
3
+ import { useDebounce } from 'src/util/useDebounce' ;
4
+
2
5
import type ScribePlugin from 'src' ;
3
- import { formatFilenamePrefix } from 'src/util/filenameUtils' ;
6
+
4
7
import { LLM_MODELS } from 'src/util/openAiUtils' ;
5
8
9
+ import { FileNameSettings } from './components/FileNameSettings' ;
10
+
6
11
export enum TRANSCRIPT_PLATFORM {
7
12
assemblyAi = 'assemblyAi' ,
8
13
openAi = 'openAi' ,
@@ -41,6 +46,7 @@ export async function handleSettingsTab(plugin: ScribePlugin) {
41
46
42
47
export class ScribeSettingsTab extends PluginSettingTab {
43
48
plugin : ScribePlugin ;
49
+ reactRoot : Root | null ;
44
50
45
51
constructor ( app : App , plugin : ScribePlugin ) {
46
52
super ( app , plugin ) ;
@@ -178,109 +184,12 @@ export class ScribeSettingsTab extends PluginSettingTab {
178
184
component . setValue ( this . plugin . settings . transcriptPlatform ) ;
179
185
} ) ;
180
186
181
- containerEl . createEl ( 'h2' , { text : 'File name properties' } ) ;
182
- containerEl . createEl ( 'sub' , {
183
- text : 'These settings must be saved via the button for validation purposes' ,
184
- } ) ;
185
-
186
- const isDateInPrefix = ( ) =>
187
- this . plugin . settings . noteFilenamePrefix . includes ( '{{date}}' ) ||
188
- this . plugin . settings . recordingFilenamePrefix . includes ( '{{date}}' ) ;
189
-
190
- new Setting ( containerEl )
191
- . setName ( 'Transcript filename prefix' )
192
- . setDesc (
193
- 'This will be the prefix of the note filename, use {{date}} to include the date' ,
194
- )
195
- . addText ( ( text ) => {
196
- text . setPlaceholder ( 'scribe-' ) ;
197
- text . onChange ( ( value ) => {
198
- this . plugin . settings . noteFilenamePrefix = value ;
199
-
200
- dateInput . setDisabled ( ! isDateInPrefix ( ) ) ;
201
- } ) ;
202
-
203
- text . setValue ( this . plugin . settings . noteFilenamePrefix ) ;
204
- } ) ;
205
-
206
- new Setting ( containerEl )
207
- . setName ( 'Audio recording filename prefix' )
208
- . setDesc (
209
- 'This will be the prefix of the audio recording filename, use {{date}} to include the date' ,
210
- )
211
- . addText ( ( text ) => {
212
- text . setPlaceholder ( 'scribe-' ) ;
213
- text . onChange ( ( value ) => {
214
- this . plugin . settings . recordingFilenamePrefix = value ;
215
- dateInput . setDisabled ( ! isDateInPrefix ( ) ) ;
216
- } ) ;
217
-
218
- text . setValue ( this . plugin . settings . recordingFilenamePrefix ) ;
219
- } ) ;
220
-
221
- const dateInput = new Setting ( containerEl )
222
- . setName ( 'Date format' )
223
- . setDesc (
224
- 'This will only be used if {{date}} is in the transcript or audio recording filename prefix above.' ,
225
- )
226
- . addText ( ( text ) => {
227
- text . setDisabled ( ! isDateInPrefix ( ) ) ;
228
- text . setPlaceholder ( 'YYYY-MM-DD' ) ;
229
- text . onChange ( ( value ) => {
230
- this . plugin . settings . dateFilenameFormat = value ;
231
- console . log ( value ) ;
232
- try {
233
- new Notice (
234
- `📆 Format: ${ formatFilenamePrefix (
235
- 'some-prefix-{{date}}' ,
236
- value ,
237
- ) } `,
238
- ) ;
239
- } catch ( error ) {
240
- console . error ( 'Invalid date format' , error ) ;
241
- new Notice ( `Invalid date format: ${ value } ` ) ;
242
- }
243
- } ) ;
244
-
245
- text . setValue ( this . plugin . settings . dateFilenameFormat ) ;
246
- } ) ;
247
-
248
- new Setting ( containerEl ) . addButton ( ( button ) => {
249
- button . setButtonText ( 'Save settings' ) ;
250
- button . onClick ( async ( ) => {
251
- if ( ! this . plugin . settings . noteFilenamePrefix ) {
252
- new Notice (
253
- '⚠️ You must provide a note filename prefix, setting to default' ,
254
- ) ;
255
- this . plugin . settings . noteFilenamePrefix =
256
- DEFAULT_SETTINGS . noteFilenamePrefix ;
257
- }
258
-
259
- if ( ! this . plugin . settings . recordingFilenamePrefix ) {
260
- new Notice (
261
- '⚠️ You must provide a recording filename prefix, setting to default' ,
262
- ) ;
263
- this . plugin . settings . recordingFilenamePrefix =
264
- DEFAULT_SETTINGS . recordingFilenamePrefix ;
265
- }
266
-
267
- if (
268
- this . plugin . settings . noteFilenamePrefix . includes ( '{{date}}' ) &&
269
- ! this . plugin . settings . dateFilenameFormat
270
- ) {
271
- new Notice ( '⚠️ You must provide a date format, setting to default' ) ;
272
- this . plugin . settings . dateFilenameFormat =
273
- DEFAULT_SETTINGS . dateFilenameFormat ;
274
- }
275
-
276
- this . saveSettings ( ) ;
277
- this . display ( ) ;
278
- } ) ;
187
+ const reactTestWrapper = containerEl . createDiv ( {
188
+ cls : 'scribe-settings-react' ,
279
189
} ) ;
280
190
281
- containerEl . createEl ( 'sub' , {
282
- text : 'This functionality will improve in future versions' ,
283
- } ) ;
191
+ this . reactRoot = createRoot ( reactTestWrapper ) ;
192
+ this . reactRoot . render ( < ScribeSettings plugin = { this . plugin } /> ) ;
284
193
285
194
new Setting ( containerEl ) . addButton ( ( button ) => {
286
195
button . setButtonText ( 'Reset to default' ) ;
@@ -299,6 +208,17 @@ export class ScribeSettingsTab extends PluginSettingTab {
299
208
300
209
saveSettings ( ) {
301
210
this . plugin . saveSettings ( ) ;
302
- new Notice ( 'Scribe: ✅ Settings saved' ) ;
303
211
}
304
212
}
213
+
214
+ const ScribeSettings : React . FC < { plugin : ScribePlugin } > = ( { plugin } ) => {
215
+ const debouncedSaveSettings = useDebounce ( ( ) => {
216
+ plugin . saveSettings ( ) ;
217
+ } , 700 ) ;
218
+
219
+ return (
220
+ < div >
221
+ < FileNameSettings plugin = { plugin } saveSettings = { debouncedSaveSettings } />
222
+ </ div >
223
+ ) ;
224
+ } ;
0 commit comments