-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path+page.svelte
124 lines (109 loc) · 2.76 KB
/
+page.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<script lang='ts'>
import { page } from '$app/stores';
import GuildInfo from '$components/index/GuildInfo.svelte';
import User from '$components/index/User.svelte';
import { onMount } from 'svelte';
import { env } from '$env/dynamic/public';
let guild: any;
let user: any = $page.data.user;
let guildId = $page.params.guildId;
let members: any = [];
let index: any = 0;
let newBatch: never[] = [];
let hasMore = true;
async function fetchData() {
if (hasMore) {
let data = await fetch(`${env.PUBLIC_STATCORD_API_URL}/guilds/${guildId}?page=${index}`, {
method: 'GET'
});
if (data.status == 200) {
const json = await data.json();
newBatch = json.members;
guild = json.guild;
index++;
if (newBatch.length < 100) {
hasMore = false;
}
}
}
}
let Member = new Promise(() => {});
onMount(async () => {
Member = import('/src/components/leaderboard/Member.svelte');
await fetchData();
});
let innerHeight = 0;
let scroll = 0;
function infiniteScroll() {
if (scroll / innerHeight >= 1) {
fetchData();
}
console.log('innerHeight', innerHeight);
console.log('scroll', scroll);
}
$: members = [...members, ...newBatch];
</script>
<svelte:window on:scrollend={infiniteScroll} bind:outerHeight={innerHeight} bind:scrollY={scroll} />
<svelte:head>
{#if guild}
<meta property='og:title' content="Statcord | {guild.name}'s Leaderboard" />
<title>Statcord | {guild.name}'s Leaderboard</title>
{/if}
</svelte:head>
<User {user} />
<div class='holder'>
{#if guildId}
<div class='info'>
<GuildInfo {user} />
</div>
{/if}
<div class='card leaderboard'>
{#if members.length != 0}
{#each members as { pos, name, id, texthistory, voicehistory, textmessages, voiceseconds, avatar }}
{#await Member then module}
<svelte:component this={module.default}
{pos}
{id}
{texthistory}
{voicehistory}
score={textmessages / guild.values.msgsperpoint + voiceseconds / guild.values.vcsecondsperpoint}
{name}
{avatar}
/>
{/await}
{/each}
<!--{#if hasMore}
<Button on:click={fetchData}>Load more</Button>
{/if}-->
{:else}
<p class='loading'>Please wait, data is loading...</p>
{/if}
</div>
</div>
<style lang='scss'>
.holder {
display: grid;
grid-template-columns: 3fr 1fr;
grid-template-areas: 'board info';
gap: 2vw;
margin: 10vh 2vw 2vw;
min-height: 90vh;
.leaderboard {
display: flex;
flex-direction: column;
gap: 1vh;
width: 100%;
grid-area: board;
}
.info {
width: 100%;
grid-area: info;
}
}
@media only screen and (max-width: 500px) {
.holder {
display: flex;
flex-direction: column;
}
}
</style>