From 2e8fa844ae3a78f32d47fc42b6c9a175690657d1 Mon Sep 17 00:00:00 2001 From: Daniils Petrovs Date: Sun, 23 Jun 2024 12:10:10 +0200 Subject: [PATCH] Fix build --- src/legacy-client.ts | 103 ----------------------- src/lib/components/LeaderboardRow.svelte | 2 +- src/routes/debug/+page.svelte | 2 +- src/routes/leaderboard/+page.svelte | 43 ---------- src/routes/leaderboard/+page.ts | 17 ---- 5 files changed, 2 insertions(+), 165 deletions(-) delete mode 100644 src/legacy-client.ts delete mode 100644 src/routes/leaderboard/+page.svelte delete mode 100644 src/routes/leaderboard/+page.ts diff --git a/src/legacy-client.ts b/src/legacy-client.ts deleted file mode 100644 index 73da239..0000000 --- a/src/legacy-client.ts +++ /dev/null @@ -1,103 +0,0 @@ -import type { Channel } from 'phoenix'; -import { get } from 'svelte/store'; -import { apiServerURL } from './const'; -import type { LeaderboardResponse, RegisterUserResponse, SetNicknameResponse } from './custom'; -import { nickname, notificationsChannel } from './store'; - -const apiToken = import.meta.env.VITE_HOLOQUEST_API_TOKEN; - -const defaultHeaders = { - Accept: 'application/vnd.api+json', - 'Content-Type': 'application/vnd.api+json', - Authorization: `Bearer ${apiToken}` -}; - -/** - * Registers a new user on the server. - * @returns {Promise} JSON-API response containing an ID as a UUIDv4. - */ -export async function registerUser(nickname = ''): Promise { - const response = await fetch(`${apiServerURL}/accounts/users/`, { - method: 'POST', - headers: defaultHeaders, - body: `{"data":{"type":"user","attributes":{"nickname":"${nickname}"}}}` - }); - const json = await response.json(); - return json; -} - -/** - * Sets the nickname of a user. - * @param {string} userId The ID of the user to set the nickname of. Must be a UUIDv4. - * @param {string} nickname The nickname to set. - * @returns {Promise} A promise that resolves when the request is complete. - */ -export async function setNickname(userId: string, nickname: string): Promise { - const response = await fetch(`${apiServerURL}/accounts/users/${userId}`, { - method: 'PATCH', - headers: defaultHeaders, - body: `{"data":{"type":"user","attributes":{"nickname":"${nickname}"}}}` - }); - const json = await response.json(); - return json; -} - -/** - * Fetches the leaderboard from the server. - * @returns {Promise} JSON-API response containing the leaderboard. - * @example - * const leaderboard = await fetchLeaderboard(); - * console.log(leaderboard); // { data: [{ id: '...', type: 'user', attributes: { nickname: '...', stamps_collected: 0 } }] } - * console.log(leaderboard.data[0].attributes.nickname); // "Cruel_KFP" - * console.log(leaderboard.data[0].attributes.stamps_collected); // 0 - */ -export async function fetchLeaderboard(): Promise { - const response = await fetch(`${apiServerURL}/leaderboard`, { - method: 'GET', - headers: defaultHeaders - }); - const json = await response.json(); - return json; -} - -export async function updateScore(userId: string, score: number): Promise { - const response = await fetch(`${apiServerURL}/accounts/users/${userId}`, { - method: 'PATCH', - headers: defaultHeaders, - body: `{"data":{"type":"user","attributes":{"stamps_collected":${score}}}}` - }); - const json = await response.json(); - return json; -} - -export class ChannelsClient { - nickname = get(nickname); - channel: Channel | null; - - constructor(channel: Channel) { - this.channel = channel; - nickname.subscribe((value) => { - this.nickname = value; - }); - notificationsChannel.subscribe((value) => { - this.channel = value; - }); - } - - /** - * Pushes a message to the channel - * @param {string} message Message to send to the server - */ - pushMessage(message: string) { - this.channel?.push('message', { nickname: this.nickname, message }); - } - - // Pushes a 'collected' message to the channel - pushCollected() { - this.channel?.push('collected', { nickname: this.nickname }); - } - - pushRallyCompleted() { - this.channel?.push('rally-completed', { nickname: this.nickname }); - } -} diff --git a/src/lib/components/LeaderboardRow.svelte b/src/lib/components/LeaderboardRow.svelte index da2fa42..48af31e 100644 --- a/src/lib/components/LeaderboardRow.svelte +++ b/src/lib/components/LeaderboardRow.svelte @@ -1,5 +1,5 @@ - -
-

Leaderboard

-

{lastUpdatedFormatted()}

- - - {#each leaderboard as { nickname, stamps_collected }, i} - - {/each} - -
-
diff --git a/src/routes/leaderboard/+page.ts b/src/routes/leaderboard/+page.ts deleted file mode 100644 index c315ee3..0000000 --- a/src/routes/leaderboard/+page.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { fetchLeaderboard } from '../../legacy-client'; -import type { PageLoad } from './$types'; - -export const load = (async () => { - try { - const leaderboard = await fetchLeaderboard(); - - const filteredLeaderboard = leaderboard.data - .filter((user) => user.nickname !== null) - .sort((a, b) => b.stamps_collected - a.stamps_collected); - - return { leaderboard: filteredLeaderboard }; - } catch (error) { - console.error(error); - return { leaderboard: [] }; - } -}) satisfies PageLoad;