Skip to content

Instantly share code, notes, and snippets.

@tommyp
Last active August 6, 2022 16:47
Show Gist options
  • Save tommyp/b184016ea69486733224009f7eb93821 to your computer and use it in GitHub Desktop.
Save tommyp/b184016ea69486733224009f7eb93821 to your computer and use it in GitHub Desktop.
<script>
let results = [];
$: console.log({ results });
</script>
{#if results.length > 0}
<Results {results} />
{:else}
<Search {results} />
{/if}
<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