Skip to content

Commit

Permalink
bunch of simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-chaos committed Oct 9, 2023
1 parent 47eea1c commit 1e4796b
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 115 deletions.
14 changes: 14 additions & 0 deletions src/routes/+page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export async function load({ fetch, depends }) {
depends("leaderboard");
const leaderboard = await fetch(
`https://hacknight.navinshrinivas.com/leaderboard_mat`
)
.then((response) => response.json())
.catch((e) => {
throw new Error(e.status, "Reddy Anna Is Not Talking");
});

return {
leaderboard
};
}
156 changes: 64 additions & 92 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,16 @@
import Card from "./Card.svelte";
import CardRow from "./CardRow.svelte";
import { onMount } from "svelte";
let innerWidth = 0;
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();
import { invalidate } from "$app/navigation";
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);
}
};
export let data;
let innerWidth = 0;
leaderboard = fetchLeaderboardData();
let leaderboard = data.leaderboard;
onMount(() => {
setInterval(async () => {
await fetchLeaderboardData();
setInterval(() => {
invalidate("leaderboard");
}, 5000);
});
</script>
Expand All @@ -41,9 +21,7 @@

<main>
{#key leaderboard}
{#await leaderboard then}
<Background info={leaderboard} />
{/await}
<Background info={leaderboard} />
{/key}

<div
Expand Down Expand Up @@ -78,78 +56,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>
Expand Down
6 changes: 3 additions & 3 deletions src/routes/Background.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script>
export let info = [
{
Name: "Navin Shrinivas",
Current_bounty: 100
Name: "Navin uWu",
Current_bounty: 27
}
];
export let maintainer = false;
Expand Down Expand Up @@ -59,7 +59,7 @@

<main class="unselect">
<div class="text-4xl font-extrabold text-center" disabled>
<span class="chunk" bind:this={infoChunk}
<span bind:this={infoChunk}
>{#each binified as [name, value]}{name}<span class="gradient"
>{value}</span
>{/each}</span
Expand Down
30 changes: 11 additions & 19 deletions src/routes/[slug]/+page.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
let user_details;

export async function load({ params, fetch }) {
let username = params.slug;
console.log(username);
try {
const response = await fetch(
`http://smaran.ddns.net:3000/records?user=${username}`
);
if (!response.ok) {
throw new Error(response.status, "Reddy Anna Is Not Talking");
} else {
user_details = await response.json();
console.log(user_details);
return {
user_details
};
}
} catch (err) {
console.log(err);
}
const userDetails = await fetch(
`https://hacknight.navinshrinivas.com/records?user=${username}`
)
.then((response) => response.json())
.catch((e) => {
throw new Error(e.status, "Reddy Anna Is Not Talking");
});

return {
userDetails
};
}
2 changes: 1 addition & 1 deletion src/routes/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Background from "../Background.svelte";
export let data;
let user_details = data.user_details;
let user_details = data.userDetails;
</script>

<main>
Expand Down

0 comments on commit 1e4796b

Please sign in to comment.