Skip to content

Commit 41261fb

Browse files
Address review comments
1 parent 9a8cdd9 commit 41261fb

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

CONFIGURATION.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,17 @@ further below for information on that.
106106
# Default: 'optional'.
107107
#seriesField = 'optional'
108108

109-
# Whether and if so how to fill the presenter name in the upload step.
110-
# This is a list of sources for potential presenter names to suggest,
111-
# in order of descending preference.
112-
# If it is empty, nothing is suggested.
113-
# Note that right now there is only one such source,
114-
# and that manual changes to the presenter form field
115-
# will be persisted in the users' `localStorage`,
116-
# and that stored value will always be preferred
117-
# over the generated suggestion.
109+
# Whether to fill the presenter name in the upload step, and if so, how.
110+
# This is a list of sources for potential presenter names to fill in,
111+
# in order of descending preference. If it is empty, nothing is suggested.
112+
#
113+
# Note that right now there is only one such source. Also, manual changes
114+
# to the presenter form field will be persisted in the users' `localStorage`,
115+
# and that stored value will always be preferred over the other sources.
118116
#
119117
# Possible sources are:
120-
# - `"opencast"`: Get the name from Opencast's `/info/me.json` API
118+
# - `"opencast"`: Get the name from Opencast's `/info/me.json` API,
119+
# specifically the field `user.name`
121120
#autofillPresenter = []
122121

123122

src/opencast.tsx

+9-19
Original file line numberDiff line numberDiff line change
@@ -290,25 +290,15 @@ export class Opencast {
290290

291291
/** Returns the value from user.name from the `/info/me.json` endpoint. */
292292
getUsername(): string | null {
293-
if (!(this.#currentUser)) {
294-
return null;
295-
}
296-
if (!(typeof this.#currentUser === "object")) {
297-
return null;
298-
}
299-
if (!("user" in this.#currentUser)) {
300-
return null;
301-
}
302-
if (!this.#currentUser.user) {
303-
return null;
304-
}
305-
if (!(typeof this.#currentUser.user === "object")) {
306-
return null;
307-
}
308-
if (!("name" in this.#currentUser.user)) {
309-
return null;
310-
}
311-
if (!(typeof this.#currentUser.user.name === "string")) {
293+
if (!(
294+
this.#currentUser
295+
&& typeof this.#currentUser === "object"
296+
&& "user" in this.#currentUser
297+
&& this.#currentUser.user
298+
&& typeof this.#currentUser.user === "object"
299+
&& "name" in this.#currentUser.user
300+
&& typeof this.#currentUser.user.name === "string"
301+
)) {
312302
return null;
313303
}
314304
return this.#currentUser.user.name;

src/steps/finish/upload.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,12 @@ type UploadFormProps = {
159159
};
160160

161161
const UploadForm: React.FC<UploadFormProps> = ({ handleUpload }) => {
162-
const uploadSettings = useSettings().upload ?? {};
163162
const {
164163
titleField = "required",
165164
presenterField = "required",
166165
seriesField = "optional",
167166
autofillPresenter = [],
168-
} = uploadSettings;
167+
} = useSettings().upload ?? {};
169168

170169
const { t, i18n } = useTranslation();
171170
const opencast = useOpencast();
@@ -178,7 +177,7 @@ const UploadForm: React.FC<UploadFormProps> = ({ handleUpload }) => {
178177
.map(source => match(source, {
179178
"opencast": () => opencast.getUsername(),
180179
}))
181-
.filter(Boolean)[0]
180+
.find(Boolean)
182181
|| "";
183182

184183
type FormState = "idle" | "testing";
@@ -214,6 +213,15 @@ const UploadForm: React.FC<UploadFormProps> = ({ handleUpload }) => {
214213
}
215214
}
216215

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.
219+
useEffect(() => {
220+
if (presenterValue !== presenter) {
221+
dispatch({ type: "UPDATE_PRESENTER", value: presenterValue });
222+
}
223+
}, []);
224+
217225
const configurableServerUrl = settingsManager.isConfigurable("opencast.serverUrl");
218226
const configurableUsername = settingsManager.isUsernameConfigurable();
219227
const configurablePassword = settingsManager.isPasswordConfigurable();

0 commit comments

Comments
 (0)