feat: add trending notes column
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
"@columns/hashtag": "workspace:^",
|
"@columns/hashtag": "workspace:^",
|
||||||
"@columns/thread": "workspace:^",
|
"@columns/thread": "workspace:^",
|
||||||
"@columns/timeline": "workspace:^",
|
"@columns/timeline": "workspace:^",
|
||||||
|
"@columns/trending-notes": "workspace:^",
|
||||||
"@columns/user": "workspace:^",
|
"@columns/user": "workspace:^",
|
||||||
"@getalby/sdk": "^3.2.3",
|
"@getalby/sdk": "^3.2.3",
|
||||||
"@lume/ark": "workspace:^",
|
"@lume/ark": "workspace:^",
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 103 KiB |
BIN
apps/desktop/public/columns/trending-notes.jpg
Normal file
BIN
apps/desktop/public/columns/trending-notes.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 102 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 381 KiB After Width: | Height: | Size: 381 KiB |
@@ -5,6 +5,7 @@ import { Group } from "@columns/group";
|
|||||||
import { Hashtag } from "@columns/hashtag";
|
import { Hashtag } from "@columns/hashtag";
|
||||||
import { Thread } from "@columns/thread";
|
import { Thread } from "@columns/thread";
|
||||||
import { Timeline } from "@columns/timeline";
|
import { Timeline } from "@columns/timeline";
|
||||||
|
import { TrendingNotes } from "@columns/trending-notes";
|
||||||
import { User } from "@columns/user";
|
import { User } from "@columns/user";
|
||||||
import { useColumnContext } from "@lume/ark";
|
import { useColumnContext } from "@lume/ark";
|
||||||
import {
|
import {
|
||||||
@@ -45,6 +46,8 @@ export function HomeScreen() {
|
|||||||
return <Group key={column.id} column={column} />;
|
return <Group key={column.id} column={column} />;
|
||||||
case COL_TYPES.antenas:
|
case COL_TYPES.antenas:
|
||||||
return <Antenas key={column.id} column={column} />;
|
return <Antenas key={column.id} column={column} />;
|
||||||
|
case COL_TYPES.trendingNotes:
|
||||||
|
return <TrendingNotes key={column.id} column={column} />;
|
||||||
default:
|
default:
|
||||||
return <Default key={column.id} column={column} />;
|
return <Default key={column.id} column={column} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,10 @@ export class Ark {
|
|||||||
return sub;
|
return sub;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getNDKEvent(event: NostrEvent) {
|
||||||
|
return new NDKEvent(this.ndk, event);
|
||||||
|
}
|
||||||
|
|
||||||
public async createEvent({
|
public async createEvent({
|
||||||
kind,
|
kind,
|
||||||
tags,
|
tags,
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ export function ColumnHeader({
|
|||||||
className="inline-flex items-center gap-3 px-3 text-sm font-medium text-red-500 rounded-lg h-9 hover:bg-red-500 hover:text-red-50 focus:outline-none"
|
className="inline-flex items-center gap-3 px-3 text-sm font-medium text-red-500 rounded-lg h-9 hover:bg-red-500 hover:text-red-50 focus:outline-none"
|
||||||
>
|
>
|
||||||
<TrashIcon className="size-4" />
|
<TrashIcon className="size-4" />
|
||||||
{t("global.Delete")}
|
{t("global.delete")}
|
||||||
</button>
|
</button>
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
</DropdownMenu.Content>
|
</DropdownMenu.Content>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Column, useColumnContext } from "@lume/ark";
|
import { Column, useColumnContext } from "@lume/ark";
|
||||||
import { ColumnIcon } from "@lume/icons";
|
|
||||||
import { IColumn } from "@lume/types";
|
import { IColumn } from "@lume/types";
|
||||||
import { COL_TYPES } from "@lume/utils";
|
import { COL_TYPES } from "@lume/utils";
|
||||||
|
|
||||||
@@ -8,11 +7,7 @@ export function Default({ column }: { column: IColumn }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Column.Root>
|
<Column.Root>
|
||||||
<Column.Header
|
<Column.Header id={column.id} title="Add columns" />
|
||||||
id={column.id}
|
|
||||||
title="Add columns"
|
|
||||||
icon={<ColumnIcon className="size-4" />}
|
|
||||||
/>
|
|
||||||
<div className="h-full px-3 mt-3 flex flex-col gap-3 overflow-y-auto scrollbar-none">
|
<div className="h-full px-3 mt-3 flex flex-col gap-3 overflow-y-auto scrollbar-none">
|
||||||
<div className="h-11 flex items-center gap-5">
|
<div className="h-11 flex items-center gap-5">
|
||||||
<button
|
<button
|
||||||
@@ -87,6 +82,39 @@ export function Default({ column }: { column: IColumn }) {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex flex-col rounded-xl overflow-hidden bg-neutral-50 dark:bg-neutral-950 ring-1 ring-neutral-100 dark:ring-neutral-900">
|
||||||
|
<div className="h-[100px] w-full px-3 pt-3">
|
||||||
|
<img
|
||||||
|
src="/columns/trending-notes.jpg"
|
||||||
|
srcSet="/columns/trending-notes@2x.jpg 2x"
|
||||||
|
alt="trendingNotes"
|
||||||
|
loading="lazy"
|
||||||
|
decoding="async"
|
||||||
|
className="w-full h-auto object-cover rounded-lg"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="h-16 shrink-0 px-3 flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<h1 className="font-semibold">Trending Notes</h1>
|
||||||
|
<p className="max-w-[18rem] truncate text-sm text-neutral-600 dark:text-neutral-500">
|
||||||
|
What is trending on Nostr?
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
addColumn({
|
||||||
|
kind: COL_TYPES.trendingNotes,
|
||||||
|
title: "",
|
||||||
|
content: "",
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
className="shrink-0 w-16 h-8 rounded-lg text-sm font-semibold bg-neutral-100 dark:bg-neutral-900 text-blue-500 hover:bg-neutral-200 dark:hover:bg-neutral-800 inline-flex items-center justify-center"
|
||||||
|
>
|
||||||
|
Add
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Column.Root>
|
</Column.Root>
|
||||||
);
|
);
|
||||||
|
|||||||
26
packages/lume-column-trending-notes/package.json
Normal file
26
packages/lume-column-trending-notes/package.json
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"name": "@columns/trending-notes",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"main": "./src/index.tsx",
|
||||||
|
"dependencies": {
|
||||||
|
"@lume/ark": "workspace:^",
|
||||||
|
"@lume/icons": "workspace:^",
|
||||||
|
"@lume/ui": "workspace:^",
|
||||||
|
"@lume/utils": "workspace:^",
|
||||||
|
"@nostr-dev-kit/ndk": "^2.3.3",
|
||||||
|
"@tanstack/react-query": "^5.17.19",
|
||||||
|
"react": "^18.2.0",
|
||||||
|
"react-router-dom": "^6.21.3",
|
||||||
|
"sonner": "^1.3.1",
|
||||||
|
"virtua": "^0.21.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@lume/tailwindcss": "workspace:^",
|
||||||
|
"@lume/tsconfig": "workspace:^",
|
||||||
|
"@lume/types": "workspace:^",
|
||||||
|
"@types/react": "^18.2.48",
|
||||||
|
"tailwind": "^4.0.0",
|
||||||
|
"typescript": "^5.3.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
71
packages/lume-column-trending-notes/src/home.tsx
Normal file
71
packages/lume-column-trending-notes/src/home.tsx
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import { TextNote, useArk } from "@lume/ark";
|
||||||
|
import { LoaderIcon } from "@lume/icons";
|
||||||
|
import { type NDKEvent, type NostrEvent } from "@nostr-dev-kit/ndk";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { fetch } from "@tauri-apps/plugin-http";
|
||||||
|
import { useEffect, useMemo, useRef } from "react";
|
||||||
|
import { CacheSnapshot, VList, VListHandle } from "virtua";
|
||||||
|
|
||||||
|
export function HomeRoute({ colKey }: { colKey: string }) {
|
||||||
|
const ark = useArk();
|
||||||
|
const ref = useRef<VListHandle>();
|
||||||
|
const cacheKey = `${colKey}-vlist`;
|
||||||
|
|
||||||
|
const [offset, cache] = useMemo(() => {
|
||||||
|
const serialized = sessionStorage.getItem(cacheKey);
|
||||||
|
if (!serialized) return [];
|
||||||
|
return JSON.parse(serialized) as [number, CacheSnapshot];
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const { data, isLoading } = useQuery({
|
||||||
|
queryKey: [colKey],
|
||||||
|
queryFn: async ({ signal }: { signal: AbortSignal }) => {
|
||||||
|
const res = await fetch("https://api.nostr.band/v0/trending/notes", {
|
||||||
|
signal,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res) throw new Error("Failed to fetch trending notes");
|
||||||
|
|
||||||
|
const data = await res.json();
|
||||||
|
const events = data.notes.map((item: { event: NostrEvent }) =>
|
||||||
|
ark.getNDKEvent(item.event),
|
||||||
|
);
|
||||||
|
|
||||||
|
return events as NDKEvent[];
|
||||||
|
},
|
||||||
|
refetchOnMount: false,
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!ref.current) return;
|
||||||
|
const handle = ref.current;
|
||||||
|
|
||||||
|
if (offset) {
|
||||||
|
handle.scrollTo(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
sessionStorage.setItem(
|
||||||
|
cacheKey,
|
||||||
|
JSON.stringify([handle.scrollOffset, handle.cache]),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full h-full">
|
||||||
|
<VList ref={ref} cache={cache} overscan={2} className="flex-1 px-3">
|
||||||
|
{isLoading ? (
|
||||||
|
<div className="w-full flex h-16 items-center justify-center gap-2 px-3 py-1.5">
|
||||||
|
<LoaderIcon className="size-5 animate-spin" />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
data.map((item) => (
|
||||||
|
<TextNote key={item.id} event={item} className="mt-3" />
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</VList>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
23
packages/lume-column-trending-notes/src/index.tsx
Normal file
23
packages/lume-column-trending-notes/src/index.tsx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { Column } from "@lume/ark";
|
||||||
|
import { IColumn } from "@lume/types";
|
||||||
|
import { EventRoute, UserRoute } from "@lume/ui";
|
||||||
|
import { HomeRoute } from "./home";
|
||||||
|
|
||||||
|
export function TrendingNotes({ column }: { column: IColumn }) {
|
||||||
|
const colKey = `trending-notes-${column.id}`;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Column.Root>
|
||||||
|
<Column.Header
|
||||||
|
id={column.id}
|
||||||
|
queryKey={[colKey]}
|
||||||
|
title="Trending Notes"
|
||||||
|
/>
|
||||||
|
<Column.Content>
|
||||||
|
<Column.Route path="/" element={<HomeRoute colKey={colKey} />} />
|
||||||
|
<Column.Route path="/events/:id" element={<EventRoute />} />
|
||||||
|
<Column.Route path="/users/:id" element={<UserRoute />} />
|
||||||
|
</Column.Content>
|
||||||
|
</Column.Root>
|
||||||
|
);
|
||||||
|
}
|
||||||
8
packages/lume-column-trending-notes/tailwind.config.js
Normal file
8
packages/lume-column-trending-notes/tailwind.config.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import sharedConfig from "@lume/tailwindcss";
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
content: ["./src/**/*.{js,ts,jsx,tsx}"],
|
||||||
|
presets: [sharedConfig],
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
||||||
8
packages/lume-column-trending-notes/tsconfig.json
Normal file
8
packages/lume-column-trending-notes/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"extends": "@lume/tsconfig/base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "dist"
|
||||||
|
},
|
||||||
|
"include": ["src"],
|
||||||
|
"exclude": ["node_modules", "dist"]
|
||||||
|
}
|
||||||
@@ -57,9 +57,7 @@ export const COL_TYPES = {
|
|||||||
hashtag: 3,
|
hashtag: 3,
|
||||||
group: 4,
|
group: 4,
|
||||||
antenas: 5,
|
antenas: 5,
|
||||||
topic: 6,
|
|
||||||
trendingNotes: 9000,
|
trendingNotes: 9000,
|
||||||
trendingAccounts: 9001,
|
|
||||||
foryou: 9998,
|
foryou: 9998,
|
||||||
newsfeed: 9999,
|
newsfeed: 9999,
|
||||||
};
|
};
|
||||||
|
|||||||
107
pnpm-lock.yaml
generated
107
pnpm-lock.yaml
generated
@@ -84,6 +84,9 @@ importers:
|
|||||||
'@columns/timeline':
|
'@columns/timeline':
|
||||||
specifier: workspace:^
|
specifier: workspace:^
|
||||||
version: link:../../packages/lume-column-timeline
|
version: link:../../packages/lume-column-timeline
|
||||||
|
'@columns/trending-notes':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../../packages/lume-column-trending-notes
|
||||||
'@columns/user':
|
'@columns/user':
|
||||||
specifier: workspace:^
|
specifier: workspace:^
|
||||||
version: link:../../packages/lume-column-user
|
version: link:../../packages/lume-column-user
|
||||||
@@ -798,6 +801,110 @@ importers:
|
|||||||
specifier: ^5.3.3
|
specifier: ^5.3.3
|
||||||
version: 5.3.3
|
version: 5.3.3
|
||||||
|
|
||||||
|
packages/lume-column-trending-notes:
|
||||||
|
dependencies:
|
||||||
|
'@lume/ark':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../ark
|
||||||
|
'@lume/icons':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../icons
|
||||||
|
'@lume/ui':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../ui
|
||||||
|
'@lume/utils':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../utils
|
||||||
|
'@nostr-dev-kit/ndk':
|
||||||
|
specifier: ^2.3.3
|
||||||
|
version: 2.3.3(typescript@5.3.3)
|
||||||
|
'@tanstack/react-query':
|
||||||
|
specifier: ^5.17.19
|
||||||
|
version: 5.17.19(react@18.2.0)
|
||||||
|
react:
|
||||||
|
specifier: ^18.2.0
|
||||||
|
version: 18.2.0
|
||||||
|
react-router-dom:
|
||||||
|
specifier: ^6.21.3
|
||||||
|
version: 6.21.3(react-dom@18.2.0)(react@18.2.0)
|
||||||
|
sonner:
|
||||||
|
specifier: ^1.3.1
|
||||||
|
version: 1.3.1(react-dom@18.2.0)(react@18.2.0)
|
||||||
|
virtua:
|
||||||
|
specifier: ^0.21.1
|
||||||
|
version: 0.21.1(react-dom@18.2.0)(react@18.2.0)
|
||||||
|
devDependencies:
|
||||||
|
'@lume/tailwindcss':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../tailwindcss
|
||||||
|
'@lume/tsconfig':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../tsconfig
|
||||||
|
'@lume/types':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../types
|
||||||
|
'@types/react':
|
||||||
|
specifier: ^18.2.48
|
||||||
|
version: 18.2.48
|
||||||
|
tailwind:
|
||||||
|
specifier: ^4.0.0
|
||||||
|
version: 4.0.0
|
||||||
|
typescript:
|
||||||
|
specifier: ^5.3.3
|
||||||
|
version: 5.3.3
|
||||||
|
|
||||||
|
packages/lume-column-trending-users:
|
||||||
|
dependencies:
|
||||||
|
'@lume/ark':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../ark
|
||||||
|
'@lume/icons':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../icons
|
||||||
|
'@lume/ui':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../ui
|
||||||
|
'@lume/utils':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../utils
|
||||||
|
'@nostr-dev-kit/ndk':
|
||||||
|
specifier: ^2.3.3
|
||||||
|
version: 2.3.3(typescript@5.3.3)
|
||||||
|
'@tanstack/react-query':
|
||||||
|
specifier: ^5.17.19
|
||||||
|
version: 5.17.19(react@18.2.0)
|
||||||
|
react:
|
||||||
|
specifier: ^18.2.0
|
||||||
|
version: 18.2.0
|
||||||
|
react-router-dom:
|
||||||
|
specifier: ^6.21.3
|
||||||
|
version: 6.21.3(react-dom@18.2.0)(react@18.2.0)
|
||||||
|
sonner:
|
||||||
|
specifier: ^1.3.1
|
||||||
|
version: 1.3.1(react-dom@18.2.0)(react@18.2.0)
|
||||||
|
virtua:
|
||||||
|
specifier: ^0.21.1
|
||||||
|
version: 0.21.1(react-dom@18.2.0)(react@18.2.0)
|
||||||
|
devDependencies:
|
||||||
|
'@lume/tailwindcss':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../tailwindcss
|
||||||
|
'@lume/tsconfig':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../tsconfig
|
||||||
|
'@lume/types':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../types
|
||||||
|
'@types/react':
|
||||||
|
specifier: ^18.2.48
|
||||||
|
version: 18.2.48
|
||||||
|
tailwind:
|
||||||
|
specifier: ^4.0.0
|
||||||
|
version: 4.0.0
|
||||||
|
typescript:
|
||||||
|
specifier: ^5.3.3
|
||||||
|
version: 5.3.3
|
||||||
|
|
||||||
packages/lume-column-user:
|
packages/lume-column-user:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@lume/ark':
|
'@lume/ark':
|
||||||
|
|||||||
Reference in New Issue
Block a user