forked from Kieran/zap.stream
Merge pull request 'fix: don't reset follow list' (#40) from uifix into main
Reviewed-on: Kieran/stream#40
This commit is contained in:
commit
cd55b0f048
@ -11,18 +11,21 @@ export function LoggedInFollowButton({
|
|||||||
loggedIn: string;
|
loggedIn: string;
|
||||||
pubkey: string;
|
pubkey: string;
|
||||||
}) {
|
}) {
|
||||||
const { contacts, relays } = useFollows(loggedIn, true);
|
|
||||||
const login = useLogin();
|
const login = useLogin();
|
||||||
const isFollowing = contacts.find((t) => t.at(1) === pubkey);
|
const following = useFollows(loggedIn, true);
|
||||||
|
const { tags, relays } = following ? following : { tags: [], relays: {} }
|
||||||
|
const follows = tags.filter((t) => t.at(0) === "p")
|
||||||
|
const isFollowing = follows.find((t) => t.at(1) === pubkey);
|
||||||
|
|
||||||
async function unfollow() {
|
async function unfollow() {
|
||||||
const pub = login?.publisher();
|
const pub = login?.publisher();
|
||||||
if (pub) {
|
if (pub) {
|
||||||
const ev = await pub.generic((eb) => {
|
const ev = await pub.generic((eb) => {
|
||||||
eb.kind(EventKind.ContactList).content(JSON.stringify(relays));
|
eb.kind(EventKind.ContactList).content(JSON.stringify(relays));
|
||||||
for (const c of contacts) {
|
for (const t of tags) {
|
||||||
if (c.at(1) !== pubkey) {
|
const isFollow = t.at(0) === "p" && t.at(1) === pubkey
|
||||||
eb.tag(c);
|
if (!isFollow) {
|
||||||
|
eb.tag(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return eb;
|
return eb;
|
||||||
@ -37,7 +40,7 @@ export function LoggedInFollowButton({
|
|||||||
if (pub) {
|
if (pub) {
|
||||||
const ev = await pub.generic((eb) => {
|
const ev = await pub.generic((eb) => {
|
||||||
eb.kind(EventKind.ContactList).content(JSON.stringify(relays));
|
eb.kind(EventKind.ContactList).content(JSON.stringify(relays));
|
||||||
for (const tag of contacts) {
|
for (const tag of tags) {
|
||||||
eb.tag(tag);
|
eb.tag(tag);
|
||||||
}
|
}
|
||||||
eb.tag(["p", pubkey]);
|
eb.tag(["p", pubkey]);
|
||||||
@ -50,6 +53,7 @@ export function LoggedInFollowButton({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<AsyncButton
|
<AsyncButton
|
||||||
|
disabled={!following}
|
||||||
type="button"
|
type="button"
|
||||||
className="btn btn-primary"
|
className="btn btn-primary"
|
||||||
onClick={isFollowing ? unfollow : follow}
|
onClick={isFollowing ? unfollow : follow}
|
||||||
|
@ -108,6 +108,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.top-zappers {
|
.top-zappers {
|
||||||
|
@ -17,6 +17,7 @@ import { useLiveChatFeed } from "../hooks/live-chat";
|
|||||||
import { Profile } from "./profile";
|
import { Profile } from "./profile";
|
||||||
import { Icon } from "./icon";
|
import { Icon } from "./icon";
|
||||||
import Spinner from "./spinner";
|
import Spinner from "./spinner";
|
||||||
|
import { Text } from "./text";
|
||||||
import { useLogin } from "../hooks/login";
|
import { useLogin } from "../hooks/login";
|
||||||
import { formatSats } from "../number";
|
import { formatSats } from "../number";
|
||||||
import useTopZappers from "../hooks/top-zappers";
|
import useTopZappers from "../hooks/top-zappers";
|
||||||
@ -201,7 +202,11 @@ function ChatZap({ zap }: { zap: ParsedZap }) {
|
|||||||
<span className="zap-amount">{formatSats(zap.amount)}</span>
|
<span className="zap-amount">{formatSats(zap.amount)}</span>
|
||||||
sats
|
sats
|
||||||
</div>
|
</div>
|
||||||
{zap.content && <div className="zap-content">{zap.content}</div>}
|
{zap.content && (
|
||||||
|
<div className="zap-content">
|
||||||
|
<Text content={zap.content} tags={[]} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,6 @@ export default function useFollows(pubkey: string, leaveOpen = false) {
|
|||||||
sub
|
sub
|
||||||
);
|
);
|
||||||
|
|
||||||
const contacts = (data?.tags ?? []).filter((t) => t.at(0) === "p");
|
|
||||||
const relays = JSON.parse(data?.content ?? "{}");
|
const relays = JSON.parse(data?.content ?? "{}");
|
||||||
|
return data ? { tags: data.tags, relays } : null
|
||||||
return { contacts, relays };
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user