adding sricter ts rules means lots of clean up ;}

This commit is contained in:
zmeyer44 2023-10-15 22:55:33 -04:00
parent 7a6d2c813c
commit 5a3003abe5
16 changed files with 42 additions and 30 deletions

View File

@ -39,7 +39,7 @@ export default function ProfilePage({
<div className="mx-auto max-w-5xl p-0">
<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]">
{!!profile.banner && (
{!!profile?.banner && (
<Image
className="absolute inset-0 h-full w-full object-cover align-middle"
src={
@ -56,7 +56,7 @@ export default function ProfilePage({
</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="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
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"
@ -84,15 +84,15 @@ export default function ProfilePage({
<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">
<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>
{!!profile.nip05 && (
{!!profile?.nip05 && (
<HiCheckBadge className="h-5 w-5 text-primary lg:h-7 lg:w-7" />
)}
</div>
<div className="flex items-center text-xs text-muted-foreground/80 md:text-sm">
{!!profile.name && <p>{profile.name}</p>}
{!!profile.name && !!profile.nip05 && (
{!!profile?.name && <p>{profile.name}</p>}
{!!profile?.name && !!profile.nip05 && (
<>
<div className="inline-flex px-1">·</div>
<p>{profile.nip05}</p>
@ -100,7 +100,7 @@ export default function ProfilePage({
)}
</div>
<div className="pt-1 md:pt-2">
{!!profile.about && (
{!!profile?.about && (
<p className="line-clamp-3 text-xs text-muted-foreground md:text-sm">
{profile.about}
</p>

View File

@ -54,8 +54,9 @@ export const Users = (ndk: NDK | undefined) => {
}
function getProfile(id: string) {
if (users[id]) {
return users[id].profile!;
const user = users[id];
if (user) {
return user.profile;
} else {
fetchUser(id);
}

View File

@ -56,8 +56,8 @@ interface NDKContext {
}
| undefined,
) => Promise<undefined | NDKEvent>;
getUser: (_: string) => NDKUser;
getProfile: (_: string) => NDKUserProfile;
getUser: (_: string) => NDKUser | undefined;
getProfile: (_: string) => NDKUserProfile | undefined;
}
const NDKContext = createContext<NDKContext>({

View File

@ -46,7 +46,7 @@ export const parseContent = ({
// Convert legacy mentions to bech32 entities
const mentionMatch = text.match(/^#\[(\d+)\]/i);
if (mentionMatch) {
if (mentionMatch && mentionMatch[1]) {
const i = parseInt(mentionMatch[1]);
if (tags[i]) {

BIN
bun.lockb

Binary file not shown.

View File

@ -13,7 +13,7 @@ import { BANNER } from "@/constants/app";
import { getNameToShow } from "@/lib/utils";
type CreatorCardProps = {
profile: NDKUserProfile;
profile?: NDKUserProfile;
npub: string;
recentWork: {
id: string;

View File

@ -10,7 +10,7 @@ import { toast } from "sonner";
export default function Kind1(props: Event) {
const { content, pubkey, tags } = props;
const r = getTagsValues("r", tags);
const r = getTagsValues("r", tags).filter(Boolean);
const npub = nip19.npubEncode(pubkey);
return (

View File

@ -8,7 +8,9 @@ import { removeDuplicates } from "@/lib/utils";
export default function Kind30023({ content, pubkey, tags }: Event) {
const title = getTagValues("title", tags);
const summary = getTagValues("summary", tags);
const contentTags = removeDuplicates(getTagsValues("t", tags));
const contentTags = removeDuplicates(getTagsValues("t", tags)).filter(
Boolean,
);
return (
<Container pubkey={pubkey} contentTags={contentTags}>

View File

@ -14,7 +14,7 @@ export default function ProfileHeader({ pubkey }: ProfileHeaderProps) {
return (
<Link href={`/${npub}`} className="center group gap-x-3">
<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">
{getTwoLetters({ npub, profile })}
</AvatarFallback>
@ -23,7 +23,7 @@ export default function ProfileHeader({ pubkey }: ProfileHeaderProps) {
<span className="text-xs uppercase text-muted-foreground group-hover:underline">
{getNameToShow({ npub, profile })}
</span>
{!!profile.nip05 && <HiCheckBadge className="h-4 w-4 text-primary" />}
{!!profile?.nip05 && <HiCheckBadge className="h-4 w-4 text-primary" />}
</div>
</Link>
);

View File

@ -50,12 +50,16 @@ const RenderText = ({ text }: { text?: string }) => {
// specialElement = <span className="">{specialValuesArray[index]}</span>;
} else if (specialValuesArray[index]?.match(nostrPrefixRegex)) {
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} />;
} else if (
mention.startsWith("nevent") ||
mention &&
(mention.startsWith("nevent") ||
mention.startsWith("note") ||
mention.startsWith("naddr")
mention.startsWith("naddr"))
) {
specialElement = <EventMention mention={mention} />;
}

View File

@ -64,9 +64,11 @@ export default function useCurrentUser() {
window.location.reload();
}
function handleUpdateUser(userInfo: string) {
const userObject = UserSchema.safeParse(JSON.parse(userInfo));
if (!userObject.success) return;
const parsedData = UserSchema.safeParse({
...currentUser,
...JSON.parse(userInfo),
...userObject,
});
if (parsedData.success) {
updateCurrentUser({

View File

@ -12,7 +12,7 @@ function useLocalStorage<T>(key: string, initialValue: T) {
// Get from local storage by key
const item = window.localStorage.getItem(key);
// Parse stored json or if none return initialValue
return item ? JSON.parse(item) : initialValue;
return item ? (JSON.parse(item) as T) : initialValue;
} catch (error) {
// If error also return initialValue
console.log(error);

View File

@ -14,12 +14,12 @@ export function nip19ToTag(nip19Id: string): string[] | undefined {
case "nprofile":
tag = ["e", decoded.data.pubkey];
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;
case "nevent":
tag = ["e", decoded.data.id];
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;
case "naddr":
tag = [
@ -27,7 +27,7 @@ export function nip19ToTag(nip19Id: string): string[] | undefined {
`${decoded.data.kind}:${decoded.data.pubkey}:${decoded.data.identifier}`,
];
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;
}
@ -35,12 +35,12 @@ export function nip19ToTag(nip19Id: string): string[] | undefined {
export function aTagToNip19(aTag: string[]): string {
if (aTag[0] !== "a") throw new Error("Not an a tag");
const tagIdSplit = aTag[1].split(":");
const tagIdSplit = aTag[1]!.split(":");
return nip19.naddrEncode({
kind: parseInt(tagIdSplit[0]),
pubkey: tagIdSplit[1],
identifier: tagIdSplit[2],
kind: parseInt(tagIdSplit[0] as string),
pubkey: tagIdSplit[1] as string,
identifier: tagIdSplit[2] as string,
});
}
export const getTagValues = (name: string, tags: string[][]) => {

View File

@ -53,6 +53,7 @@
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.10",
"@total-typescript/ts-reset": "^0.5.1",
"@types/crypto-js": "^4.1.2",
"@types/node": "^20",
"@types/ramda": "^0.29.6",

1
reset.d.ts vendored Normal file
View File

@ -0,0 +1 @@
import "@total-typescript/ts-reset";

View File

@ -14,6 +14,7 @@
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"noUncheckedIndexedAccess": true,
"plugins": [
{
"name": "next"