diff --git a/bun.lockb b/bun.lockb index 4c75131e..b2cb3516 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/web/app/(pages)/profile/_components/wrapper.tsx b/web/app/(pages)/profile/_components/wrapper.tsx index a8433c32..a236a42e 100644 --- a/web/app/(pages)/profile/_components/wrapper.tsx +++ b/web/app/(pages)/profile/_components/wrapper.tsx @@ -1,10 +1,11 @@ "use client" import { useAccount } from "@/lib/providers/jazz-provider" -import { useParams, useRouter } from "next/navigation" +import { useParams } from "next/navigation" +import { useState, useRef } from "react" +import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar" +import { Input } from "@/components/ui/input" import Link from "next/link" -import { LaIcon } from "@/components/custom/la-icon" -import { Icon } from "@/components/la-editor/components/ui/icon" import { Button } from "@/components/ui/button" interface ProfileStatsProps { @@ -12,16 +13,6 @@ interface ProfileStatsProps { label: string } -interface ProfileLinksProps { - linklabel?: string - link?: string - topic?: string -} - -interface ProfilePagesProps { - topic?: string -} - const ProfileStats: React.FC = ({ number, label }) => { return (
@@ -31,37 +22,47 @@ const ProfileStats: React.FC = ({ number, label }) => { ) } -const ProfileLinks: React.FC = ({ linklabel, link, topic }) => { - return ( -
-
-

{linklabel || "Untitled"}

-
- -

{link || "#"}

-
-
-
{topic || "Uncategorized"}
-
- ) -} - -const ProfilePages: React.FC = ({ topic }) => { - return ( -
-
{topic || "Uncategorized"}
-
- ) -} - export const ProfileWrapper = () => { const account = useAccount() const params = useParams() const username = params.username as string + const avatarInputRef = useRef(null) - const router = useRouter() + const [isEditing, setIsEditing] = useState(false) + const [newName, setNewName] = useState(account.me?.profile?.name || "") + const [originalName, setOriginalName] = useState(account.me?.profile?.name || "") - const clickEdit = () => router.push("/edit-profile") + const editProfileClicked = () => { + setIsEditing(!isEditing) + } + + const changeName = (e: React.ChangeEvent) => { + setNewName(e.target.value) + } + + const saveProfile = () => { + if (newName.trim() !== "") { + if (account.me && account.me.profile) { + account.me.profile.name = newName.trim() + } + setOriginalName(newName.trim()) + setIsEditing(false) + } + } + + const clickOutside = () => { + if (isEditing) { + setNewName(originalName) + setIsEditing(false) + } + } + + const editAvatar = (event: React.ChangeEvent) => { + const file = event.target.files?.[0] + if (file) { + console.log("File selected:", file) + } + } if (!account.me || !account.me.profile) { return ( @@ -87,31 +88,36 @@ export const ProfileWrapper = () => {

Profile

-

{username}

-
+ + + avatarInputRef.current?.click()} className="cursor-pointer"> + {account.me?.profile?.name?.charAt(0)} + + + +
-

{account.me.profile.name}

-
- @

{account.me.root?.username}

-
- - -

{account.me.root?.website}

-
+ {isEditing ? ( + + ) : ( +

{account.me?.profile?.name}

+ )}
- +
@@ -121,17 +127,52 @@ export const ProfileWrapper = () => {
- - {/*
-

Public Pages

- {account.me.root?.personalPages?.map((page, index) => )} +
+

Public profiles are coming soon

-
-

Public Links

- {account.me.root?.personalLinks?.map((link, index) => ( - - ))} -
*/}
) } + +{ + // interface ProfileLinksProps { + // linklabel?: string + // link?: string + // topic?: string + // } + // interface ProfilePagesProps { + // topic?: string + // } + // const ProfileLinks: React.FC = ({ linklabel, link, topic }) => { + // return ( + //
+ //
+ //

{linklabel || "Untitled"}

+ //
+ // + //

{link || "#"}

+ //
+ //
+ //
{topic || "Uncategorized"}
+ //
+ // ) + // } + // const ProfilePages: React.FC = ({ topic }) => { + // return ( + //
+ //
{topic || "Uncategorized"}
+ //
+ // ) + // } + /* + +

{account.me.root?.website}

+
*/ + /* */ +} diff --git a/web/components/custom/sidebar/partial/profile-section.tsx b/web/components/custom/sidebar/partial/profile-section.tsx index df626468..68f6bc2c 100644 --- a/web/components/custom/sidebar/partial/profile-section.tsx +++ b/web/components/custom/sidebar/partial/profile-section.tsx @@ -1,7 +1,7 @@ +import { useAccount } from "@/lib/providers/jazz-provider" import { LaIcon } from "../../la-icon" import { useState } from "react" -import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar" -import { Button } from "@/components/ui/button" +import { useAuth } from "@clerk/nextjs" import { DropdownMenu, DropdownMenuContent, @@ -9,9 +9,8 @@ import { DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu" -import { useAccount } from "@/lib/providers/jazz-provider" +import { Avatar, AvatarImage } from "@/components/ui/avatar" import Link from "next/link" -import { useAuth } from "@clerk/nextjs" const MenuItem = ({ icon, @@ -52,7 +51,7 @@ export const ProfileSection: React.FC = () => { const { me } = useAccount({ profile: true }) - const { signOut } = useAuth() + const { signOut, isSignedIn } = useAuth() const [menuOpen, setMenuOpen] = useState(false) const closeMenu = () => setMenuOpen(false) @@ -67,11 +66,16 @@ export const ProfileSection: React.FC = () => { aria-label="Profile" className="hover:bg-accent focus-visible:ring-ring hover:text-accent-foreground flex items-center gap-1.5 truncate rounded pl-1 pr-1.5 focus-visible:outline-none focus-visible:ring-1" > - - - {/* CN */} - - {me?.profile?.name} + {isSignedIn ? ( + + + + ) : ( + + )} + + {isSignedIn ? me?.profile?.name : "guest"} + { - - - - - - - - - - - - - - + {isSignedIn ? ( + <> + + + + + + + + + + + + + ) : ( + + + + )}
- {/*
-
- - - - -
*/}
) } + +/* + + */ diff --git a/web/lib/schema/index.ts b/web/lib/schema/index.ts index c0a29f54..3ba49c10 100644 --- a/web/lib/schema/index.ts +++ b/web/lib/schema/index.ts @@ -13,6 +13,11 @@ import { PersonalPageLists } from "./personal-page" import { PersonalLinkLists } from "./personal-link" import { ListOfTopics } from "./master/topic" +declare module "jazz-tools" { + interface Profile { + avatarUrl?: string + } +} export class UserRoot extends CoMap { name = co.string username = co.string @@ -33,7 +38,7 @@ export class LaAccount extends Account { profile = co.ref(Profile) root = co.ref(UserRoot) - migrate(this: LaAccount, creationProps?: { name: string }) { + migrate(this: LaAccount, creationProps?: { name: string; avatarUrl?: string }) { // since we dont have a custom AuthProvider yet. // and still using the DemoAuth. the creationProps will only accept name. // so just do default profile create provided by jazz-tools @@ -46,7 +51,7 @@ export class LaAccount extends Account { { name: creationProps.name, username: creationProps.name, - avatar: "", + avatar: creationProps.avatarUrl || "", website: "", bio: "", is_public: false,