This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
scoresaber-reloadedv3/src/components/player/claim-profile.tsx

54 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-09-08 21:35:32 +00:00
"use client";
import { CheckIcon } from "@heroicons/react/24/solid";
import { useLiveQuery } from "dexie-react-hooks";
2024-09-09 08:24:16 +00:00
import { setPlayerIdCookie } from "../../common/website-utils";
import useDatabase from "../../hooks/use-database";
import { useToast } from "../../hooks/use-toast";
import { Button } from "../ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
2024-09-08 21:35:32 +00:00
type Props = {
/**
* The ID of the players profile to claim.
*/
playerId: string;
};
export default function ClaimProfile({ playerId }: Props) {
const database = useDatabase();
const { toast } = useToast();
const settings = useLiveQuery(() => database.getSettings());
/**
* Claims the profile.
*/
async function claimProfile() {
const settings = await database.getSettings();
settings?.setPlayerId(playerId);
setPlayerIdCookie(playerId);
2024-09-08 21:35:32 +00:00
toast({
title: "Profile Claimed",
description: "You have claimed this profile.",
});
}
if (settings?.playerId == playerId || settings == undefined) {
return null; // Don't show the claim button if it's the same user.
}
return (
<Tooltip>
<TooltipTrigger asChild>
<Button variant={"outline"} onClick={claimProfile}>
<CheckIcon className="size-6 text-green-500" />
</Button>
</TooltipTrigger>
<TooltipContent>
<p>Set as your profile</p>
</TooltipContent>
</Tooltip>
);
}