diff --git a/src/app/(sidebars)/error.tsx b/src/app/(sidebars)/error.tsx index ac6d97b..50e5139 100644 --- a/src/app/(sidebars)/error.tsx +++ b/src/app/(sidebars)/error.tsx @@ -10,7 +10,7 @@ export default function error({ error, reset }: { error: Error & { digest?: stri return (
-

Σ(O_O) Something went wrong

+

Something went wrong

{message &&

{message}

}
diff --git a/src/app/(sidebars)/u/[user]/layout.tsx b/src/app/(sidebars)/u/[user]/layout.tsx index eb27248..6ee6847 100644 --- a/src/app/(sidebars)/u/[user]/layout.tsx +++ b/src/app/(sidebars)/u/[user]/layout.tsx @@ -1,7 +1,6 @@ import { Card } from "~/components/ui/card"; import { UserNavigation } from "~/components/user/UserNavigation"; import { UserProfile } from "~/components/user/UserProfile"; -import { getLensClient } from "~/utils/getLensClient"; import { getUserByHandle } from "~/utils/getUserByHandle"; export default async function layout({ @@ -11,12 +10,11 @@ export default async function layout({ children: React.ReactNode; params: { user: string }; }) { - const { handle: authenticatedHandle } = await getLensClient(); const handle = params.user; - const isUserProfile = handle === authenticatedHandle; const user = await getUserByHandle(handle); if (!user) throw new Error("∑(O_O;) Profile not found"); + console.log(user); return ( <> diff --git a/src/app/(sidebars)/u/[user]/page.tsx b/src/app/(sidebars)/u/[user]/page.tsx index a7dfed5..9522989 100644 --- a/src/app/(sidebars)/u/[user]/page.tsx +++ b/src/app/(sidebars)/u/[user]/page.tsx @@ -27,6 +27,10 @@ const getInitialData = async (handle: string) => { const { client } = await getLensClient(); const user = await getUserByHandle(handle); + if (!user) { + throw new Error("☆⌒(>。<) User not found"); + } + const lensPosts = await client.publication .fetchAll({ where: { from: [user.id], publicationTypes: [PublicationType.Post] }, diff --git a/src/components/user/UserInterests.tsx b/src/components/user/UserInterests.tsx index 660cf68..c5d86ed 100644 --- a/src/components/user/UserInterests.tsx +++ b/src/components/user/UserInterests.tsx @@ -4,7 +4,6 @@ import { ProfileInterestTypes } from "@lens-protocol/react-web"; import { useMemo } from "react"; import { toast } from "sonner"; import { Label } from "../ui/label"; -import { Separator } from "../ui/separator"; import { Toggle } from "../ui/toggle"; import { type UserInterests, capitalize, parseInterests } from "./User"; diff --git a/src/components/user/UserProfile.tsx b/src/components/user/UserProfile.tsx index 9d13efe..dd42f3e 100644 --- a/src/components/user/UserProfile.tsx +++ b/src/components/user/UserProfile.tsx @@ -1,6 +1,5 @@ import { CalendarIcon, EditIcon, MessageCircleIcon, PawPrintIcon, User2Icon } from "lucide-react"; import Link from "next/link"; -import Markdown from "~/components/Markdown"; import { TimeSince } from "~/components/TimeLabel"; import { UserAvatar } from "~/components/user/UserAvatar"; import { getLensClient } from "~/utils/getLensClient"; @@ -8,13 +7,12 @@ import { FollowButton } from "../FollowButton"; import { TruncatedText } from "../TruncatedText"; import { Badge } from "../ui/badge"; import { Dialog, DialogContent, DialogHeader, DialogTrigger } from "../ui/dialog"; -import { Label } from "../ui/label"; import { Separator } from "../ui/separator"; import { type User, parseInterests } from "./User"; import { UserInterestsList } from "./UserInterests"; export const UserProfile = async ({ user }: { user: User }) => { - if (!user) throw new Error("∑(O_O;) Profile not found"); + if (!user) throw new Error("Profile not found"); const { user: authedUser } = await getLensClient(); const isUserProfile = user.id === authedUser.id; @@ -22,7 +20,7 @@ export const UserProfile = async ({ user }: { user: User }) => { const commonInterestTypes = user.interests .map((interest) => interest.value) - .filter((interest) => authedUser.interests.map((interest) => interest.value).includes(interest)); + .filter((interest) => authedUser?.interests?.map((interest) => interest.value).includes(interest)); const commonInterests = parseInterests(commonInterestTypes); return ( diff --git a/src/utils/getUserByHandle.ts b/src/utils/getUserByHandle.ts index a4802e8..61166c1 100644 --- a/src/utils/getUserByHandle.ts +++ b/src/utils/getUserByHandle.ts @@ -1,13 +1,15 @@ -import { lensProfileToUser } from "~/components/user/User"; +import { type User, lensProfileToUser } from "~/components/user/User"; import { getLensClient } from "./getLensClient"; -export const getUserByHandle = async (handle: string) => { +export const getUserByHandle = async (handle: string): Promise => { const { client } = await getLensClient(); const profile = await client.profile.fetch({ forHandle: `lens/${handle}`, }); + if (!profile) return null + const user = lensProfileToUser(profile); if (!user) throw new Error("∑(O_O;) Profile not found");