feat: filter follow sets
This commit is contained in:
@ -1,10 +1,12 @@
|
|||||||
import { dedupe } from "@snort/shared";
|
import { dedupe } from "@snort/shared";
|
||||||
import { EventKind, NostrLink, RequestBuilder } from "@snort/system";
|
import { EventKind, NostrLink, RequestBuilder } from "@snort/system";
|
||||||
import { useRequestBuilder } from "@snort/system-react";
|
import { useRequestBuilder } from "@snort/system-react";
|
||||||
import { FormattedMessage } from "react-intl";
|
import { useState } from "react";
|
||||||
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
|
||||||
import AsyncButton from "@/Components/Button/AsyncButton";
|
import AsyncButton from "@/Components/Button/AsyncButton";
|
||||||
|
import { AutoLoadMore } from "@/Components/Event/LoadMore";
|
||||||
import { AvatarGroup } from "@/Components/User/AvatarGroup";
|
import { AvatarGroup } from "@/Components/User/AvatarGroup";
|
||||||
import DisplayName from "@/Components/User/DisplayName";
|
import DisplayName from "@/Components/User/DisplayName";
|
||||||
import { ProfileLink } from "@/Components/User/ProfileLink";
|
import { ProfileLink } from "@/Components/User/ProfileLink";
|
||||||
@ -15,15 +17,32 @@ import { findTag } from "@/Utils";
|
|||||||
export default function FollowSetsPage() {
|
export default function FollowSetsPage() {
|
||||||
const sub = new RequestBuilder("follow-sets");
|
const sub = new RequestBuilder("follow-sets");
|
||||||
sub.withFilter().kinds([EventKind.StarterPackSet, EventKind.FollowSet]);
|
sub.withFilter().kinds([EventKind.StarterPackSet, EventKind.FollowSet]);
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
const data = useRequestBuilder(sub);
|
const data = useRequestBuilder(sub);
|
||||||
const wot = useWoT();
|
const wot = useWoT();
|
||||||
const control = useFollowsControls();
|
const control = useFollowsControls();
|
||||||
const dataSorted = wot.sortEvents(data);
|
const dataSorted = wot.sortEvents(data);
|
||||||
|
const [showN, setShowN] = useState(10);
|
||||||
|
const [search, setSearch] = useState("");
|
||||||
|
|
||||||
|
const filtered = dataSorted.filter(s => {
|
||||||
|
if (search) {
|
||||||
|
const ss = search.toLowerCase();
|
||||||
|
return s.content.toLowerCase().includes(ss) || s.tags.some(t => t[1].toLowerCase().includes(ss));
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
return (
|
return (
|
||||||
<div className="p flex flex-col gap-4">
|
<div className="p flex flex-col gap-4">
|
||||||
{dataSorted.map(a => {
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder={formatMessage({ defaultMessage: "Search sets.." })}
|
||||||
|
value={search}
|
||||||
|
onChange={e => setSearch(e.target.value)}
|
||||||
|
/>
|
||||||
|
{filtered.slice(0, showN).map(a => {
|
||||||
const title = findTag(a, "title") ?? findTag(a, "d") ?? a.content;
|
const title = findTag(a, "title") ?? findTag(a, "d") ?? a.content;
|
||||||
const pTags = wot.sortPubkeys(dedupe(a.tags.filter(a => a[0] === "p").map(a => a[1])));
|
const pTags = wot.sortPubkeys(dedupe(a.tags.filter(a => a[0] === "p").map(a => a[1])));
|
||||||
const isFollowingAll = pTags.every(a => control.isFollowing(a));
|
const isFollowingAll = pTags.every(a => control.isFollowing(a));
|
||||||
@ -75,6 +94,7 @@ export default function FollowSetsPage() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
{filtered.length > showN && <AutoLoadMore onClick={() => setShowN(n => n + 10)} />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -474,6 +474,9 @@
|
|||||||
"9WRlF4": {
|
"9WRlF4": {
|
||||||
"defaultMessage": "Send"
|
"defaultMessage": "Send"
|
||||||
},
|
},
|
||||||
|
"9WTAKy": {
|
||||||
|
"defaultMessage": "Search sets.."
|
||||||
|
},
|
||||||
"9kO0VQ": {
|
"9kO0VQ": {
|
||||||
"defaultMessage": "Hide muted notes"
|
"defaultMessage": "Hide muted notes"
|
||||||
},
|
},
|
||||||
|
@ -157,6 +157,7 @@
|
|||||||
"9SvQep": "Follows {n}",
|
"9SvQep": "Follows {n}",
|
||||||
"9V0wg3": "Calendar Event RSVP",
|
"9V0wg3": "Calendar Event RSVP",
|
||||||
"9WRlF4": "Send",
|
"9WRlF4": "Send",
|
||||||
|
"9WTAKy": "Search sets..",
|
||||||
"9kO0VQ": "Hide muted notes",
|
"9kO0VQ": "Hide muted notes",
|
||||||
"9kSari": "Retry publishing",
|
"9kSari": "Retry publishing",
|
||||||
"9pMqYs": "Nostr Address",
|
"9pMqYs": "Nostr Address",
|
||||||
|
Reference in New Issue
Block a user