commit 87cda09ac6442820a0b16933989525dcb53a4425
Merge: 02d9bbf7
2bec5d95
Author: Karnage <karnagebitcoin@gmail.com>
Date: Tue Sep 19 23:13:32 2023 +0900
Merge branch 'css-fixes'
commit 2bec5d95c00476537dc5460f01557af12c1baa7b
Author: Karnage <karnagebitcoin@gmail.com>
Date: Tue Sep 19 22:40:27 2023 +0900
minor tweak on tabs
commit 776005e5eaafd5a8bc94cbf7821579a5bb831b1c
Author: Karnage <karnagebitcoin@gmail.com>
Date: Tue Sep 19 00:28:53 2023 +0900
added subscription tier borders in light mode
commit 66a55feb9950f433787d2a6966b200339462c4c6
Author: Karnage <karnagebitcoin@gmail.com>
Date: Tue Sep 19 00:28:43 2023 +0900
fixed tab colors in light mode
commit 830cc3c973301d2ce63745e1e328c69a219db1ef
Author: Karnage <karnagebitcoin@gmail.com>
Date: Tue Sep 19 00:28:29 2023 +0900
secondary color adjustment
commit 8c9939f3484c2dd5678ac72795dba7fa7f970402
Author: Karnage <karnagebitcoin@gmail.com>
Date: Tue Sep 19 00:12:46 2023 +0900
szh menu shadow fix
commit a59124f91055a4a9a3758823dee76e8bc44c5e83
Author: Karnage <karnagebitcoin@gmail.com>
Date: Tue Sep 19 00:01:34 2023 +0900
misc fixes
commit a4da5d86677eadace1b86df2d72e35255178a5f0
Author: Karnage <karnagebitcoin@gmail.com>
Date: Mon Sep 18 17:50:15 2023 +0900
Re-ordered reactions for consistency
commit 665162b6918b1666f1413884d4b4185d4df0f74a
Author: Karnage <karnagebitcoin@gmail.com>
Date: Mon Sep 18 13:25:55 2023 +0900
styled light load more button
commit a3058168d6df685cdf9d2871f8e3b335318eedcb
Author: Karnage <karnagebitcoin@gmail.com>
Date: Mon Sep 18 00:38:16 2023 +0900
styled subscriptions a bit
commit dcc940d96cefeca476e16891c148e2058fb48fd7
Author: Karnage <karnagebitcoin@gmail.com>
Date: Mon Sep 18 00:22:39 2023 +0900
adjusted input border to 2px and font size 15
commit 690e1662eeded6eab9f3029ce168d44b35604dca
Author: Karnage <karnagebitcoin@gmail.com>
Date: Mon Sep 18 00:22:12 2023 +0900
fixed settings tabs paddings
commit a5809c4c7d502da42788c6c758d6025e79699cf5
Author: Karnage <karnagebitcoin@gmail.com>
Date: Mon Sep 18 00:05:45 2023 +0900
removed some double borders
commit d1e0c331ed665c63160c2ae83f9e010b666c39df
Author: Karnage <karnagebitcoin@gmail.com>
Date: Mon Sep 18 00:05:28 2023 +0900
follow is primary now
commit 338bc03aa3616906326fe0a777a63c04dc4a7f48
Author: Karnage <karnagebitcoin@gmail.com>
Date: Mon Sep 18 00:05:10 2023 +0900
made follow button a primary
commit 4b5eb0c4fc71e0a8cf822ba8cac8facc53301e1e
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sun Sep 17 23:43:12 2023 +0900
made follows you into a label
commit 0a9d616402528311f4feba53f0ba9171b0640274
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sun Sep 17 23:35:07 2023 +0900
created secondary button bg variable
commit 2abcab804adf392e8f7ff2907762bc35c77f0297
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sun Sep 17 23:34:41 2023 +0900
added gap to profile buttons
commit 04a54ddb0d7b19c5ea7f420645c6bd3d37747c17
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sun Sep 17 23:34:26 2023 +0900
change new note button color
commit 2d2401586af70187785cff693061666d1de343f2
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sun Sep 17 22:57:01 2023 +0900
forget what I did here
commit 14d8bd255cc41e5450b18908b807e3d745c10fbe
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sun Sep 17 22:35:32 2023 +0900
adjusted new note button position
commit e3a6143626424b898aad43fc2eb1625336342c16
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sun Sep 17 22:32:37 2023 +0900
added primary button colors
commit 4d02bfef54668d1a09f0615634d6be540c9837ea
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sun Sep 17 18:51:37 2023 +0900
cleaned up modal reactions
commit 891f7985c6cf674d03188a95b3ca807ecb16c0bc
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sun Sep 17 00:10:46 2023 +0900
minimized error text from scary to less scary
commit dc563e7ded8794e43ed14409d5ffeb917172b800
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sat Sep 16 23:50:27 2023 +0900
adjusted search colors in light mode
commit 328cc853794c9b32abf8eab067bfd3f9b1a76aee
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sat Sep 16 22:59:33 2023 +0900
revert main font size, adjust thread root size
commit 2e55cbcbc1bc6e9494410ec77052adb3fd8bbbcf
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sat Sep 16 22:49:09 2023 +0900
re-styled quoted replies note creator
commit a3257eecff0a028a22d975eec778daeb73d8ec2e
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sat Sep 16 22:38:00 2023 +0900
got rid of weird filter menu shadow and radius
commit 258d51c6fddb65d3afecd595a1fd9352c2cfa13e
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sat Sep 16 22:12:03 2023 +0900
adjusted header bottom spacing per design to 8px
commit 03669925086e8a4995124d6e9077d61373fa89d3
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sat Sep 16 22:00:34 2023 +0900
adjusted gap to 16 per design
commit 9a1c77b0dd876632ecd313d25ce163204ff89897
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sat Sep 16 21:56:50 2023 +0900
set root font size to 16px per design
commit 4d0a91317d8946465b0d591db3d13c2e3df63ff8
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sat Sep 16 21:50:57 2023 +0900
made search full width
commit 3ea6b4ca005b27003f1554d53def14337620af2a
Author: Karnage <karnagebitcoin@gmail.com>
Date: Sat Sep 16 21:47:29 2023 +0900
fixed line height on thread root note
194 lines
6.1 KiB
TypeScript
194 lines
6.1 KiB
TypeScript
import "./Profile.css";
|
|
import { useEffect, useState } from "react";
|
|
import { FormattedMessage } from "react-intl";
|
|
import { useNavigate } from "react-router-dom";
|
|
import { mapEventToProfile } from "@snort/system";
|
|
import { useUserProfile } from "@snort/system-react";
|
|
|
|
import { System } from "index";
|
|
import useEventPublisher from "Feed/EventPublisher";
|
|
import { openFile } from "SnortUtils";
|
|
import useFileUpload from "Upload";
|
|
import AsyncButton from "Element/AsyncButton";
|
|
import { UserCache } from "Cache";
|
|
import useLogin from "Hooks/useLogin";
|
|
import Icon from "Icons/Icon";
|
|
import Avatar from "Element/Avatar";
|
|
|
|
export interface ProfileSettingsProps {
|
|
avatar?: boolean;
|
|
banner?: boolean;
|
|
}
|
|
|
|
export default function ProfileSettings(props: ProfileSettingsProps) {
|
|
const navigate = useNavigate();
|
|
const { publicKey: id } = useLogin();
|
|
const user = useUserProfile(id ?? "");
|
|
const publisher = useEventPublisher();
|
|
const uploader = useFileUpload();
|
|
|
|
const [name, setName] = useState<string>();
|
|
const [picture, setPicture] = useState<string>();
|
|
const [banner, setBanner] = useState<string>();
|
|
const [about, setAbout] = useState<string>();
|
|
const [website, setWebsite] = useState<string>();
|
|
const [nip05, setNip05] = useState<string>();
|
|
const [lud16, setLud16] = useState<string>();
|
|
|
|
useEffect(() => {
|
|
if (user) {
|
|
setName(user.name);
|
|
setPicture(user.picture);
|
|
setBanner(user.banner);
|
|
setAbout(user.about);
|
|
setWebsite(user.website);
|
|
setNip05(user.nip05);
|
|
setLud16(user.lud16);
|
|
}
|
|
}, [user]);
|
|
|
|
async function saveProfile() {
|
|
// copy user object and delete internal fields
|
|
const userCopy = {
|
|
...user,
|
|
name,
|
|
about,
|
|
picture,
|
|
banner,
|
|
website,
|
|
nip05,
|
|
lud16,
|
|
} as Record<string, string | number | undefined | boolean>;
|
|
delete userCopy["loaded"];
|
|
delete userCopy["created"];
|
|
delete userCopy["pubkey"];
|
|
delete userCopy["npub"];
|
|
delete userCopy["deleted"];
|
|
delete userCopy["zapService"];
|
|
delete userCopy["isNostrAddressValid"];
|
|
console.debug(userCopy);
|
|
|
|
if (publisher) {
|
|
const ev = await publisher.metadata(userCopy);
|
|
System.BroadcastEvent(ev);
|
|
|
|
const newProfile = mapEventToProfile(ev);
|
|
if (newProfile) {
|
|
await UserCache.update(newProfile);
|
|
}
|
|
}
|
|
}
|
|
|
|
async function uploadFile() {
|
|
const file = await openFile();
|
|
if (file) {
|
|
console.log(file);
|
|
const rsp = await uploader.upload(file, file.name);
|
|
console.log(rsp);
|
|
if (typeof rsp?.error === "string") {
|
|
throw new Error(`Upload failed ${rsp.error}`);
|
|
}
|
|
return rsp.url;
|
|
}
|
|
}
|
|
|
|
async function setNewBanner() {
|
|
const rsp = await uploadFile();
|
|
if (rsp) {
|
|
setBanner(rsp);
|
|
}
|
|
}
|
|
|
|
async function setNewAvatar() {
|
|
const rsp = await uploadFile();
|
|
if (rsp) {
|
|
setPicture(rsp);
|
|
}
|
|
}
|
|
|
|
function editor() {
|
|
return (
|
|
<div className="flex f-col g24">
|
|
<div className="flex f-col w-max g8">
|
|
<h4>
|
|
<FormattedMessage defaultMessage="Name" />
|
|
</h4>
|
|
<input className="w-max" type="text" value={name} onChange={e => setName(e.target.value)} />
|
|
</div>
|
|
<div className="flex f-col w-max g8">
|
|
<h4>
|
|
<FormattedMessage defaultMessage="About" />
|
|
</h4>
|
|
<textarea className="w-max" onChange={e => setAbout(e.target.value)} value={about}></textarea>
|
|
</div>
|
|
<div className="flex f-col w-max g8">
|
|
<h4>
|
|
<FormattedMessage defaultMessage="Website" />
|
|
</h4>
|
|
<input className="w-max" type="text" value={website} onChange={e => setWebsite(e.target.value)} />
|
|
</div>
|
|
<div className="flex f-col w-max g8">
|
|
<h4>
|
|
<FormattedMessage defaultMessage="Nostr Address" />
|
|
</h4>
|
|
<div className="flex f-col g8 w-max">
|
|
<input type="text" className="w-max" value={nip05} onChange={e => setNip05(e.target.value)} />
|
|
<small>
|
|
<FormattedMessage defaultMessage="Usernames are not unique on Nostr. The nostr address is your unique human-readable address that is unique to you upon registration." />
|
|
</small>
|
|
<div className="flex g12">
|
|
<button className="flex f-center" type="button" onClick={() => navigate("/nostr-address")}>
|
|
<FormattedMessage defaultMessage="Buy nostr address" />
|
|
</button>
|
|
<button className="flex f-center secondary" type="button" onClick={() => navigate("/nostr-address")}>
|
|
<FormattedMessage defaultMessage="Get a free one" />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="flex f-col w-max g8">
|
|
<h4>
|
|
<FormattedMessage defaultMessage="Lightning Address" />
|
|
</h4>
|
|
<input className="w-max" type="text" value={lud16} onChange={e => setLud16(e.target.value)} />
|
|
</div>
|
|
<AsyncButton className="primary" onClick={() => saveProfile()}>
|
|
<FormattedMessage defaultMessage="Save" />
|
|
</AsyncButton>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function settings() {
|
|
if (!id) return null;
|
|
return (
|
|
<>
|
|
<div className="flex f-center image-settings">
|
|
{(props.banner ?? true) && (
|
|
<div
|
|
style={{
|
|
background: (banner?.length ?? 0) > 0 ? `no-repeat center/cover url("${banner}")` : undefined,
|
|
}}
|
|
className="banner">
|
|
<AsyncButton type="button" onClick={() => setNewBanner()}>
|
|
<FormattedMessage defaultMessage="Upload" />
|
|
</AsyncButton>
|
|
</div>
|
|
)}
|
|
{(props.avatar ?? true) && (
|
|
<div className="avatar-stack">
|
|
<Avatar pubkey={id} user={user} image={picture} />
|
|
<AsyncButton type="button" className="btn-rnd" onClick={() => setNewAvatar()}>
|
|
<Icon name="upload-01" />
|
|
</AsyncButton>
|
|
</div>
|
|
)}
|
|
</div>
|
|
{editor()}
|
|
</>
|
|
);
|
|
}
|
|
|
|
return <div className="settings">{settings()}</div>;
|
|
}
|