add sorting by tags

This commit is contained in:
Sebastian Korotkiewicz 2023-10-20 03:16:32 +02:00
parent 1e1c675a7a
commit 42434a4486
Signed by: skorotkiewicz
GPG key ID: 5BDC557B496BDB0D
4 changed files with 39 additions and 1 deletions

View file

@ -16,6 +16,7 @@ import { getLoginKeys } from "./utils";
import { useNostr } from "./context/NostrProvider"; import { useNostr } from "./context/NostrProvider";
import Sniped from "./pages/Sniped"; import Sniped from "./pages/Sniped";
import { Loading } from "./components/Loading"; import { Loading } from "./components/Loading";
import SnipByTag from "./pages/SnipByTag";
export default function App() { export default function App() {
const [keypair, setKeypair] = useAtom("keypair"); const [keypair, setKeypair] = useAtom("keypair");
@ -41,6 +42,7 @@ export default function App() {
<Routes> <Routes>
<Route path="/" element={<Layout />}> <Route path="/" element={<Layout />}>
<Route index element={<Home />} /> <Route index element={<Home />} />
<Route path="lang/:lang" element={<SnipByTag />} />
<Route path="about" element={<About />} /> <Route path="about" element={<About />} />
<Route path="profile?/:id" element={<Profile />} /> <Route path="profile?/:id" element={<Profile />} />
<Route path="snip?/:id" element={<Sniped />} /> <Route path="snip?/:id" element={<Sniped />} />

View file

@ -33,7 +33,11 @@ const Editor = () => {
sendSignEvent({ sendSignEvent({
kind: 1, kind: 1,
keypair, keypair,
tags: [["t", TOPIC]], // tags: [["t", TOPIC]],
tags: [
["t", TOPIC],
["l", mode],
],
content: JSON.stringify({ snip, mode, fileName }), content: JSON.stringify({ snip, mode, fileName }),
publish, publish,
}).then(() => { }).then(() => {

View file

@ -50,6 +50,8 @@ const Snip = ({ events }) => {
{shortPubKey(data.pubkey, 7)} {shortPubKey(data.pubkey, 7)}
</Link> </Link>
</p> </p>
<Link to={`/lang/${s.mode}`}>#{s.mode}</Link>
</div> </div>
); );
})} })}

30
src/pages/SnipByTag.jsx Normal file
View file

@ -0,0 +1,30 @@
import { useParams } from "react-router-dom";
import { Loading } from "../components/Loading";
import Snip from "../components/Snip";
import { TOPIC } from "../config";
import { useNostrEvents } from "../context/NostrProvider";
const SnipByTag = () => {
const { lang } = useParams();
const { events, isLoading } = useNostrEvents({
filter: {
// since: dateToUnix(now.current),
// until: dateToUnix(now.current),
kinds: [1],
"#t": [TOPIC],
"#l": [lang],
limit: 100,
},
});
return (
<div>
<h2>#{lang}</h2>
{isLoading ? <Loading /> : <Snip events={events} />}
</div>
);
};
export default SnipByTag;