feat: Trending users @ghobs91
This commit is contained in:
parent
4afdd5afd4
commit
d309bfd472
@ -5,6 +5,7 @@ import { HexKey } from "@snort/nostr";
|
|||||||
import useEventPublisher from "Feed/EventPublisher";
|
import useEventPublisher from "Feed/EventPublisher";
|
||||||
import { parseId } from "Util";
|
import { parseId } from "Util";
|
||||||
import useLogin from "Hooks/useLogin";
|
import useLogin from "Hooks/useLogin";
|
||||||
|
import AsyncButton from "Element/AsyncButton";
|
||||||
|
|
||||||
import messages from "./messages";
|
import messages from "./messages";
|
||||||
|
|
||||||
@ -37,11 +38,10 @@ export default function FollowButton(props: FollowButtonProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<AsyncButton
|
||||||
type="button"
|
|
||||||
className={isFollowing ? `${baseClassname} secondary` : baseClassname}
|
className={isFollowing ? `${baseClassname} secondary` : baseClassname}
|
||||||
onClick={() => (isFollowing ? unfollow(pubkey) : follow(pubkey))}>
|
onClick={() => (isFollowing ? unfollow(pubkey) : follow(pubkey))}>
|
||||||
{isFollowing ? <FormattedMessage {...messages.Unfollow} /> : <FormattedMessage {...messages.Follow} />}
|
{isFollowing ? <FormattedMessage {...messages.Unfollow} /> : <FormattedMessage {...messages.Follow} />}
|
||||||
</button>
|
</AsyncButton>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
52
packages/app/src/Element/TrendingUsers.tsx
Normal file
52
packages/app/src/Element/TrendingUsers.tsx
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { HexKey } from "@snort/nostr";
|
||||||
|
import { FormattedMessage } from "react-intl";
|
||||||
|
|
||||||
|
import FollowListBase from "Element/FollowListBase";
|
||||||
|
import PageSpinner from "Element/PageSpinner";
|
||||||
|
|
||||||
|
interface TrendingUser {
|
||||||
|
pubkey: HexKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TrendingUserResponse {
|
||||||
|
profiles: Array<TrendingUser>;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchTrendingUsers() {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`https://api.nostr.band/v0/trending/profiles`);
|
||||||
|
if (res.ok) {
|
||||||
|
const data = (await res.json()) as TrendingUserResponse;
|
||||||
|
return data.profiles.map(a => a.pubkey);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`Failed to load link preview`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const TrendingUsers = () => {
|
||||||
|
const [userList, setUserList] = useState<HexKey[]>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
const data = await fetchTrendingUsers();
|
||||||
|
if (data) {
|
||||||
|
setUserList(data);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!userList) return <PageSpinner />;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h3>
|
||||||
|
<FormattedMessage defaultMessage="Trending Users" />
|
||||||
|
</h3>
|
||||||
|
<FollowListBase pubkeys={userList} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TrendingUsers;
|
@ -9,6 +9,7 @@ import { SearchRelays } from "Const";
|
|||||||
import { System } from "System";
|
import { System } from "System";
|
||||||
import { MetadataCache } from "Cache";
|
import { MetadataCache } from "Cache";
|
||||||
import { UserCache } from "Cache/UserCache";
|
import { UserCache } from "Cache/UserCache";
|
||||||
|
import TrendingUsers from "Element/TrendingUsers";
|
||||||
|
|
||||||
import messages from "./messages";
|
import messages from "./messages";
|
||||||
|
|
||||||
@ -64,6 +65,7 @@ const SearchPage = () => {
|
|||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{!keyword && <TrendingUsers />}
|
||||||
{keyword && allUsers?.slice(0, 3).map(u => <ProfilePreview actions={<></>} className="card" pubkey={u.pubkey} />)}
|
{keyword && allUsers?.slice(0, 3).map(u => <ProfilePreview actions={<></>} className="card" pubkey={u.pubkey} />)}
|
||||||
{keyword && (
|
{keyword && (
|
||||||
<Timeline
|
<Timeline
|
||||||
|
Loading…
x
Reference in New Issue
Block a user