Last active
August 6, 2022 16:47
-
-
Save tommyp/b184016ea69486733224009f7eb93821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
let results = []; | |
$: console.log({ results }); | |
</script> | |
{#if results.length > 0} | |
<Results {results} /> | |
{:else} | |
<Search {results} /> | |
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
export let results; | |
const handleSubmit = () => { | |
const requests = artists | |
.split('\n') | |
.map((a) => a.split(',')) | |
.flat() | |
.map((a) => a.split('b2b')) | |
.flat() | |
.map((a) => a.trim()); | |
Promise.allSettled(requests.map((artist) => spotify.searchArtists(artist))) | |
.then((promises) => { | |
promises.forEach((promise, index) => { | |
if (promise.status === 'fulfilled') { | |
const { value } = promise; | |
if (value.artists.total > 0) { | |
results = [...results, value.artists.items[0]]; | |
} | |
return promise.value.artists.items[0]; | |
} | |
}); | |
}) | |
.catch((error) => console.log(error)); | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment