cleanup and track friends data (if not being already tracked)
This commit is contained in:
@ -3,9 +3,9 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { getApiHealth } from "@ssr/common/utils/api-utils";
|
||||
import { config } from "../../../config";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { useIsFirstRender } from "@uidotdev/usehooks";
|
||||
import { Config } from "@ssr/common/config";
|
||||
|
||||
export function ApiHealth() {
|
||||
const { toast } = useToast();
|
||||
@ -16,7 +16,7 @@ export function ApiHealth() {
|
||||
useQuery({
|
||||
queryKey: ["api-health"],
|
||||
queryFn: async () => {
|
||||
const status = (await getApiHealth(config.siteApi + "/health")).online;
|
||||
const status = (await getApiHealth(Config.apiUrl + "/health")).online;
|
||||
setOnline(status);
|
||||
return status;
|
||||
},
|
||||
|
@ -1,9 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import { useLiveQuery } from "dexie-react-hooks";
|
||||
import { config } from "../../config";
|
||||
import { getImageUrl } from "@/common/image-utils";
|
||||
import useDatabase from "../hooks/use-database";
|
||||
import { Config } from "@ssr/common/config";
|
||||
|
||||
export default function BackgroundCover() {
|
||||
const database = useDatabase();
|
||||
@ -22,7 +22,7 @@ export default function BackgroundCover() {
|
||||
backgroundCover = backgroundCover.substring(1);
|
||||
}
|
||||
if (prependWebsiteUrl) {
|
||||
backgroundCover = config.siteUrl + "/" + backgroundCover;
|
||||
backgroundCover = Config.websiteUrl + "/" + backgroundCover;
|
||||
}
|
||||
|
||||
// Static background color
|
||||
|
@ -7,6 +7,7 @@ import Tooltip from "../tooltip";
|
||||
import { Button } from "../ui/button";
|
||||
import { PersonIcon } from "@radix-ui/react-icons";
|
||||
import ScoreSaberPlayer from "@ssr/common/types/player/impl/scoresaber-player";
|
||||
import { trackPlayer } from "@ssr/common/utils/player-utils";
|
||||
|
||||
type Props = {
|
||||
/**
|
||||
@ -27,6 +28,7 @@ export default function AddFriend({ player }: Props) {
|
||||
* Adds this player as a friend
|
||||
*/
|
||||
async function addFriend() {
|
||||
await trackPlayer(id);
|
||||
await database.addFriend(id);
|
||||
toast({
|
||||
title: "Friend Added",
|
||||
|
@ -14,7 +14,6 @@ import ScoreSaberPlayer, { getScoreSaberPlayerFromToken } from "@ssr/common/type
|
||||
import ScoreSaberPlayerScoresPageToken from "@ssr/common/types/token/scoresaber/score-saber-player-scores-page-token";
|
||||
import { ScoreSort } from "@ssr/common/types/score/score-sort";
|
||||
import { scoresaberService } from "@ssr/common/service/impl/scoresaber";
|
||||
import { config } from "../../../config";
|
||||
import useDatabase from "@/hooks/use-database";
|
||||
import { useLiveQuery } from "dexie-react-hooks";
|
||||
|
||||
@ -40,16 +39,17 @@ export default function PlayerData({
|
||||
const isMiniRankingsVisible = useIsVisible(miniRankingsRef);
|
||||
const database = useDatabase();
|
||||
const settings = useLiveQuery(() => database.getSettings());
|
||||
const isFriend = useLiveQuery(() => database.isFriend(initialPlayerData.id));
|
||||
|
||||
let player = initialPlayerData;
|
||||
const { data, isLoading, isError } = useQuery({
|
||||
queryKey: ["playerData", player.id, settings?.playerId],
|
||||
queryKey: ["playerData", player.id, settings?.playerId, isFriend],
|
||||
queryFn: async (): Promise<ScoreSaberPlayer | undefined> => {
|
||||
const playerResponse = await scoresaberService.lookupPlayer(player.id);
|
||||
if (playerResponse == undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return await getScoreSaberPlayerFromToken(playerResponse, config.siteApi, settings?.playerId);
|
||||
return await getScoreSaberPlayerFromToken(playerResponse, settings?.playerId);
|
||||
},
|
||||
refetchInterval: REFRESH_INTERVAL,
|
||||
refetchIntervalInBackground: false,
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import ky from "ky";
|
||||
import { config } from "../../../config";
|
||||
import Tooltip from "@/components/tooltip";
|
||||
import { InformationCircleIcon } from "@heroicons/react/16/solid";
|
||||
import { formatNumberWithCommas } from "@ssr/common/utils/number-utils";
|
||||
import { PlayerTrackedSince } from "@ssr/common/types/player/player-tracked-since";
|
||||
import ScoreSaberPlayer from "@ssr/common/types/player/impl/scoresaber-player";
|
||||
import { Config } from "@ssr/common/config";
|
||||
|
||||
type Props = {
|
||||
player: ScoreSaberPlayer;
|
||||
@ -16,7 +16,7 @@ type Props = {
|
||||
export default function PlayerTrackedStatus({ player }: Props) {
|
||||
const { data, isLoading, isError } = useQuery({
|
||||
queryKey: ["playerIsBeingTracked", player.id],
|
||||
queryFn: () => ky.get<PlayerTrackedSince>(`${config.siteApi}/player/tracked/${player.id}`).json(),
|
||||
queryFn: () => ky.get<PlayerTrackedSince>(`${Config.apiUrl}/player/tracked/${player.id}`).json(),
|
||||
});
|
||||
|
||||
if (isLoading || isError || !data?.tracked) {
|
||||
|
Reference in New Issue
Block a user