2024-09-04 17:09:46 -05:00
|
|
|
import React, { useRef, useState, useEffect } from "react";
|
|
|
|
import { Menu } from "primereact/menu";
|
|
|
|
import { useImageProxy } from "@/hooks/useImageProxy";
|
|
|
|
import { useSession } from 'next-auth/react';
|
|
|
|
import { useNDKContext } from "@/context/NDKContext";
|
|
|
|
import { formatDateTime } from "@/utils/time";
|
2024-09-14 18:36:46 -05:00
|
|
|
import { Tooltip } from "primereact/tooltip";
|
|
|
|
import { nip19 } from "nostr-tools";
|
2024-09-04 17:09:46 -05:00
|
|
|
import Image from "next/image";
|
2024-11-19 19:16:47 -06:00
|
|
|
import CombinedContributionChart from "@/components/charts/CombinedContributionChart";
|
2024-09-21 14:45:45 -05:00
|
|
|
import GithubContributionChart from "@/components/charts/GithubContributionChart";
|
2024-09-25 17:41:57 -05:00
|
|
|
import GithubContributionChartDisabled from "@/components/charts/GithubContributionChartDisabled";
|
2024-10-05 17:28:57 -05:00
|
|
|
import useCheckCourseProgress from "@/hooks/tracking/useCheckCourseProgress";
|
2024-09-10 17:56:48 -05:00
|
|
|
import useWindowWidth from "@/hooks/useWindowWidth";
|
2024-09-14 18:36:46 -05:00
|
|
|
import { useToast } from "@/hooks/useToast";
|
2024-09-20 12:22:42 -05:00
|
|
|
import UserProgress from "@/components/profile/progress/UserProgress";
|
2024-11-19 16:02:11 -06:00
|
|
|
import UserProgressTable from '@/components/profile/DataTables/UserProgressTable';
|
2024-11-19 17:45:09 -06:00
|
|
|
import UserPurchaseTable from '@/components/profile/DataTables/UserPurchaseTable';
|
2024-09-10 17:56:48 -05:00
|
|
|
|
2024-09-04 17:09:46 -05:00
|
|
|
const UserProfile = () => {
|
2024-09-10 17:56:48 -05:00
|
|
|
const windowWidth = useWindowWidth();
|
2024-09-04 17:09:46 -05:00
|
|
|
const [user, setUser] = useState(null);
|
2024-11-18 18:05:55 -06:00
|
|
|
const [account, setAccount] = useState(null);
|
2024-09-04 17:09:46 -05:00
|
|
|
const { data: session } = useSession();
|
|
|
|
const { returnImageProxy } = useImageProxy();
|
|
|
|
const { ndk, addSigner } = useNDKContext();
|
2024-09-14 18:36:46 -05:00
|
|
|
const { showToast } = useToast();
|
2024-09-04 17:09:46 -05:00
|
|
|
const menu = useRef(null);
|
2024-10-05 17:28:57 -05:00
|
|
|
useCheckCourseProgress();
|
2024-09-04 17:09:46 -05:00
|
|
|
|
2024-09-28 19:06:17 -05:00
|
|
|
const copyToClipboard = (text) => {
|
|
|
|
navigator.clipboard.writeText(text);
|
|
|
|
showToast("success", "Copied", "Copied to clipboard");
|
|
|
|
};
|
|
|
|
|
2024-09-04 17:09:46 -05:00
|
|
|
useEffect(() => {
|
|
|
|
if (session?.user) {
|
2024-11-18 18:05:55 -06:00
|
|
|
console.log("Session", session)
|
2024-09-04 17:09:46 -05:00
|
|
|
setUser(session.user);
|
2024-11-18 18:05:55 -06:00
|
|
|
|
|
|
|
if (session?.account) {
|
|
|
|
setAccount(session.account);
|
|
|
|
}
|
2024-09-04 17:09:46 -05:00
|
|
|
}
|
|
|
|
}, [session]);
|
|
|
|
|
|
|
|
const header = (
|
|
|
|
<div className="flex flex-wrap align-items-center justify-content-between gap-2">
|
2024-09-22 15:19:40 -05:00
|
|
|
<span className="text-xl text-900 font-bold text-[#f8f8ff]">Progress</span>
|
2024-09-04 17:09:46 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2024-09-25 17:41:57 -05:00
|
|
|
const purchasesHeader = (
|
|
|
|
<div className="flex flex-wrap align-items-center justify-content-between gap-2">
|
|
|
|
<span className="text-xl text-900 font-bold text-[#f8f8ff]">Purchases</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2024-11-09 15:21:43 -06:00
|
|
|
const menuItems = [
|
|
|
|
...(user?.privkey ? [{
|
|
|
|
label: 'Copy nsec',
|
|
|
|
icon: 'pi pi-key',
|
|
|
|
command: () => {
|
|
|
|
const privkeyBuffer = Buffer.from(user.privkey, 'hex');
|
|
|
|
copyToClipboard(nip19.nsecEncode(privkeyBuffer));
|
|
|
|
}
|
|
|
|
}] : []),
|
|
|
|
{
|
|
|
|
label: 'Copy npub',
|
|
|
|
icon: 'pi pi-user',
|
|
|
|
command: () => {
|
|
|
|
if (user.pubkey) {
|
|
|
|
copyToClipboard(nip19.npubEncode(user?.pubkey));
|
|
|
|
}
|
|
|
|
}
|
2024-11-18 16:42:40 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Open Nostr Profile',
|
|
|
|
icon: 'pi pi-external-link',
|
|
|
|
command: () => window.open(`https://nostr.com/${nip19.npubEncode(user?.pubkey)}`, '_blank')
|
2024-11-09 15:21:43 -06:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-09-04 17:09:46 -05:00
|
|
|
return (
|
|
|
|
user && (
|
2024-09-10 17:56:48 -05:00
|
|
|
<div className="p-4">
|
|
|
|
{
|
|
|
|
windowWidth < 768 && (
|
|
|
|
<h1 className="text-3xl font-bold mb-6">Profile</h1>
|
|
|
|
)
|
|
|
|
}
|
2024-09-04 17:09:46 -05:00
|
|
|
<div className="w-full flex flex-col justify-center mx-auto">
|
|
|
|
<div className="relative flex w-full items-center justify-center">
|
|
|
|
<Image
|
|
|
|
alt="user's avatar"
|
2024-11-14 15:51:29 -06:00
|
|
|
src={returnImageProxy(user.avatar, user?.pubkey || "")}
|
2024-09-04 17:09:46 -05:00
|
|
|
width={100}
|
|
|
|
height={100}
|
|
|
|
className="rounded-full my-4"
|
|
|
|
/>
|
2024-11-09 15:21:43 -06:00
|
|
|
<div className="absolute top-8 right-80 max-tab:right-20 max-mob:left-0">
|
2024-11-19 17:45:09 -06:00
|
|
|
<i
|
2024-11-09 15:21:43 -06:00
|
|
|
className="pi pi-ellipsis-h text-2xl cursor-pointer"
|
|
|
|
onClick={(e) => menu.current.toggle(e)}
|
|
|
|
/>
|
2024-11-19 17:45:09 -06:00
|
|
|
<Menu
|
|
|
|
model={menuItems}
|
|
|
|
popup
|
|
|
|
ref={menu}
|
2024-11-09 15:21:43 -06:00
|
|
|
id="profile-options-menu"
|
|
|
|
/>
|
|
|
|
</div>
|
2024-09-04 17:09:46 -05:00
|
|
|
</div>
|
|
|
|
|
2024-11-09 15:21:43 -06:00
|
|
|
|
2024-09-04 17:09:46 -05:00
|
|
|
<h1 className="text-center text-2xl my-2">
|
2024-11-18 16:42:40 -06:00
|
|
|
{user.username || user?.name || user?.email || "Anon"}
|
2024-09-04 17:09:46 -05:00
|
|
|
</h1>
|
2024-11-14 15:51:29 -06:00
|
|
|
{user.pubkey && (
|
|
|
|
<h2 className="text-center text-xl my-2 truncate max-tab:px-4 max-mob:px-4">
|
|
|
|
<Tooltip target=".pubkey-tooltip" content={"this is your nostr npub"} />
|
|
|
|
{nip19.npubEncode(user.pubkey)} <i className="pi pi-question-circle text-xl pubkey-tooltip" />
|
|
|
|
</h2>
|
|
|
|
)}
|
2024-09-27 13:33:27 -05:00
|
|
|
{user?.lightningAddress && (
|
2024-09-28 19:06:17 -05:00
|
|
|
<h3 className="w-fit mx-auto text-center text-xl my-2 bg-gray-800 rounded-lg p-4">
|
|
|
|
<span className="font-bold">Lightning Address:</span> {user.lightningAddress.name}@plebdevs.com <i className="pi pi-copy cursor-pointer hover:text-gray-400" onClick={() => copyToClipboard(user.lightningAddress.name + "@plebdevs.com")} />
|
2024-09-27 13:33:27 -05:00
|
|
|
</h3>
|
|
|
|
)}
|
|
|
|
{user?.nip05 && (
|
2024-09-28 19:06:17 -05:00
|
|
|
<h3 className="w-fit mx-auto text-center text-xl my-2 bg-gray-800 rounded-lg p-4">
|
|
|
|
<span className="font-bold">NIP-05:</span> {user.nip05.name}@plebdevs.com <i className="pi pi-copy cursor-pointer hover:text-gray-400" onClick={() => copyToClipboard(user.nip05.name + "@plebdevs.com")} />
|
2024-09-27 13:33:27 -05:00
|
|
|
</h3>
|
|
|
|
)}
|
2024-11-18 18:05:55 -06:00
|
|
|
{account && account?.provider === "github" ? (
|
2024-11-19 19:16:47 -06:00
|
|
|
<CombinedContributionChart username={user.username} session={session} />
|
2024-11-18 18:05:55 -06:00
|
|
|
) : (
|
|
|
|
<GithubContributionChartDisabled username={"austinkelsay"} />
|
|
|
|
)}
|
2024-09-20 12:22:42 -05:00
|
|
|
<UserProgress />
|
2024-09-04 17:09:46 -05:00
|
|
|
</div>
|
2024-11-19 17:45:09 -06:00
|
|
|
<UserProgressTable
|
|
|
|
session={session}
|
|
|
|
ndk={ndk}
|
|
|
|
windowWidth={windowWidth}
|
|
|
|
/>
|
|
|
|
<UserPurchaseTable
|
|
|
|
session={session}
|
|
|
|
windowWidth={windowWidth}
|
|
|
|
/>
|
2024-09-04 17:09:46 -05:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default UserProfile;
|