-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify Polling and make the background instantly available #26
Open
ad-chaos
wants to merge
1
commit into
main
Choose a base branch
from
simplify
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+87
−98
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export async function load({ fetch, depends }) { | ||
depends("leaderboard"); | ||
let leaderboard = await fetch( | ||
`https://hacknight.navinshrinivas.com/leaderboard_mat` | ||
) | ||
.then((response) => response.json()) | ||
.then((leaderboard) => | ||
leaderboard.sort((a, b) => b.Current_bounty - a.Current_bounty) | ||
) | ||
.catch((e) => { | ||
throw new Error(e.status, "Reddy Anna Is Not Talking"); | ||
}); | ||
|
||
return { | ||
leaderboard | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,48 +3,28 @@ | |
import Card from "./Card.svelte"; | ||
import CardRow from "./CardRow.svelte"; | ||
import { onMount } from "svelte"; | ||
let innerWidth = 0; | ||
import { invalidate } from "$app/navigation"; | ||
|
||
let leaderboard; | ||
let oldLeaderboard = []; | ||
const fetchLeaderboardData = async () => { | ||
try { | ||
const response = await fetch( | ||
"https://hacknight.navinshrinivas.com/leaderboard_mat" | ||
); | ||
if (!response.ok) { | ||
throw new Error("Reddy Anna Is Not Talking"); | ||
} else { | ||
let json_response = await response.json(); | ||
export let data; | ||
let innerWidth = 0; | ||
|
||
json_response.sort((a, b) => b.Current_bounty - a.Current_bounty); | ||
if (JSON.stringify(json_response) != JSON.stringify(oldLeaderboard)) { | ||
leaderboard = json_response; | ||
oldLeaderboard = leaderboard; | ||
} | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}; | ||
let leaderboard = {}; | ||
|
||
leaderboard = fetchLeaderboardData(); | ||
$: if (JSON.stringify(leaderboard) !== JSON.stringify(data.leaderboard)) { | ||
leaderboard = data.leaderboard; | ||
} | ||
|
||
onMount(() => { | ||
setInterval(async () => { | ||
await fetchLeaderboardData(); | ||
setInterval(() => { | ||
invalidate("leaderboard"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Polling doesn't work on local for me. Have you verified this works? |
||
}, 5000); | ||
}); | ||
</script> | ||
|
||
<svelte:window bind:innerWidth /> | ||
|
||
<main> | ||
{#key leaderboard} | ||
{#await leaderboard then} | ||
<Background info={leaderboard} /> | ||
{/await} | ||
{/key} | ||
<Background info={leaderboard} /> | ||
|
||
<div | ||
class="flex flex-col h-[75vh] md:h-[80vh] lg:h-[100vh] justify-between mb-10" | ||
|
@@ -78,78 +58,72 @@ | |
</div> | ||
</div> | ||
|
||
{#key leaderboard} | ||
{#await leaderboard} | ||
<div class="text-center">loading...</div> | ||
{:then} | ||
<div | ||
class="leaderboard-background rounded-xl bg-[#0F0913] m-4 lg:m-10 p-5 flex flex-col justify-stretch items-center" | ||
> | ||
{#if innerWidth <= 672} | ||
{#each leaderboard as person, i} | ||
<Card | ||
index={i + 1} | ||
username={person.Name} | ||
points={person.Current_bounty} | ||
/> | ||
{/each} | ||
{:else} | ||
{#if innerWidth >= 1440} | ||
<CardRow | ||
index={1} | ||
username={leaderboard[0].Name} | ||
points={leaderboard[0].Current_bounty} | ||
/> | ||
{:else} | ||
<Card | ||
index={1} | ||
username={leaderboard[0].Name} | ||
points={leaderboard[0].Current_bounty} | ||
/> | ||
{/if} | ||
<div | ||
class="leaderboard-background rounded-xl bg-[#0F0913] m-4 lg:m-10 p-5 flex flex-col justify-stretch items-center" | ||
class="grid-wrapper2-3 grid grid-cols-2 items-stretch justify-stretch" | ||
> | ||
{#if innerWidth <= 672} | ||
{#each leaderboard as person, i} | ||
{#if innerWidth >= 1440} | ||
<CardRow | ||
index={2} | ||
username={leaderboard[1].Name} | ||
points={leaderboard[1].Current_bounty} | ||
/> | ||
<CardRow | ||
index={3} | ||
username={leaderboard[2].Name} | ||
points={leaderboard[2].Current_bounty} | ||
/> | ||
{:else} | ||
<Card | ||
index={2} | ||
username={leaderboard[1].Name} | ||
points={leaderboard[1].Current_bounty} | ||
/> | ||
<Card | ||
index={3} | ||
username={leaderboard[2].Name} | ||
points={leaderboard[2].Current_bounty} | ||
/> | ||
{/if} | ||
</div> | ||
|
||
<div class="grid-peeps grid justify-stretch items-center w-full"> | ||
{#each leaderboard as person, i} | ||
{#if ![0, 1, 2].includes(i)} | ||
<Card | ||
index={i + 1} | ||
username={person.Name} | ||
points={person.Current_bounty} | ||
/> | ||
{/each} | ||
{:else} | ||
{#if innerWidth >= 1440} | ||
<CardRow | ||
index={1} | ||
username={leaderboard[0].Name} | ||
points={leaderboard[0].Current_bounty} | ||
/> | ||
{:else} | ||
<Card | ||
index={1} | ||
username={leaderboard[0].Name} | ||
points={leaderboard[0].Current_bounty} | ||
/> | ||
{/if} | ||
<div | ||
class="grid-wrapper2-3 grid grid-cols-2 items-stretch justify-stretch" | ||
> | ||
{#if innerWidth >= 1440} | ||
<CardRow | ||
index={2} | ||
username={leaderboard[1].Name} | ||
points={leaderboard[1].Current_bounty} | ||
/> | ||
<CardRow | ||
index={3} | ||
username={leaderboard[2].Name} | ||
points={leaderboard[2].Current_bounty} | ||
/> | ||
{:else} | ||
<Card | ||
index={2} | ||
username={leaderboard[1].Name} | ||
points={leaderboard[1].Current_bounty} | ||
/> | ||
<Card | ||
index={3} | ||
username={leaderboard[2].Name} | ||
points={leaderboard[2].Current_bounty} | ||
/> | ||
{/if} | ||
</div> | ||
|
||
<div class="grid-peeps grid justify-stretch items-center w-full"> | ||
{#each leaderboard as person, i} | ||
{#if ![0, 1, 2].includes(i)} | ||
<Card | ||
index={i + 1} | ||
username={person.Name} | ||
points={person.Current_bounty} | ||
/> | ||
{/if} | ||
{/each} | ||
</div> | ||
{/if} | ||
{/each} | ||
</div> | ||
{/await} | ||
{/key} | ||
{/if} | ||
</div> | ||
</main> | ||
|
||
<style> | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
let user_details; | ||
|
||
export async function load({ params, fetch }) { | ||
let username = params.slug; | ||
try { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add
leaderboard.sort((a, b) => b.Current_bounty - a.Current_bounty)
here. The leaderboard isn't sorted from backend