Set default time to 'this week' in discover params

This commit is contained in:
patrickkfkan 2021-01-24 21:04:07 +08:00
parent 9645bf0cc7
commit ee34118b7d

View File

@ -37,7 +37,7 @@ async function discover(params, options = {}) {
async function sanitizeDiscoverParams(params) { async function sanitizeDiscoverParams(params) {
return getDiscoverOptions().then( options => { return getDiscoverOptions().then( options => {
const getOptionValue = (optArr, value) => { const getOptionValue = (optArr, value, defaultIndex = 0) => {
if (value !== undefined && optArr) { if (value !== undefined && optArr) {
const opt = optArr.find( o => o.value == value ); const opt = optArr.find( o => o.value == value );
if (opt) { if (opt) {
@ -45,7 +45,7 @@ async function sanitizeDiscoverParams(params) {
} }
} }
if (optArr) { if (optArr) {
return optArr[0].value; return optArr[defaultIndex].value;
} }
else { else {
return null; return null;
@ -66,7 +66,7 @@ async function sanitizeDiscoverParams(params) {
// or subgenre is 'all-metal') // or subgenre is 'all-metal')
const timeAllowed = sanitized.subgenre === undefined || sanitized.subgenre == subgenreOptions[0].value; const timeAllowed = sanitized.subgenre === undefined || sanitized.subgenre == subgenreOptions[0].value;
if (timeAllowed) { if (timeAllowed) {
sanitized.time = getOptionValue(options.times, params.time); sanitized.time = getOptionValue(options.times, params.time, 1);
} }
sanitized.location = getOptionValue(options.locations, params.location); sanitized.location = getOptionValue(options.locations, params.location);
sanitized.format = getOptionValue(options.formats, params.format); sanitized.format = getOptionValue(options.formats, params.format);