Skip to content

Commit 9e41a4b

Browse files
committed
Refactor GithubFeed to handle PR events
The logic for determining the verb for pull request events has been simplified and reorganized. Previously, it relied heavily on fetching PR details first, which could lead to unnecessary API calls. This change prioritizes checking the event type and action before fetching details, improving efficiency and clarity. Additionally, the loading state for the GitHub feed has been updated with a more detailed and visually representative skeleton loader. The styling of the GitHub feed heading has also been adjusted for better consistency.
1 parent a92b2b0 commit 9e41a4b

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

src/components/GithubFeed.svelte

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,23 @@
7373
const prKey = `${repo.name}#${pr.number}`;
7474
if (processedPRs.has(prKey)) continue;
7575
76-
const details = await fetchDetails(pr.url);
77-
7876
let verb = "";
79-
if (details.merged) {
77+
78+
if (type === "PullRequestEvent" && payload.action === "closed" && pr.merged) {
8079
verb = "merged";
8180
} else if (type === "PullRequestReviewEvent") {
8281
const state = payload.review.state.toLowerCase();
8382
if (state === "commented") continue;
8483
verb = state.replace("_", " ");
85-
} else {
86-
if (!allowedActions.includes(payload.action)) continue;
84+
} else if (type === "PullRequestEvent" && allowedActions.includes(payload.action)) {
8785
verb = payload.action;
86+
} else {
87+
continue;
8888
}
8989
90+
const details = await fetchDetails(pr.url);
9091
processedPRs.add(prKey);
92+
9193
tempEvents.push({
9294
...base,
9395
verb: verb + " pull request",
@@ -123,9 +125,27 @@
123125
</script>
124126

125127
{#if loading}
126-
<div class="space-y-4 p-4">
127-
{#each Array(3) as _}
128-
<div class="h-28 w-full animate-pulse rounded-xl bg-viola-50" />
128+
<div class="flex flex-col space-y-3">
129+
{#each Array(8) as _}
130+
<div class="mx-2 animate-pulse rounded-xl bg-viola-50 p-4 sm:mx-4 sm:p-5">
131+
<div class="flex items-start space-x-3 sm:space-x-4">
132+
<div class="h-8 w-8 shrink-0 rounded-full bg-viola-200 sm:h-10 sm:w-10" />
133+
134+
<div class="min-w-0 flex-1">
135+
<div class="mb-1 flex flex-col sm:mb-0 sm:flex-row sm:items-center sm:justify-between">
136+
<div class="h-4 w-3/4 rounded bg-viola-200 sm:w-1/2" />
137+
<div class="mt-2 h-3 w-16 rounded bg-viola-100 sm:mt-0" />
138+
</div>
139+
140+
<div class="mt-3 space-y-2">
141+
<div class="h-3 w-full rounded bg-viola-100/70" />
142+
<div class="h-3 w-5/6 rounded bg-viola-100/70" />
143+
</div>
144+
145+
<div class="mt-4 h-3 w-24 rounded bg-viola-200/60" />
146+
</div>
147+
</div>
148+
</div>
129149
{/each}
130150
</div>
131151
{:else}

src/pages/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import GithubFeed from "../components/GithubFeed.svelte";
6767
</div>
6868

6969
<div class="m-2 rounded-lg bg-viola-100 p-6 shadow-lg lg:p-8">
70-
<h2 class="lg:mb-6 text-2xl font-bold">GitHub Feed</h2>
70+
<h2 class="mb-6 text-2xl font-bold">GitHub Feed</h2>
7171
<GithubFeed client:idle />
7272
</div>
7373
</div>

0 commit comments

Comments
 (0)