temp remove threads

This commit is contained in:
Ren Amamiya
2023-06-07 13:30:50 +07:00
parent f00ed56a06
commit 2f3ea13613
10 changed files with 28 additions and 245 deletions

View File

@@ -74,12 +74,6 @@ export function Page() {
since: lastLogin,
});
// long post
query.push({
kinds: [30023],
since: lastLogin,
});
return query;
}, [account]);
@@ -169,19 +163,6 @@ export function Page() {
event.id,
);
break;
// long post
case 30023:
createNote(
event.id,
account.id,
event.pubkey,
event.kind,
event.tags,
event.content,
event.created_at,
event.id,
);
break;
default:
break;
}

View File

@@ -1 +0,0 @@
export { LayoutNewsfeed as Layout } from "./layout";

View File

@@ -1,38 +0,0 @@
import { Image } from "@shared/image";
import { DEFAULT_AVATAR } from "@stores/constants";
import { useProfile } from "@utils/hooks/useProfile";
import { shortenKey } from "@utils/shortenKey";
import dayjs from "dayjs";
export function ThreadAuthor({
pubkey,
time,
}: { pubkey: string; time: number }) {
const { user } = useProfile(pubkey);
return (
<div className="relative flex items-center gap-2.5">
<div className="h-9 w-9 shrink-0 overflow-hidden rounded-md bg-zinc-900">
<Image
src={user?.picture || DEFAULT_AVATAR}
alt={pubkey}
className="h-9 w-9 object-cover"
/>
</div>
<div className="flex w-full flex-1 items-start justify-between">
<div className="flex flex-col gap-0.5">
<h5 className="text-base font-semibold leading-none">
{user?.display_name || user?.name || (
<div className="h-3 w-20 animate-pulse rounded-sm bg-zinc-700" />
)}
</h5>
<div className="flex items-baseline gap-1.5 text-base leading-none text-zinc-500">
<span>{user?.nip05 || shortenKey(pubkey)}</span>
<span></span>
<span>{dayjs().to(dayjs.unix(time), true)}</span>
</div>
</div>
</div>
</div>
);
}

View File

@@ -1,40 +0,0 @@
import { ThreadAuthor } from "@app/threads/components/author";
import { Image } from "@shared/image";
export function ThreadBase({ event }: { event: any }) {
const metadata = JSON.parse(event.tags);
const title = metadata.find((i: any) => i[0] === "title")?.[1];
const summary = metadata.find((i: any) => i[0] === "summary")?.[1];
const image = metadata.find((i: any) => i[0] === "image")?.[1];
if (!title) {
return null;
}
return (
<div className="h-min w-full px-3 py-1.5">
<div className="rounded-md border border-zinc-800 bg-zinc-900 shadow-input shadow-black/20">
<div className="px-3 py-3">
<div className="flex flex-row gap-2">
<div className="flex-1">
<h3 className="text-white text-lg font-semibold">{title}</h3>
<div className="mt-2 markdown">
<p>{summary}</p>
</div>
</div>
<div className="shrink-0 w-32 h-32">
<Image
src={image}
alt={title}
className="w-32 h-32 rounded-md object-cover"
/>
</div>
</div>
</div>
<div className="inline-flex border-t border-zinc-800 w-full justify-between items-center px-3 h-16">
<ThreadAuthor pubkey={event.pubkey} time={event.created_at} />
</div>
</div>
</div>
);
}

View File

@@ -1,14 +0,0 @@
import { MultiAccounts } from "@shared/multiAccounts";
import { Navigation } from "@shared/navigation";
export function LayoutNewsfeed({ children }: { children: React.ReactNode }) {
return (
<div className="flex w-screen h-screen">
<div className="relative flex flex-row flex-wrap shrink-0">
<MultiAccounts />
<Navigation />
</div>
<div className="w-full h-full">{children}</div>
</div>
);
}

View File

@@ -1,103 +0,0 @@
import { NoteSkeleton } from "@app/note/components/skeleton";
import { ThreadBase } from "@app/threads/components/base";
import { useVirtualizer } from "@tanstack/react-virtual";
import { getLongNotes } from "@utils/storage";
import { useEffect, useMemo, useRef } from "react";
import useSWRInfinite from "swr/infinite";
const ITEM_PER_PAGE = 10;
const TIME = Math.floor(Date.now() / 1000);
const fetcher = async ([, offset]) => getLongNotes(TIME, ITEM_PER_PAGE, offset);
function isJSON(str: string) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
export function Page() {
const getKey = (pageIndex, previousPageData) => {
if (previousPageData && !previousPageData.data) return null;
if (pageIndex === 0) return ["following", 0];
return ["following", previousPageData.nextCursor];
};
const { data, isLoading, size, setSize } = useSWRInfinite(getKey, fetcher);
const notes = useMemo(
() => (data ? data.flatMap((d) => d.data) : []),
[data],
);
const parentRef = useRef();
const rowVirtualizer = useVirtualizer({
count: notes.length,
getScrollElement: () => parentRef.current,
estimateSize: () => 400,
overscan: 2,
});
const itemsVirtualizer = rowVirtualizer.getVirtualItems();
useEffect(() => {
const [lastItem] = [...rowVirtualizer.getVirtualItems()].reverse();
if (!lastItem) {
return;
}
if (lastItem.index >= notes.length - 1) {
setSize(size + 1);
}
}, [notes.length, rowVirtualizer.getVirtualItems()]);
return (
<div
ref={parentRef}
className="scrollbar-hide h-full overflow-y-auto"
style={{ contain: "strict" }}
>
{!data || isLoading ? (
<div className="px-3 py-1.5">
<div className="rounded-md border border-zinc-800 bg-zinc-900 px-3 py-3 shadow-input shadow-black/20">
<NoteSkeleton />
</div>
</div>
) : (
<div
className="relative w-full mt-2"
style={{
height: `${rowVirtualizer.getTotalSize()}px`,
}}
>
<div
className="absolute left-0 top-0 w-full"
style={{
transform: `translateY(${
itemsVirtualizer[0].start - rowVirtualizer.options.scrollMargin
}px)`,
}}
>
{rowVirtualizer.getVirtualItems().map((virtualRow) => {
const note = notes[virtualRow.index];
if (note && isJSON(note.tags)) {
return (
<div
key={virtualRow.index}
data-index={virtualRow.index}
ref={rowVirtualizer.measureElement}
>
<ThreadBase key={note.event_id} event={note} />
</div>
);
}
})}
</div>
</div>
)}
</div>
);
}