cleanup and remove web worker tests
All checks were successful
Deploy SSR / deploy (push) Successful in 1m16s
All checks were successful
Deploy SSR / deploy (push) Successful in 1m16s
This commit is contained in:
parent
bc2ddfa3a3
commit
37e2b305ff
@ -1,5 +1,5 @@
|
||||
import { scoresaberFetcher } from "@/common/data-fetcher/impl/scoresaber";
|
||||
import { ScoreSort } from "@/common/data-fetcher/sort";
|
||||
import { scoresaberService } from "@/common/service/impl/scoresaber";
|
||||
import { ScoreSort } from "@/common/service/score-sort";
|
||||
import { formatNumberWithCommas } from "@/common/number-utils";
|
||||
import PlayerData from "@/components/player/player-data";
|
||||
import { format } from "@formkit/tempo";
|
||||
@ -16,7 +16,7 @@ export async function generateMetadata({
|
||||
params: { slug },
|
||||
}: Props): Promise<Metadata> {
|
||||
const id = slug[0]; // The players id
|
||||
const player = await scoresaberFetcher.lookupPlayer(id, false);
|
||||
const player = await scoresaberService.lookupPlayer(id, false);
|
||||
if (player === undefined) {
|
||||
return {
|
||||
title: `Unknown Player`,
|
||||
@ -44,8 +44,8 @@ export default async function Search({ params: { slug } }: Props) {
|
||||
const id = slug[0]; // The players id
|
||||
const sort: ScoreSort = (slug[1] as ScoreSort) || "recent"; // The sorting method
|
||||
const page = parseInt(slug[2]) || 1; // The page number
|
||||
const player = await scoresaberFetcher.lookupPlayer(id, false);
|
||||
const scores = await scoresaberFetcher.lookupPlayerScores({
|
||||
const player = await scoresaberService.lookupPlayer(id, false);
|
||||
const scores = await scoresaberService.lookupPlayerScores({
|
||||
playerId: id,
|
||||
sort,
|
||||
page,
|
||||
|
@ -6,3 +6,13 @@
|
||||
export function copyToClipboard(str: string) {
|
||||
navigator.clipboard.writeText(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current context is a worker
|
||||
*/
|
||||
export function isRunningAsWorker() {
|
||||
if (typeof window === "undefined") {
|
||||
return false;
|
||||
}
|
||||
return navigator.constructor.name === "WorkerNavigator";
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { BeatSaverMap as BSMap } from "@/common/data-fetcher/types/beatsaver/beatsaver-map";
|
||||
import { BeatSaverMap as BSMap } from "@/common/service/types/beatsaver/beatsaver-map";
|
||||
import { Entity } from "dexie";
|
||||
import Database from "../database";
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import ScoreSaberPlayer from "@/common/data-fetcher/types/scoresaber/scoresaber-player";
|
||||
import { scoresaberFetcher } from "@/common/data-fetcher/impl/scoresaber";
|
||||
import { ScoreSort } from "@/common/data-fetcher/sort";
|
||||
import ScoreSaberPlayer from "@/common/service/types/scoresaber/scoresaber-player";
|
||||
import { scoresaberService } from "@/common/service/impl/scoresaber";
|
||||
import { ScoreSort } from "@/common/service/score-sort";
|
||||
|
||||
export const leaderboards = {
|
||||
ScoreSaber: {
|
||||
@ -9,7 +9,7 @@ export const leaderboards = {
|
||||
},
|
||||
queries: {
|
||||
lookupScores: (player: ScoreSaberPlayer, sort: ScoreSort, page: number) =>
|
||||
scoresaberFetcher.lookupPlayerScores({
|
||||
scoresaberService.lookupPlayerScores({
|
||||
playerId: player.id,
|
||||
sort: sort,
|
||||
page: page,
|
||||
|
@ -1,12 +1,12 @@
|
||||
import BeatSaverMap from "@/common/database/types/beatsaver-map";
|
||||
import { db } from "../../database/database";
|
||||
import DataFetcher from "../data-fetcher";
|
||||
import Service from "../service";
|
||||
import { BeatSaverMap as BSMap } from "../types/beatsaver/beatsaver-map";
|
||||
|
||||
const API_BASE = "https://api.beatsaver.com";
|
||||
const LOOKUP_MAP_BY_HASH_ENDPOINT = `${API_BASE}/maps/hash/:query`;
|
||||
|
||||
class BeatSaverFetcher extends DataFetcher {
|
||||
class BeatSaverService extends Service {
|
||||
constructor() {
|
||||
super("BeatSaver");
|
||||
}
|
||||
@ -62,4 +62,4 @@ class BeatSaverFetcher extends DataFetcher {
|
||||
}
|
||||
}
|
||||
|
||||
export const beatsaverFetcher = new BeatSaverFetcher();
|
||||
export const beatsaverService = new BeatSaverService();
|
@ -1,5 +1,5 @@
|
||||
import DataFetcher from "../data-fetcher";
|
||||
import { ScoreSort } from "../sort";
|
||||
import Service from "../service";
|
||||
import { ScoreSort } from "../score-sort";
|
||||
import ScoreSaberLeaderboardScoresPage from "../types/scoresaber/scoresaber-leaderboard-scores-page";
|
||||
import ScoreSaberPlayer from "../types/scoresaber/scoresaber-player";
|
||||
import ScoreSaberPlayerScoresPage from "../types/scoresaber/scoresaber-player-scores-page";
|
||||
@ -11,7 +11,7 @@ const LOOKUP_PLAYER_ENDPOINT = `${API_BASE}/player/:id/full`;
|
||||
const LOOKUP_PLAYER_SCORES_ENDPOINT = `${API_BASE}/player/:id/scores?limit=:limit&sort=:sort&page=:page`;
|
||||
const LOOKUP_LEADERBOARD_SCORES_ENDPOINT = `${API_BASE}/leaderboard/by-id/:id/scores?page=:page`;
|
||||
|
||||
class ScoreSaberFetcher extends DataFetcher {
|
||||
class ScoreSaberService extends Service {
|
||||
constructor() {
|
||||
super("ScoreSaber");
|
||||
}
|
||||
@ -110,7 +110,7 @@ class ScoreSaberFetcher extends DataFetcher {
|
||||
return undefined;
|
||||
}
|
||||
this.log(
|
||||
`Found scores for player "${playerId}" in ${(performance.now() - before).toFixed(0)}ms`,
|
||||
`Found ${response.playerScores.length} scores for player "${playerId}" in ${(performance.now() - before).toFixed(0)}ms`,
|
||||
);
|
||||
return response;
|
||||
}
|
||||
@ -144,10 +144,10 @@ class ScoreSaberFetcher extends DataFetcher {
|
||||
return undefined;
|
||||
}
|
||||
this.log(
|
||||
`Found scores for leaderboard "${leaderboardId}" in ${(performance.now() - before).toFixed(0)}ms`,
|
||||
`Found ${response.scores.length} scores for leaderboard "${leaderboardId}" in ${(performance.now() - before).toFixed(0)}ms`,
|
||||
);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
export const scoresaberFetcher = new ScoreSaberFetcher();
|
||||
export const scoresaberService = new ScoreSaberService();
|
@ -1,8 +1,9 @@
|
||||
import ky from "ky";
|
||||
import { isRunningAsWorker } from "@/common/browser-utils";
|
||||
|
||||
export default class DataFetcher {
|
||||
export default class Service {
|
||||
/**
|
||||
* The name of the leaderboard.
|
||||
* The name of the service.
|
||||
*/
|
||||
private name: string;
|
||||
|
||||
@ -16,7 +17,9 @@ export default class DataFetcher {
|
||||
* @param data the data to log
|
||||
*/
|
||||
public log(data: unknown) {
|
||||
console.debug(`[${this.name}]: ${data}`);
|
||||
console.log(
|
||||
`[${isRunningAsWorker() ? "Worker - " : ""}${this.name}]: ${data}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
@ -1,16 +1,16 @@
|
||||
import * as Comlink from "comlink";
|
||||
import { scoresaberFetcher } from "@/common/data-fetcher/impl/scoresaber";
|
||||
import { scoresaberService } from "@/common/service/impl/scoresaber";
|
||||
|
||||
export interface WorkerApi {
|
||||
getName: typeof getName;
|
||||
getPlayerExample: typeof getPlayerExample;
|
||||
}
|
||||
|
||||
const workerApi: WorkerApi = {
|
||||
getName,
|
||||
getPlayerExample: getPlayerExample,
|
||||
};
|
||||
|
||||
async function getName() {
|
||||
return await scoresaberFetcher.lookupPlayer("76561198449412074");
|
||||
async function getPlayerExample() {
|
||||
return await scoresaberService.lookupPlayer("76561198449412074");
|
||||
}
|
||||
|
||||
Comlink.expose(workerApi);
|
||||
|
@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { scoresaberFetcher } from "@/common/data-fetcher/impl/scoresaber";
|
||||
import ScoreSaberPlayer from "@/common/data-fetcher/types/scoresaber/scoresaber-player";
|
||||
import { scoresaberService } from "@/common/service/impl/scoresaber";
|
||||
import ScoreSaberPlayer from "@/common/service/types/scoresaber/scoresaber-player";
|
||||
import { formatNumberWithCommas } from "@/common/number-utils";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import Link from "next/link";
|
||||
@ -31,7 +31,7 @@ export default function SearchPlayer() {
|
||||
async function onSubmit({ username }: z.infer<typeof formSchema>) {
|
||||
setLoading(true);
|
||||
setResults(undefined); // Reset results
|
||||
const results = await scoresaberFetcher.searchPlayers(username);
|
||||
const results = await scoresaberService.searchPlayers(username);
|
||||
setResults(results?.players);
|
||||
setLoading(false);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import ScoreSaberScore from "@/common/data-fetcher/types/scoresaber/scoresaber-score";
|
||||
import ScoreSaberScore from "@/common/service/types/scoresaber/scoresaber-score";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import ScoreSaberLeaderboard from "@/common/data-fetcher/types/scoresaber/scoresaber-leaderboard";
|
||||
import ScoreSaberScore from "@/common/data-fetcher/types/scoresaber/scoresaber-score";
|
||||
import ScoreSaberLeaderboard from "@/common/service/types/scoresaber/scoresaber-leaderboard";
|
||||
import ScoreSaberScore from "@/common/service/types/scoresaber/scoresaber-score";
|
||||
import { formatNumberWithCommas } from "@/common/number-utils";
|
||||
import StatValue from "@/components/stat-value";
|
||||
import { XMarkIcon } from "@heroicons/react/24/solid";
|
||||
|
@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import ScoreSaberLeaderboard from "@/common/data-fetcher/types/scoresaber/scoresaber-leaderboard";
|
||||
import ScoreSaberScore from "@/common/data-fetcher/types/scoresaber/scoresaber-score";
|
||||
import ScoreSaberLeaderboard from "@/common/service/types/scoresaber/scoresaber-leaderboard";
|
||||
import ScoreSaberScore from "@/common/service/types/scoresaber/scoresaber-score";
|
||||
import ScoreRankInfo from "../player/score/score-rank-info";
|
||||
import LeaderboardPlayer from "./leaderboard-player";
|
||||
import LeaderboardScoreStats from "./leaderboard-score-stats";
|
||||
|
@ -1,8 +1,8 @@
|
||||
"use client";
|
||||
|
||||
import { scoresaberFetcher } from "@/common/data-fetcher/impl/scoresaber";
|
||||
import ScoreSaberLeaderboard from "@/common/data-fetcher/types/scoresaber/scoresaber-leaderboard";
|
||||
import ScoreSaberLeaderboardScoresPage from "@/common/data-fetcher/types/scoresaber/scoresaber-leaderboard-scores-page";
|
||||
import { scoresaberService } from "@/common/service/impl/scoresaber";
|
||||
import ScoreSaberLeaderboard from "@/common/service/types/scoresaber/scoresaber-leaderboard";
|
||||
import ScoreSaberLeaderboardScoresPage from "@/common/service/types/scoresaber/scoresaber-leaderboard-scores-page";
|
||||
import useWindowDimensions from "@/hooks/use-window-dimensions";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { motion } from "framer-motion";
|
||||
@ -31,7 +31,7 @@ export default function LeaderboardScores({ leaderboard }: Props) {
|
||||
} = useQuery({
|
||||
queryKey: ["playerScores", leaderboard.id, currentPage],
|
||||
queryFn: () =>
|
||||
scoresaberFetcher.lookupLeaderboardScores(
|
||||
scoresaberService.lookupLeaderboardScores(
|
||||
leaderboard.id + "",
|
||||
currentPage,
|
||||
),
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
import { CheckIcon } from "@heroicons/react/24/solid";
|
||||
import { useLiveQuery } from "dexie-react-hooks";
|
||||
import { setPlayerIdCookie } from "../../common/website-utils";
|
||||
import { setPlayerIdCookie } from "@/common/website-utils";
|
||||
import useDatabase from "../../hooks/use-database";
|
||||
import { useToast } from "../../hooks/use-toast";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import Tooltip from "../tooltip";
|
||||
import { Button } from "../ui/button";
|
||||
|
||||
|
@ -1,15 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { scoresaberFetcher } from "@/common/data-fetcher/impl/scoresaber";
|
||||
import { ScoreSort } from "@/common/data-fetcher/sort";
|
||||
import ScoreSaberPlayer from "@/common/data-fetcher/types/scoresaber/scoresaber-player";
|
||||
import ScoreSaberPlayerScoresPage from "@/common/data-fetcher/types/scoresaber/scoresaber-player-scores-page";
|
||||
import { scoresaberService } from "@/common/service/impl/scoresaber";
|
||||
import { ScoreSort } from "@/common/service/score-sort";
|
||||
import ScoreSaberPlayer from "@/common/service/types/scoresaber/scoresaber-player";
|
||||
import ScoreSaberPlayerScoresPage from "@/common/service/types/scoresaber/scoresaber-player-scores-page";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import PlayerHeader from "./player-header";
|
||||
import PlayerRankChart from "./player-rank-chart";
|
||||
import PlayerScores from "./player-scores";
|
||||
import { useEffect } from "react";
|
||||
import { scoresaberReloadedWorker } from "@/common/workers/workers";
|
||||
|
||||
const REFRESH_INTERVAL = 5 * 60 * 1000; // 5 minutes
|
||||
|
||||
@ -29,17 +27,10 @@ export default function PlayerData({
|
||||
let player = initalPlayerData;
|
||||
const { data, isLoading, isError } = useQuery({
|
||||
queryKey: ["player", player.id],
|
||||
queryFn: () => scoresaberFetcher.lookupPlayer(player.id),
|
||||
queryFn: () => scoresaberService.lookupPlayer(player.id),
|
||||
refetchInterval: REFRESH_INTERVAL,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const worker = scoresaberReloadedWorker();
|
||||
console.log(await worker.getName());
|
||||
})();
|
||||
}, []);
|
||||
|
||||
if (data && (!isLoading || !isError)) {
|
||||
player = data;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import ScoreSaberPlayer from "@/common/data-fetcher/types/scoresaber/scoresaber-player";
|
||||
import ScoreSaberPlayer from "@/common/service/types/scoresaber/scoresaber-player";
|
||||
import { formatNumberWithCommas } from "@/common/number-utils";
|
||||
import { GlobeAmericasIcon } from "@heroicons/react/24/solid";
|
||||
import Card from "../card";
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
"use client";
|
||||
|
||||
import ScoreSaberPlayer from "@/common/data-fetcher/types/scoresaber/scoresaber-player";
|
||||
import ScoreSaberPlayer from "@/common/service/types/scoresaber/scoresaber-player";
|
||||
import { formatNumberWithCommas } from "@/common/number-utils";
|
||||
import {
|
||||
CategoryScale,
|
||||
|
@ -1,8 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { ScoreSort } from "@/common/data-fetcher/sort";
|
||||
import ScoreSaberPlayer from "@/common/data-fetcher/types/scoresaber/scoresaber-player";
|
||||
import ScoreSaberPlayerScoresPage from "@/common/data-fetcher/types/scoresaber/scoresaber-player-scores-page";
|
||||
import { capitalizeFirstLetter } from "@/common/string-utils";
|
||||
import useWindowDimensions from "@/hooks/use-window-dimensions";
|
||||
import { ClockIcon, TrophyIcon } from "@heroicons/react/24/solid";
|
||||
@ -14,6 +11,9 @@ import Pagination from "../input/pagination";
|
||||
import { Button } from "../ui/button";
|
||||
import Score from "./score/score";
|
||||
import { leaderboards } from "@/common/leaderboards";
|
||||
import { ScoreSort } from "@/common/service/score-sort";
|
||||
import ScoreSaberPlayer from "@/common/service/types/scoresaber/scoresaber-player";
|
||||
import ScoreSaberPlayerScoresPage from "@/common/service/types/scoresaber/scoresaber-player-scores-page";
|
||||
|
||||
type Props = {
|
||||
initialScoreData?: ScoreSaberPlayerScoresPage;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import ScoreSaberPlayer from "@/common/data-fetcher/types/scoresaber/scoresaber-player";
|
||||
import { formatNumberWithCommas } from "@/common/number-utils";
|
||||
import StatValue from "@/components/stat-value";
|
||||
import ScoreSaberPlayer from "@/common/service/types/scoresaber/scoresaber-player";
|
||||
|
||||
type Badge = {
|
||||
name: string;
|
||||
|
@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { copyToClipboard } from "@/common/browser-utils";
|
||||
import ScoreSaberPlayerScore from "@/common/data-fetcher/types/scoresaber/scoresaber-player-score";
|
||||
import ScoreSaberPlayerScore from "@/common/service/types/scoresaber/scoresaber-player-score";
|
||||
import BeatSaverMap from "@/common/database/types/beatsaver-map";
|
||||
import { songNameToYouTubeLink } from "@/common/youtube-utils";
|
||||
import BeatSaverLogo from "@/components/logos/beatsaver-logo";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import ScoreSaberLeaderboard from "@/common/data-fetcher/types/scoresaber/scoresaber-leaderboard";
|
||||
import ScoreSaberLeaderboard from "@/common/service/types/scoresaber/scoresaber-leaderboard";
|
||||
import BeatSaverMap from "@/common/database/types/beatsaver-map";
|
||||
import { getDifficultyFromScoreSaberDifficulty } from "@/common/scoresaber-utils";
|
||||
import { songDifficultyToColor } from "@/common/song-utils";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import ScoreSaberScore from "@/common/data-fetcher/types/scoresaber/scoresaber-score";
|
||||
import ScoreSaberScore from "@/common/service/types/scoresaber/scoresaber-score";
|
||||
import { formatNumberWithCommas } from "@/common/number-utils";
|
||||
import { timeAgo } from "@/common/time-utils";
|
||||
import { GlobeAmericasIcon } from "@heroicons/react/24/solid";
|
||||
|
@ -1,5 +1,5 @@
|
||||
import ScoreSaberLeaderboard from "@/common/data-fetcher/types/scoresaber/scoresaber-leaderboard";
|
||||
import ScoreSaberScore from "@/common/data-fetcher/types/scoresaber/scoresaber-score";
|
||||
import ScoreSaberLeaderboard from "@/common/service/types/scoresaber/scoresaber-leaderboard";
|
||||
import ScoreSaberScore from "@/common/service/types/scoresaber/scoresaber-score";
|
||||
import { formatNumberWithCommas } from "@/common/number-utils";
|
||||
import StatValue from "@/components/stat-value";
|
||||
import { XMarkIcon } from "@heroicons/react/24/solid";
|
||||
|
@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { beatsaverFetcher } from "@/common/data-fetcher/impl/beatsaver";
|
||||
import ScoreSaberPlayerScore from "@/common/data-fetcher/types/scoresaber/scoresaber-player-score";
|
||||
import { beatsaverService } from "@/common/service/impl/beatsaver";
|
||||
import ScoreSaberPlayerScore from "@/common/service/types/scoresaber/scoresaber-player-score";
|
||||
import BeatSaverMap from "@/common/database/types/beatsaver-map";
|
||||
import LeaderboardScores from "@/components/leaderboard/leaderboard-scores";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
@ -23,7 +23,7 @@ export default function Score({ playerScore }: Props) {
|
||||
const [isLeaderboardExpanded, setIsLeaderboardExpanded] = useState(false);
|
||||
|
||||
const fetchBeatSaverData = useCallback(async () => {
|
||||
const beatSaverMap = await beatsaverFetcher.lookupMap(leaderboard.songHash);
|
||||
const beatSaverMap = await beatsaverService.lookupMap(leaderboard.songHash);
|
||||
setBeatSaverMap(beatSaverMap);
|
||||
}, [leaderboard.songHash]);
|
||||
|
||||
|
Reference in New Issue
Block a user