function attributeUrl(url, { source, medium }) { const attributedUrl = new URL(url); // Adding source attribution to the URL for Unsplash to track usage // https://help.unsplash.com/articles/2511315-guideline-attribution if (source) { attributedUrl.searchParams.set('utm_source', source); if (medium) { attributedUrl.searchParams.set('utm_medium', medium); } } return attributedUrl; }
function stripAutoPlays( searchParams ) { const returnVal = new URLSearchParams( searchParams ); const keys = Array.from( searchParams.keys() ).filter( ( k ) => /^auto_?play$/i.test( k ) ) || []; keys.forEach( ( key ) => { // In the rare case that we're handed an array of values, we use the first one const val = searchParams.get( key ).toLowerCase(); if ( val === '1' ) { returnVal.set( key, '0' ); } else if ( val === 'true' ) { returnVal.set( key, 'false' ); } else { // force a singular value returnVal.set( key, val ); } } ); return returnVal; }
const handleChangeSearch = async ({ target: { name, value } }) => { const currentSearch = new URLSearchParams(searchToSendForRequest); // Pagination currentSearch.delete('_start'); if (value === '') { currentSearch.delete(name); } else { currentSearch.set(name, value); } const searchToString = currentSearch.toString(); push({ search: searchToString }); }
urlParts.searchParams.set( sizeParam, width * IMAGE_SCALE_FACTOR ); urlParts.searchParams.set( 'quality', DEFAULT_PHOTON_QUALITY ); urlParts.searchParams.set( 'strip', 'info' ); // strip all exif data, leave ICC intact sortedKeys.forEach( ( key ) => sortedParams.set( key, urlParts.searchParams.get( key ) ) );
const handleChangeFilters = ({ target: { value } }) => { const newSearch = new URLSearchParams(); // Set the default params newSearch.set('_limit', _limit); newSearch.set('_sort', _sort); newSearch.set('_page', 1); value.forEach(({ filter, name, value: filterValue }) => { const filterType = filter === '=' ? '' : filter; const filterName = `${name}${filterType}`; newSearch.append(filterName, filterValue); }); push({ search: newSearch.toString() }); }
const handleChangeSearch = async ({ target: { name, value } }) => { const currentSearch = new URLSearchParams(searchToSendForRequest); // Pagination currentSearch.delete('_start'); if (value === '') { currentSearch.delete(name); } else { currentSearch.set(name, value); } const searchToString = currentSearch.toString(); push({ search: searchToString }); }
function attributeUrl(url, { source, medium }) { const attributedUrl = new URL(url); // Adding source attribution to the URL for Unsplash to track usage // https://help.unsplash.com/articles/2511315-guideline-attribution if (source) { attributedUrl.searchParams.set('utm_source', source); if (medium) { attributedUrl.searchParams.set('utm_medium', medium); } } return attributedUrl; }
const handleChangeFilters = ({ target: { value } }) => { const newSearch = new URLSearchParams(); // Set the default params newSearch.set('_limit', _limit); newSearch.set('_sort', _sort); newSearch.set('_page', 1); value.forEach(({ filter, name, value: filterValue }) => { const filterType = filter === '=' ? '' : filter; const filterName = `${name}${filterType}`; newSearch.append(filterName, filterValue); }); push({ search: newSearch.toString() }); }