adding sricter ts rules means lots of clean up ;}
This commit is contained in:
parent
7a6d2c813c
commit
5a3003abe5
@ -39,7 +39,7 @@ export default function ProfilePage({
|
|||||||
<div className="mx-auto max-w-5xl p-0">
|
<div className="mx-auto max-w-5xl p-0">
|
||||||
<div className="m-0 @5xl:px-5 @5xl:pt-8">
|
<div className="m-0 @5xl:px-5 @5xl:pt-8">
|
||||||
<div className="relative w-full overflow-hidden bg-gradient-to-b from-primary pb-[29%] @5xl:rounded-[20px]">
|
<div className="relative w-full overflow-hidden bg-gradient-to-b from-primary pb-[29%] @5xl:rounded-[20px]">
|
||||||
{!!profile.banner && (
|
{!!profile?.banner && (
|
||||||
<Image
|
<Image
|
||||||
className="absolute inset-0 h-full w-full object-cover align-middle"
|
className="absolute inset-0 h-full w-full object-cover align-middle"
|
||||||
src={
|
src={
|
||||||
@ -56,7 +56,7 @@ export default function ProfilePage({
|
|||||||
</div>
|
</div>
|
||||||
<div className="relative mx-auto mb-4 mt-[calc(-0.4375_*_4rem)] flex max-w-[800px] items-end justify-between gap-2 px-3 sm:mt-[calc(-0.4375_*_4.5rem)] sm:px-5 md:mt-[calc(-0.5625_*_5rem)] lg:mt-[calc(-0.5625_*_6rem)]">
|
<div className="relative mx-auto mb-4 mt-[calc(-0.4375_*_4rem)] flex max-w-[800px] items-end justify-between gap-2 px-3 sm:mt-[calc(-0.4375_*_4.5rem)] sm:px-5 md:mt-[calc(-0.5625_*_5rem)] lg:mt-[calc(-0.5625_*_6rem)]">
|
||||||
<div className="z-1 ml-[calc(-1_*_3px)] overflow-hidden rounded-[0.5rem] bg-background p-[3px] sm:ml-[calc(-1_*_4px)] sm:p-[4px] lg:ml-[calc(-1_*_6px)] lg:rounded-[1rem] lg:p-[6px]">
|
<div className="z-1 ml-[calc(-1_*_3px)] overflow-hidden rounded-[0.5rem] bg-background p-[3px] sm:ml-[calc(-1_*_4px)] sm:p-[4px] lg:ml-[calc(-1_*_6px)] lg:rounded-[1rem] lg:p-[6px]">
|
||||||
{profile.image ? (
|
{profile?.image ? (
|
||||||
<Image
|
<Image
|
||||||
src={
|
src={
|
||||||
"https://images.lumacdn.com/cdn-cgi/image/format=auto,fit=cover,dpr=2,background=white,quality=75,width=96,height=96/calendars/hw/70772773-6d97-4fbb-a076-fc4dee603080"
|
"https://images.lumacdn.com/cdn-cgi/image/format=auto,fit=cover,dpr=2,background=white,quality=75,width=96,height=96/calendars/hw/70772773-6d97-4fbb-a076-fc4dee603080"
|
||||||
@ -84,15 +84,15 @@ export default function ProfilePage({
|
|||||||
<div className="mx-auto max-w-[800px] space-y-1 px-4">
|
<div className="mx-auto max-w-[800px] space-y-1 px-4">
|
||||||
<div className="flex items-center gap-x-1.5 lg:gap-x-2.5">
|
<div className="flex items-center gap-x-1.5 lg:gap-x-2.5">
|
||||||
<h2 className="text-xl font-semibold sm:text-2xl lg:text-3xl">
|
<h2 className="text-xl font-semibold sm:text-2xl lg:text-3xl">
|
||||||
{profile.displayName ?? profile.name ?? truncateText(npub)}
|
{profile?.displayName ?? profile?.name ?? truncateText(npub)}
|
||||||
</h2>
|
</h2>
|
||||||
{!!profile.nip05 && (
|
{!!profile?.nip05 && (
|
||||||
<HiCheckBadge className="h-5 w-5 text-primary lg:h-7 lg:w-7" />
|
<HiCheckBadge className="h-5 w-5 text-primary lg:h-7 lg:w-7" />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center text-xs text-muted-foreground/80 md:text-sm">
|
<div className="flex items-center text-xs text-muted-foreground/80 md:text-sm">
|
||||||
{!!profile.name && <p>{profile.name}</p>}
|
{!!profile?.name && <p>{profile.name}</p>}
|
||||||
{!!profile.name && !!profile.nip05 && (
|
{!!profile?.name && !!profile.nip05 && (
|
||||||
<>
|
<>
|
||||||
<div className="inline-flex px-1">·</div>
|
<div className="inline-flex px-1">·</div>
|
||||||
<p>{profile.nip05}</p>
|
<p>{profile.nip05}</p>
|
||||||
@ -100,7 +100,7 @@ export default function ProfilePage({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="pt-1 md:pt-2">
|
<div className="pt-1 md:pt-2">
|
||||||
{!!profile.about && (
|
{!!profile?.about && (
|
||||||
<p className="line-clamp-3 text-xs text-muted-foreground md:text-sm">
|
<p className="line-clamp-3 text-xs text-muted-foreground md:text-sm">
|
||||||
{profile.about}
|
{profile.about}
|
||||||
</p>
|
</p>
|
||||||
|
@ -54,8 +54,9 @@ export const Users = (ndk: NDK | undefined) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getProfile(id: string) {
|
function getProfile(id: string) {
|
||||||
if (users[id]) {
|
const user = users[id];
|
||||||
return users[id].profile!;
|
if (user) {
|
||||||
|
return user.profile;
|
||||||
} else {
|
} else {
|
||||||
fetchUser(id);
|
fetchUser(id);
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,8 @@ interface NDKContext {
|
|||||||
}
|
}
|
||||||
| undefined,
|
| undefined,
|
||||||
) => Promise<undefined | NDKEvent>;
|
) => Promise<undefined | NDKEvent>;
|
||||||
getUser: (_: string) => NDKUser;
|
getUser: (_: string) => NDKUser | undefined;
|
||||||
getProfile: (_: string) => NDKUserProfile;
|
getProfile: (_: string) => NDKUserProfile | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NDKContext = createContext<NDKContext>({
|
const NDKContext = createContext<NDKContext>({
|
||||||
|
@ -46,7 +46,7 @@ export const parseContent = ({
|
|||||||
// Convert legacy mentions to bech32 entities
|
// Convert legacy mentions to bech32 entities
|
||||||
const mentionMatch = text.match(/^#\[(\d+)\]/i);
|
const mentionMatch = text.match(/^#\[(\d+)\]/i);
|
||||||
|
|
||||||
if (mentionMatch) {
|
if (mentionMatch && mentionMatch[1]) {
|
||||||
const i = parseInt(mentionMatch[1]);
|
const i = parseInt(mentionMatch[1]);
|
||||||
|
|
||||||
if (tags[i]) {
|
if (tags[i]) {
|
||||||
|
@ -13,7 +13,7 @@ import { BANNER } from "@/constants/app";
|
|||||||
import { getNameToShow } from "@/lib/utils";
|
import { getNameToShow } from "@/lib/utils";
|
||||||
|
|
||||||
type CreatorCardProps = {
|
type CreatorCardProps = {
|
||||||
profile: NDKUserProfile;
|
profile?: NDKUserProfile;
|
||||||
npub: string;
|
npub: string;
|
||||||
recentWork: {
|
recentWork: {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -10,7 +10,7 @@ import { toast } from "sonner";
|
|||||||
|
|
||||||
export default function Kind1(props: Event) {
|
export default function Kind1(props: Event) {
|
||||||
const { content, pubkey, tags } = props;
|
const { content, pubkey, tags } = props;
|
||||||
const r = getTagsValues("r", tags);
|
const r = getTagsValues("r", tags).filter(Boolean);
|
||||||
const npub = nip19.npubEncode(pubkey);
|
const npub = nip19.npubEncode(pubkey);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -8,7 +8,9 @@ import { removeDuplicates } from "@/lib/utils";
|
|||||||
export default function Kind30023({ content, pubkey, tags }: Event) {
|
export default function Kind30023({ content, pubkey, tags }: Event) {
|
||||||
const title = getTagValues("title", tags);
|
const title = getTagValues("title", tags);
|
||||||
const summary = getTagValues("summary", tags);
|
const summary = getTagValues("summary", tags);
|
||||||
const contentTags = removeDuplicates(getTagsValues("t", tags));
|
const contentTags = removeDuplicates(getTagsValues("t", tags)).filter(
|
||||||
|
Boolean,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container pubkey={pubkey} contentTags={contentTags}>
|
<Container pubkey={pubkey} contentTags={contentTags}>
|
||||||
|
@ -14,7 +14,7 @@ export default function ProfileHeader({ pubkey }: ProfileHeaderProps) {
|
|||||||
return (
|
return (
|
||||||
<Link href={`/${npub}`} className="center group gap-x-3">
|
<Link href={`/${npub}`} className="center group gap-x-3">
|
||||||
<Avatar className="center h-8 w-8 overflow-hidden rounded-sm bg-muted">
|
<Avatar className="center h-8 w-8 overflow-hidden rounded-sm bg-muted">
|
||||||
<AvatarImage src={profile.image} alt={profile.displayName} />
|
<AvatarImage src={profile?.image} alt={profile?.displayName} />
|
||||||
<AvatarFallback className="text-xs">
|
<AvatarFallback className="text-xs">
|
||||||
{getTwoLetters({ npub, profile })}
|
{getTwoLetters({ npub, profile })}
|
||||||
</AvatarFallback>
|
</AvatarFallback>
|
||||||
@ -23,7 +23,7 @@ export default function ProfileHeader({ pubkey }: ProfileHeaderProps) {
|
|||||||
<span className="text-xs uppercase text-muted-foreground group-hover:underline">
|
<span className="text-xs uppercase text-muted-foreground group-hover:underline">
|
||||||
{getNameToShow({ npub, profile })}
|
{getNameToShow({ npub, profile })}
|
||||||
</span>
|
</span>
|
||||||
{!!profile.nip05 && <HiCheckBadge className="h-4 w-4 text-primary" />}
|
{!!profile?.nip05 && <HiCheckBadge className="h-4 w-4 text-primary" />}
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
|
@ -50,12 +50,16 @@ const RenderText = ({ text }: { text?: string }) => {
|
|||||||
// specialElement = <span className="">{specialValuesArray[index]}</span>;
|
// specialElement = <span className="">{specialValuesArray[index]}</span>;
|
||||||
} else if (specialValuesArray[index]?.match(nostrPrefixRegex)) {
|
} else if (specialValuesArray[index]?.match(nostrPrefixRegex)) {
|
||||||
const mention = specialValuesArray[index]?.split(":")[1];
|
const mention = specialValuesArray[index]?.split(":")[1];
|
||||||
if (mention.startsWith("nprofile") || mention.startsWith("npub")) {
|
if (
|
||||||
|
mention &&
|
||||||
|
(mention.startsWith("nprofile") || mention.startsWith("npub"))
|
||||||
|
) {
|
||||||
specialElement = <ProfileMention mention={mention} />;
|
specialElement = <ProfileMention mention={mention} />;
|
||||||
} else if (
|
} else if (
|
||||||
mention.startsWith("nevent") ||
|
mention &&
|
||||||
mention.startsWith("note") ||
|
(mention.startsWith("nevent") ||
|
||||||
mention.startsWith("naddr")
|
mention.startsWith("note") ||
|
||||||
|
mention.startsWith("naddr"))
|
||||||
) {
|
) {
|
||||||
specialElement = <EventMention mention={mention} />;
|
specialElement = <EventMention mention={mention} />;
|
||||||
}
|
}
|
||||||
|
@ -64,9 +64,11 @@ export default function useCurrentUser() {
|
|||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
function handleUpdateUser(userInfo: string) {
|
function handleUpdateUser(userInfo: string) {
|
||||||
|
const userObject = UserSchema.safeParse(JSON.parse(userInfo));
|
||||||
|
if (!userObject.success) return;
|
||||||
const parsedData = UserSchema.safeParse({
|
const parsedData = UserSchema.safeParse({
|
||||||
...currentUser,
|
...currentUser,
|
||||||
...JSON.parse(userInfo),
|
...userObject,
|
||||||
});
|
});
|
||||||
if (parsedData.success) {
|
if (parsedData.success) {
|
||||||
updateCurrentUser({
|
updateCurrentUser({
|
||||||
|
@ -12,7 +12,7 @@ function useLocalStorage<T>(key: string, initialValue: T) {
|
|||||||
// Get from local storage by key
|
// Get from local storage by key
|
||||||
const item = window.localStorage.getItem(key);
|
const item = window.localStorage.getItem(key);
|
||||||
// Parse stored json or if none return initialValue
|
// Parse stored json or if none return initialValue
|
||||||
return item ? JSON.parse(item) : initialValue;
|
return item ? (JSON.parse(item) as T) : initialValue;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If error also return initialValue
|
// If error also return initialValue
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
@ -14,12 +14,12 @@ export function nip19ToTag(nip19Id: string): string[] | undefined {
|
|||||||
case "nprofile":
|
case "nprofile":
|
||||||
tag = ["e", decoded.data.pubkey];
|
tag = ["e", decoded.data.pubkey];
|
||||||
if (decoded.data.relays && decoded.data.relays.length > 0)
|
if (decoded.data.relays && decoded.data.relays.length > 0)
|
||||||
tag.push(decoded.data.relays[0]);
|
tag.push(decoded.data.relays[0] as string);
|
||||||
return tag;
|
return tag;
|
||||||
case "nevent":
|
case "nevent":
|
||||||
tag = ["e", decoded.data.id];
|
tag = ["e", decoded.data.id];
|
||||||
if (decoded.data.relays && decoded.data.relays.length > 0)
|
if (decoded.data.relays && decoded.data.relays.length > 0)
|
||||||
tag.push(decoded.data.relays[0]);
|
tag.push(decoded.data.relays[0] as string);
|
||||||
return tag;
|
return tag;
|
||||||
case "naddr":
|
case "naddr":
|
||||||
tag = [
|
tag = [
|
||||||
@ -27,7 +27,7 @@ export function nip19ToTag(nip19Id: string): string[] | undefined {
|
|||||||
`${decoded.data.kind}:${decoded.data.pubkey}:${decoded.data.identifier}`,
|
`${decoded.data.kind}:${decoded.data.pubkey}:${decoded.data.identifier}`,
|
||||||
];
|
];
|
||||||
if (decoded.data.relays && decoded.data.relays.length > 0) {
|
if (decoded.data.relays && decoded.data.relays.length > 0) {
|
||||||
tag.push(decoded.data.relays[0]);
|
tag.push(decoded.data.relays[0] as string);
|
||||||
}
|
}
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
@ -35,12 +35,12 @@ export function nip19ToTag(nip19Id: string): string[] | undefined {
|
|||||||
|
|
||||||
export function aTagToNip19(aTag: string[]): string {
|
export function aTagToNip19(aTag: string[]): string {
|
||||||
if (aTag[0] !== "a") throw new Error("Not an a tag");
|
if (aTag[0] !== "a") throw new Error("Not an a tag");
|
||||||
const tagIdSplit = aTag[1].split(":");
|
const tagIdSplit = aTag[1]!.split(":");
|
||||||
|
|
||||||
return nip19.naddrEncode({
|
return nip19.naddrEncode({
|
||||||
kind: parseInt(tagIdSplit[0]),
|
kind: parseInt(tagIdSplit[0] as string),
|
||||||
pubkey: tagIdSplit[1],
|
pubkey: tagIdSplit[1] as string,
|
||||||
identifier: tagIdSplit[2],
|
identifier: tagIdSplit[2] as string,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
export const getTagValues = (name: string, tags: string[][]) => {
|
export const getTagValues = (name: string, tags: string[][]) => {
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/typography": "^0.5.10",
|
"@tailwindcss/typography": "^0.5.10",
|
||||||
|
"@total-typescript/ts-reset": "^0.5.1",
|
||||||
"@types/crypto-js": "^4.1.2",
|
"@types/crypto-js": "^4.1.2",
|
||||||
"@types/node": "^20",
|
"@types/node": "^20",
|
||||||
"@types/ramda": "^0.29.6",
|
"@types/ramda": "^0.29.6",
|
||||||
|
1
reset.d.ts
vendored
Normal file
1
reset.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
import "@total-typescript/ts-reset";
|
@ -14,6 +14,7 @@
|
|||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
"jsx": "preserve",
|
"jsx": "preserve",
|
||||||
"incremental": true,
|
"incremental": true,
|
||||||
|
"noUncheckedIndexedAccess": true,
|
||||||
"plugins": [
|
"plugins": [
|
||||||
{
|
{
|
||||||
"name": "next"
|
"name": "next"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user