62 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-07-12 17:58:47 +01:00
"use client";
import Image from "next/image";
import { Fragment } from "react";
2023-07-12 17:58:47 +01:00
import { useLanyardWS } from "use-lanyard";
import Config from "../../../config.json";
function LanyardWrapper(props: { children: any }) {
return <Fragment>{props.children}</Fragment>;
}
2023-07-12 17:58:47 +01:00
export default function Avatar(props: any) {
const { avatar } = props;
const { discord }: any = Config;
2023-07-12 17:58:47 +01:00
return (
<div className="relative inline-block">
<Image
src={avatar}
alt="Avatar"
width={120}
height={120}
className="rounded-full"
/>
{discord ? (
<LanyardWrapper>
<LanyardComponent discord={discord} />
</LanyardWrapper>
) : null}
</div>
);
}
function LanyardComponent(props: { discord: any }) {
const { discord } = props;
const discordId = discord.id;
2023-07-12 17:58:47 +01:00
const lanyardData = useLanyardWS(discordId);
const hasLanyard = lanyardData !== undefined;
2023-07-12 17:58:47 +01:00
const statusColor = {
online: "bg-green-400",
offline: "bg-slate-400",
dnd: "bg-red-500",
idle: "bg-orange-400",
};
const currentStatus =
lanyardData !== undefined
2023-07-12 17:58:47 +01:00
? statusColor[lanyardData.discord_status]
: undefined;
return (
<div>
2023-07-12 17:58:47 +01:00
{hasLanyard && (
<div
className={`absolute bottom-2 right-2 w-4 h-4 rounded-full transition ${currentStatus}`}
/>
)}
</div>
);
}