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.yml";
2023-07-12 17:58:47 +01:00
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 = {
2023-07-13 05:41:36 +01:00
online: "bg-[#43B581]",
offline: "bg-transparent",
2023-07-13 05:41:36 +01:00
dnd: "bg-[#F04747]",
idle: "bg-[#FAA61A]",
2023-07-12 17:58:47 +01:00
};
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
2023-07-13 05:31:23 +01:00
className={`absolute bottom-2 right-2 w-5 h-5 rounded-full transition ${currentStatus}`}
2023-07-12 17:58:47 +01:00
/>
)}
</div>
);
}