import { createRef, h } from "https://esm.sh/preact@10.17.1"; import { ProfileData } from "../features/profile.ts"; import { DividerBackgroundColor, HintLinkColor, HintTextColor, PlaceholderColor, PrimaryTextColor, SecondaryBackgroundColor, } from "./style/colors.ts"; import { Component } from "https://esm.sh/preact@10.11.3"; import { emitFunc } from "../event-bus.ts"; import { NostrAccountContext } from "../../libs/nostr.ts/nostr.ts"; import { UserIcon } from "./icons/user-icon.tsx"; export type SaveProfile = { type: "SaveProfile"; profile: ProfileData | undefined; ctx: NostrAccountContext; }; type Props = { ctx: NostrAccountContext; profile: ProfileData; emit: emitFunc; }; type State = { profileData: ProfileData | undefined; newFieldKeyError: string; }; export class EditProfile extends Component { state: Readonly = { newFieldKeyError: "", profileData: undefined, }; newFieldKey = createRef(); newFieldValue = createRef(); componentDidMount(): void { this.setState({ profileData: this.props.profile, }); } render(_props: Props, state: State) { return (
Profile

Name

this.onInput(e, "name")} type="text" class={`focus:outline-none focus:border-white w-full px-4 py-3 rounded-lg resize-y bg-transparent border-[2px] border-[${DividerBackgroundColor}] placeholder-[${PlaceholderColor}] text-[${PrimaryTextColor}] `} />

Profile Image URL

this.onInput(e, "picture")} type="text" class={`focus:outline-none focus:border-white w-full px-4 py-3 rounded-lg resize-y bg-transparent border-[2px] border-[${DividerBackgroundColor}] placeholder-[${PlaceholderColor}] text-[${PrimaryTextColor}] `} /> You can upload your images on websites like{" "} nostr.build

Banner Image URL

this.onInput(e, "banner")} type="text" class={`focus:outline-none focus:border-white w-full px-4 py-3 rounded-lg resize-y bg-transparent border-[2px] border-[${DividerBackgroundColor}] placeholder-[${PlaceholderColor}] text-[${PrimaryTextColor}]`} />

About

this.onInput(e, "about")} type="text" class={`focus:outline-none focus:border-white w-full px-4 py-3 rounded-lg resize-y bg-transparent border-[2px] border-[${DividerBackgroundColor}] placeholder-[${PlaceholderColor}] text-[${PrimaryTextColor}] `} />

Website

this.onInput(e, "website")} type="text" class={`focus:outline-none focus:border-white w-full px-4 py-3 rounded-lg resize-y bg-transparent border-[2px] border-[${DividerBackgroundColor}] placeholder-[${PlaceholderColor}] text-[${PrimaryTextColor}]`} />
); } onInput = (e: h.JSX.TargetedEvent, key?: string) => { const lines = e.currentTarget.value.split("\n"); e.currentTarget.setAttribute( "rows", `${lines.length}`, ); if (key) { const value = e.currentTarget.value; this.setState({ profileData: { ...this.state.profileData, [key]: value, }, }); } }; addField = () => { if (!this.newFieldKey.current || !this.newFieldValue.current) { return; } if (this.newFieldKey.current.value.trim() == "") { this.setState({ newFieldKeyError: "Key is required.", }); return; } console.log(`Adding field ${this.newFieldKey.current.value}`); console.log(`Adding field ${this.newFieldValue.current.value}`); this.setState({ profileData: { ...this.state.profileData, [this.newFieldKey.current.value]: this.newFieldValue.current.value, }, newFieldKeyError: "", }); this.newFieldKey.current.value = ""; this.newFieldValue.current.value = ""; }; onSubmit = (e: h.JSX.TargetedEvent) => { e.preventDefault(); this.props.emit({ type: "SaveProfile", ctx: this.props.ctx, profile: this.state.profileData, }); }; }