mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Prevent blank playlist names
This commit is contained in:
parent
363171b56d
commit
a37388b2e3
3 changed files with 37 additions and 3 deletions
|
@ -11,6 +11,7 @@ import globalize from 'lib/globalize';
|
||||||
import { currentSettings as userSettings } from 'scripts/settings/userSettings';
|
import { currentSettings as userSettings } from 'scripts/settings/userSettings';
|
||||||
import { PluginType } from 'types/plugin';
|
import { PluginType } from 'types/plugin';
|
||||||
import { toApi } from 'utils/jellyfin-apiclient/compat';
|
import { toApi } from 'utils/jellyfin-apiclient/compat';
|
||||||
|
import { isBlank } from 'utils/string';
|
||||||
|
|
||||||
import dialogHelper from '../dialogHelper/dialogHelper';
|
import dialogHelper from '../dialogHelper/dialogHelper';
|
||||||
import loading from '../loading/loading';
|
import loading from '../loading/loading';
|
||||||
|
@ -86,12 +87,15 @@ function createPlaylist(dlg: DialogElement) {
|
||||||
const apiClient = ServerConnections.getApiClient(currentServerId);
|
const apiClient = ServerConnections.getApiClient(currentServerId);
|
||||||
const api = toApi(apiClient);
|
const api = toApi(apiClient);
|
||||||
|
|
||||||
|
const name = dlg.querySelector<HTMLInputElement>('#txtNewPlaylistName')?.value;
|
||||||
|
if (isBlank(name)) return Promise.reject(new Error('Playlist name should not be blank'));
|
||||||
|
|
||||||
const itemIds = dlg.querySelector<HTMLInputElement>('.fldSelectedItemIds')?.value || undefined;
|
const itemIds = dlg.querySelector<HTMLInputElement>('.fldSelectedItemIds')?.value || undefined;
|
||||||
|
|
||||||
return getPlaylistsApi(api)
|
return getPlaylistsApi(api)
|
||||||
.createPlaylist({
|
.createPlaylist({
|
||||||
createPlaylistDto: {
|
createPlaylistDto: {
|
||||||
Name: dlg.querySelector<HTMLInputElement>('#txtNewPlaylistName')?.value,
|
Name: name,
|
||||||
IsPublic: dlg.querySelector<HTMLInputElement>('#chkPlaylistPublic')?.checked,
|
IsPublic: dlg.querySelector<HTMLInputElement>('#chkPlaylistPublic')?.checked,
|
||||||
Ids: itemIds?.split(','),
|
Ids: itemIds?.split(','),
|
||||||
UserId: apiClient.getCurrentUserId()
|
UserId: apiClient.getCurrentUserId()
|
||||||
|
@ -115,11 +119,14 @@ function updatePlaylist(dlg: DialogElement) {
|
||||||
|
|
||||||
if (!dlg.playlistId) return Promise.reject(new Error('Missing playlist ID'));
|
if (!dlg.playlistId) return Promise.reject(new Error('Missing playlist ID'));
|
||||||
|
|
||||||
|
const name = dlg.querySelector<HTMLInputElement>('#txtNewPlaylistName')?.value;
|
||||||
|
if (isBlank(name)) return Promise.reject(new Error('Playlist name should not be blank'));
|
||||||
|
|
||||||
return getPlaylistsApi(api)
|
return getPlaylistsApi(api)
|
||||||
.updatePlaylist({
|
.updatePlaylist({
|
||||||
playlistId: dlg.playlistId,
|
playlistId: dlg.playlistId,
|
||||||
updatePlaylistDto: {
|
updatePlaylistDto: {
|
||||||
Name: dlg.querySelector<HTMLInputElement>('#txtNewPlaylistName')?.value,
|
Name: name,
|
||||||
IsPublic: dlg.querySelector<HTMLInputElement>('#chkPlaylistPublic')?.checked
|
IsPublic: dlg.querySelector<HTMLInputElement>('#chkPlaylistPublic')?.checked
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,24 @@
|
||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
import { toBoolean, toFloat } from './string';
|
import { isBlank, toBoolean, toFloat } from './string';
|
||||||
|
|
||||||
|
describe('isBlank', () => {
|
||||||
|
it('Should return true if the string is blank', () => {
|
||||||
|
let check = isBlank(undefined);
|
||||||
|
expect(check).toBe(true);
|
||||||
|
check = isBlank(null);
|
||||||
|
expect(check).toBe(true);
|
||||||
|
check = isBlank('');
|
||||||
|
expect(check).toBe(true);
|
||||||
|
check = isBlank(' \t\t ');
|
||||||
|
expect(check).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should return false if the string is not blank', () => {
|
||||||
|
const check = isBlank('not an empty string');
|
||||||
|
expect(check).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('toBoolean', () => {
|
describe('toBoolean', () => {
|
||||||
it('Should return the boolean represented by the string', () => {
|
it('Should return the boolean represented by the string', () => {
|
||||||
|
|
|
@ -1,3 +1,12 @@
|
||||||
|
/**
|
||||||
|
* Checks if a string is empty or contains only whitespace.
|
||||||
|
* @param {string} value The string to test.
|
||||||
|
* @returns {boolean} True if the string is blank.
|
||||||
|
*/
|
||||||
|
export function isBlank(value: string | undefined | null) {
|
||||||
|
return !value?.trim().length;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of a string as boolean.
|
* Gets the value of a string as boolean.
|
||||||
* @param {string} name The value as a string.
|
* @param {string} name The value as a string.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue