diff --git a/package.json b/package.json index 157f4cc24..527377aa7 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-error-boundary": "^3.1.4", + "react-hook-form": "^7.41.2", "react-markdown": "^8.0.4", "react-router-dom": "^6.5.0", "react-singleton-hook": "^4.0.1", diff --git a/src/app.tsx b/src/app.tsx index cc255678d..3a80ca648 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -6,6 +6,7 @@ import { Page } from "./components/page"; import { SettingsView } from "./views/settings"; import { GlobalView } from "./views/global"; import { SetupView } from "./views/setup"; +import { ProfileView } from "./views/profile"; import useSubject from "./hooks/use-subject"; import identity from "./services/identity"; @@ -54,6 +55,16 @@ export const App = () => { } /> + + + + + + } + /> { const navigate = useNavigate(); - const pubkey = useSubject(identity.pubkey); return ( @@ -46,7 +44,7 @@ const MobileLayout = ({ children }: { children: React.ReactNode }) => { } aria-label="Profile" - onClick={() => navigate(`/user/${pubkey}`)} + onClick={() => navigate(`/profile`)} flexGrow="1" size="lg" /> @@ -63,7 +61,6 @@ const MobileLayout = ({ children }: { children: React.ReactNode }) => { }; const DesktopLayout = ({ children }: { children: React.ReactNode }) => { const navigate = useNavigate(); - const pubkey = useSubject(identity.pubkey); return ( { overflow="hidden" > + - diff --git a/src/components/profile-button.tsx b/src/components/profile-button.tsx new file mode 100644 index 000000000..f33478fb5 --- /dev/null +++ b/src/components/profile-button.tsx @@ -0,0 +1,35 @@ +import { Box, LinkBox, Text } from "@chakra-ui/react"; +import { Link } from "react-router-dom"; +import useSubject from "../hooks/use-subject"; +import identity from "../services/identity"; +import { UserAvatar } from "./user-avatar"; +import { useUserMetadata } from "../hooks/use-user-metadata"; + +export type ProfileButtonProps = { + to: string; +}; + +export const ProfileButton = ({ to }: ProfileButtonProps) => { + const pubkey = useSubject(identity.pubkey); + const { loading, metadata } = useUserMetadata(pubkey); + + return ( + + + + {metadata?.name} + {pubkey} + + + ); +}; diff --git a/src/views/profile/edit.tsx b/src/views/profile/edit.tsx new file mode 100644 index 000000000..b34f5040a --- /dev/null +++ b/src/views/profile/edit.tsx @@ -0,0 +1,95 @@ +import { + Avatar, + Button, + Flex, + FormControl, + FormLabel, + Input, + SkeletonText, + Textarea, +} from "@chakra-ui/react"; +import { useMemo } from "react"; +import { useForm } from "react-hook-form"; +import useSubject from "../../hooks/use-subject"; +import { useUserMetadata } from "../../hooks/use-user-metadata"; +import identity from "../../services/identity"; + +type FormData = { + displayName?: string; + username?: string; + picture?: string; + about?: string; +}; + +type MetadataFormProps = { + defaultValues?: FormData; + onSubmit: (data: FormData) => void; +}; + +const MetadataForm = ({ defaultValues, onSubmit }: MetadataFormProps) => { + const { register, reset, handleSubmit, getValues } = useForm({ + defaultValues, + }); + + const submit = handleSubmit(onSubmit); + + return ( +
+ + + + Display Name + + + + Username + + + + + + Picture + + + + + + About +