mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-13 14:23:02 -05:00
fix: github api
This commit is contained in:
@@ -4,7 +4,7 @@ const response = await fetch(`https://api.github.com/search/issues?q=repo:tomala
|
|||||||
const { total_count } = await response.json();
|
const { total_count } = await response.json();
|
||||||
---
|
---
|
||||||
|
|
||||||
<div class="answer-text">Answered by {total_count} people</div>
|
{total_count ? <div class="answer-text">Answered by {total_count} people</div> : null }
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.answer-text {
|
.answer-text {
|
||||||
|
|||||||
@@ -11,18 +11,26 @@ const authorLink = `https://github.com/tomalaforge/angular-challenges/pulls?q=la
|
|||||||
const communityLink = `https://github.com/tomalaforge/angular-challenges/pulls?q=label%3A${challengeNumber}+label%3Aanswer+sort%3Areactions-%2B1-desc`;
|
const communityLink = `https://github.com/tomalaforge/angular-challenges/pulls?q=label%3A${challengeNumber}+label%3Aanswer+sort%3Areactions-%2B1-desc`;
|
||||||
const npxCommand = `npx nx serve ${command}`;
|
const npxCommand = `npx nx serve ${command}`;
|
||||||
|
|
||||||
const response = await fetch(`https://api.github.com/search/issues?q=repo:tomalaforge/angular-challenges+is:pr+label:%22${challengeNumber}%22+label:%22answer%22`);
|
let items = [];
|
||||||
const { total_count, items } = await response.json();
|
let page = 1;
|
||||||
|
let error = false;
|
||||||
let count = 1;
|
try {
|
||||||
while(total_count > count*30) {
|
while (true) {
|
||||||
const response = await fetch(`https://api.github.com/search/issues?q=repo:tomalaforge/angular-challenges+is:pr+label:%22${challengeNumber}%22+label:%22answer%22&page=${count}`);
|
const response = await fetch(`https://api.github.com/search/issues?q=repo:tomalaforge/angular-challenges+is:pr+label:%22${challengeNumber}%22+label:%22answer%22&per_page=100&page=${page}`);
|
||||||
const { items: new_items } = await response.json();
|
if (!response.ok) {
|
||||||
if(new_items && new_items.length === 0) break;
|
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;
|
||||||
items.push(...new_items);
|
items.push(...new_items);
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(total_count < page * 100) break;
|
||||||
|
|
||||||
|
page++;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
---
|
---
|
||||||
|
|
||||||
<div class="separator"></div>
|
<div class="separator"></div>
|
||||||
@@ -62,7 +70,7 @@ while(total_count > count*30) {
|
|||||||
<div class="article-footer">
|
<div class="article-footer">
|
||||||
<a
|
<a
|
||||||
href={communityLink}>
|
href={communityLink}>
|
||||||
❖ {total_count} {data['challenge.footer.communityAnswers']}*
|
❖ {items.length > 0 ? items.length : ''} {data['challenge.footer.communityAnswers']}*
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
href={authorLink}>
|
href={authorLink}>
|
||||||
@@ -83,6 +91,7 @@ while(total_count > count*30) {
|
|||||||
<VideoButton {...videoLink} {...Astro.props} />}
|
<VideoButton {...videoLink} {...Astro.props} />}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{error ? null :
|
||||||
<div class="solution-container">
|
<div class="solution-container">
|
||||||
<div>Answered by</div>
|
<div>Answered by</div>
|
||||||
{(items ?? []).map((item) => (
|
{(items ?? []).map((item) => (
|
||||||
@@ -95,7 +104,7 @@ while(total_count > count*30) {
|
|||||||
class="avatar"
|
class="avatar"
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>}
|
||||||
|
|
||||||
<div class="footer-note">
|
<div class="footer-note">
|
||||||
* {data['challenge.footer.upvoteAnswer']}
|
* {data['challenge.footer.upvoteAnswer']}
|
||||||
|
|||||||
Reference in New Issue
Block a user