@@ -163,14 +163,22 @@ const UploadForm: React.FC<UploadFormProps> = ({ handleUpload }) => {
163
163
titleField = "required" ,
164
164
presenterField = "required" ,
165
165
seriesField = "optional" ,
166
+ autofillPresenter = [ ] ,
166
167
} = useSettings ( ) . upload ?? { } ;
167
168
168
169
const { t, i18n } = useTranslation ( ) ;
169
170
const opencast = useOpencast ( ) ;
170
171
const dispatch = useDispatch ( ) ;
171
172
const settingsManager = useSettingsManager ( ) ;
172
173
const { title, presenter, upload : uploadState , recordings } = useStudioState ( ) ;
173
- const presenterValue = presenter || window . localStorage . getItem ( LAST_PRESENTER_KEY ) || "" ;
174
+ const presenterValue = presenter
175
+ || window . localStorage . getItem ( LAST_PRESENTER_KEY )
176
+ || autofillPresenter
177
+ . map ( source => match ( source , {
178
+ "opencast" : ( ) => opencast . getUsername ( ) ,
179
+ } ) )
180
+ . find ( Boolean )
181
+ || "" ;
174
182
175
183
type FormState = "idle" | "testing" ;
176
184
const [ state , setState ] = useState < FormState > ( "idle" ) ;
@@ -205,13 +213,14 @@ const UploadForm: React.FC<UploadFormProps> = ({ handleUpload }) => {
205
213
}
206
214
}
207
215
208
- // If the user has not yet changed the value of the field and the last used
209
- // presenter name is used in local storage, use that.
216
+ // If the user has not yet changed the value of the field, but it has been prefilled
217
+ // from local storage or one of the `autofillPresenter` sources, update the state
218
+ // using that value.
210
219
useEffect ( ( ) => {
211
220
if ( presenterValue !== presenter ) {
212
221
dispatch ( { type : "UPDATE_PRESENTER" , value : presenterValue } ) ;
213
222
}
214
- } ) ;
223
+ } , [ ] ) ;
215
224
216
225
const configurableServerUrl = settingsManager . isConfigurable ( "opencast.serverUrl" ) ;
217
226
const configurableUsername = settingsManager . isUsernameConfigurable ( ) ;
@@ -404,20 +413,23 @@ const UploadForm: React.FC<UploadFormProps> = ({ handleUpload }) => {
404
413
} ;
405
414
406
415
type InputProps < I extends FieldValues , F > =
407
- Pick < JSX . IntrinsicElements [ "input" ] , "onChange" | "autoComplete" | "defaultValue" | "onBlur" > &
416
+ Pick <
417
+ JSX . IntrinsicElements [ "input" ] ,
418
+ "onChange" | "autoComplete" | "defaultValue" | "onBlur"
419
+ > &
408
420
Pick < ReturnType < typeof useForm < I > > , "register" > & {
409
- /** Human readable string describing the field. */
410
- label : string ;
411
- name : Path < I > ;
412
- /** Whether this field is required or may be empty. */
413
- required : boolean ;
414
- /** Function validating the value and returning a string in the case of error. */
415
- validate ?: Validate < F , I > ;
416
- errors : Partial < Record < keyof I , FieldError > > ;
417
- /** Passed to the `<input>`. */
418
- type ?: HTMLInputTypeAttribute ;
419
- autoFocus ?: boolean ;
420
- } ;
421
+ /** Human readable string describing the field. */
422
+ label : string ;
423
+ name : Path < I > ;
424
+ /** Whether this field is required or may be empty. */
425
+ required : boolean ;
426
+ /** Function validating the value and returning a string in the case of error. */
427
+ validate ?: Validate < F , I > ;
428
+ errors : Partial < Record < keyof I , FieldError > > ;
429
+ /** Passed to the `<input>`. */
430
+ type ?: HTMLInputTypeAttribute ;
431
+ autoFocus ?: boolean ;
432
+ } ;
421
433
422
434
/**
423
435
* A styled `<input>` element with a label. Displays errors and integrated with
0 commit comments