Skip to content

Commit 2b6ee76

Browse files
keikarimiko
andauthored
Minor fixes around playlist (#3416)
* Fix some collection publish errors not reaching UI * Trim leading/trailing whitespaces in collection title * Fix new playlist creation eating "Enter" globally until reload * Coderabbit --------- Co-authored-by: miko <sauce47@posteo.net>
1 parent 651ca81 commit 2b6ee76

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

ui/component/formNewCollection/view.jsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function FormNewCollection(props: Props) {
3232
}
3333

3434
function handleAddCollection() {
35-
const name = newCollectionName;
35+
const name = newCollectionName.trim();
3636
let id;
3737

3838
doPlaylistAddAndAllowPlaying({
@@ -50,21 +50,13 @@ function FormNewCollection(props: Props) {
5050
closeForm(name, id);
5151
}
5252

53-
function altEnterListener(e: SyntheticKeyboardEvent<*>) {
53+
function handleKeyDown(e: SyntheticKeyboardEvent<*>) {
5454
if (e.keyCode === KEYCODES.ENTER) {
5555
e.preventDefault();
5656
buttonref.current.click();
5757
}
5858
}
5959

60-
function onTextareaFocus() {
61-
window.addEventListener('keydown', altEnterListener);
62-
}
63-
64-
function onTextareaBlur() {
65-
window.removeEventListener('keydown', altEnterListener);
66-
}
67-
6860
function handleClearNew() {
6961
closeForm();
7062
}
@@ -76,16 +68,15 @@ function FormNewCollection(props: Props) {
7668
name="new_collection"
7769
label={__('New Playlist Title')}
7870
placeholder={__(COLLECTIONS_CONSTS.PLACEHOLDER)}
79-
onFocus={onTextareaFocus}
80-
onBlur={onTextareaBlur}
71+
onKeyDown={handleKeyDown}
8172
inputButton={
8273
<>
8374
<Button
8475
button="alt"
8576
icon={ICONS.COMPLETED}
8677
title={__('Confirm')}
8778
className="button-toggle"
88-
disabled={newCollectionName.length === 0}
79+
disabled={newCollectionName.trim().length === 0}
8980
onClick={handleAddCollection}
9081
ref={buttonref}
9182
/>

ui/page/collection/internal/collectionPublishForm/view.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const CollectionPublishForm = (props: Props) => {
104104
setFormParams((prevParams) => ({ ...prevParams, ...newParams }));
105105
}
106106

107-
function handlePublish() {
107+
function handlePublish(params) {
108108
setPublishPending(true);
109109

110110
const successCb = (pendingClaim) => {
@@ -118,17 +118,22 @@ const CollectionPublishForm = (props: Props) => {
118118
};
119119

120120
// $FlowFixMe
121-
doCollectionPublish(formParams, collectionId)
121+
doCollectionPublish(params, collectionId)
122122
.then(successCb)
123123
.catch(() => setPublishPending(false));
124124
}
125125

126126
function handleSubmitForm() {
127127
if (!hasChanges) return goBack();
128128

129+
const trimmedParams = { ...formParams };
130+
if (trimmedParams.title) trimmedParams.title = trimmedParams.title.trim();
131+
132+
setFormParams(trimmedParams);
133+
129134
if (editing) {
130135
// $FlowFixMe
131-
doCollectionEdit(collectionId, formParams);
136+
doCollectionEdit(collectionId, trimmedParams);
132137

133138
return onDoneForId(collectionId);
134139
}
@@ -140,12 +145,12 @@ const CollectionPublishForm = (props: Props) => {
140145
'You are about to publish this playlist with unavailable items that will be removed (all other items will be unaffected). This action is permanent and cannot be undone.'
141146
),
142147
onConfirm: (closeModal) => {
143-
handlePublish();
148+
handlePublish(trimmedParams);
144149
closeModal();
145150
},
146151
});
147152
} else {
148-
handlePublish();
153+
handlePublish(trimmedParams);
149154
}
150155
}
151156

ui/redux/actions/collections.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export function doCollectionPublish(options: CollectionPublishCreateParams, coll
160160
function failure(error) {
161161
if (cb) cb();
162162

163-
const scriptSizeError = error.message.match(/script size ([0-9]+) exceeds limit 8192/);
163+
const scriptSizeError = error?.message?.match && error.message.match(/script size ([0-9]+) exceeds limit 8192/);
164164
let customMessage = null;
165165
if (scriptSizeError) {
166166
const maxSize = 8192;
@@ -179,7 +179,7 @@ export function doCollectionPublish(options: CollectionPublishCreateParams, coll
179179
? __('or %extraBytes% characters of text.', { extraBytes })
180180
: __('or 1 character of text.'));
181181
}
182-
dispatch(doToast({ message: customMessage || error.message, isError: true }));
182+
dispatch(doToast({ message: customMessage || error.message || error, isError: true }));
183183
reject(error);
184184
throw new Error(error);
185185
}

0 commit comments

Comments
 (0)