feat: in-chat mute button

resolves #73
This commit is contained in:
2023-08-04 18:28:08 +02:00
parent 22a799aac7
commit 78d9a2779a
5 changed files with 46 additions and 17 deletions

View File

@ -1,13 +1,17 @@
import { useMemo } from "react";
import { useLogin } from "hooks/login";
import AsyncButton from "element/async-button";
import { Login, System } from "index";
import { MUTED } from "const";
export function LoggedInMuteButton({ pubkey }: { pubkey: string }) {
export function useMute(pubkey: string) {
const login = useLogin();
const { tags, content } = login!.muted;
const muted = tags.filter((t) => t.at(0) === "p");
const isMuted = muted.find((t) => t.at(1) === pubkey);
const muted = useMemo(() => tags.filter((t) => t.at(0) === "p"), [tags]);
const isMuted = useMemo(
() => muted.find((t) => t.at(1) === pubkey),
[pubkey, muted]
);
async function unmute() {
const pub = login?.publisher();
@ -43,6 +47,12 @@ export function LoggedInMuteButton({ pubkey }: { pubkey: string }) {
}
}
return { isMuted, mute, unmute };
}
export function LoggedInMuteButton({ pubkey }: { pubkey: string }) {
const { isMuted, mute, unmute } = useMute(pubkey);
return (
<AsyncButton
type="button"