mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
67 lines
1.4 KiB
Svelte
67 lines
1.4 KiB
Svelte
<script>
|
|
import { onMount } from 'svelte';
|
|
import { data, error, isLoaded, isLoading, totalCount } from './github-store';
|
|
|
|
export let challengeNumber;
|
|
|
|
let page = 1;
|
|
|
|
async function fetchTotalCount() {
|
|
isLoading.set(true);
|
|
try {
|
|
while (true) {
|
|
const response = await fetch(`https://api.github.com/search/issues?q=repo:tomalaforge/angular-challenges+is:pr+label:"${challengeNumber}"+label:"answer"&per_page=100&page=${page}`);
|
|
if (!response.ok) {
|
|
throw new Error('Network response was not ok');
|
|
}
|
|
const { items: new_items, total_count } = await response.json();
|
|
if (!new_items || new_items.length === 0) break;
|
|
data.update(items => [...items, ...new_items]);
|
|
totalCount.set(total_count);
|
|
|
|
if(total_count < page * 100) break;
|
|
|
|
page++;
|
|
}
|
|
} catch (e) {
|
|
error.set(true);
|
|
} finally {
|
|
isLoading.set(false);
|
|
}
|
|
}
|
|
|
|
onMount(() => {
|
|
fetchTotalCount();
|
|
});
|
|
|
|
</script>
|
|
|
|
{#if $isLoaded}
|
|
<div class="solution-container">
|
|
<div>Answered by</div>
|
|
{#each $data as { user }}
|
|
<img
|
|
loading="lazy"
|
|
src={user.avatar_url}
|
|
width="30"
|
|
height="30"
|
|
alt=""
|
|
class="avatar"
|
|
/>
|
|
{/each}
|
|
</div>
|
|
{/if}
|
|
|
|
<style>
|
|
.solution-container {
|
|
margin-top: 3rem;
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 0.5rem;
|
|
|
|
}
|
|
.avatar {
|
|
border-radius: 50%;
|
|
}
|
|
</style>
|