Setup lang
This commit is contained in:
@ -3,21 +3,19 @@ import { useLogin } from "hooks/login";
|
||||
import AsyncButton from "element/async-button";
|
||||
import { Login, System } from "index";
|
||||
import { MUTED } from "const";
|
||||
import { FormattedMessage } from "react-intl";
|
||||
|
||||
export function useMute(pubkey: string) {
|
||||
const login = useLogin();
|
||||
const { tags, content } = login?.muted ?? { tags: [] };
|
||||
const muted = useMemo(() => tags.filter((t) => t.at(0) === "p"), [tags]);
|
||||
const isMuted = useMemo(
|
||||
() => muted.find((t) => t.at(1) === pubkey),
|
||||
[pubkey, muted]
|
||||
);
|
||||
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();
|
||||
if (pub) {
|
||||
const newMuted = tags.filter((t) => t.at(1) !== pubkey);
|
||||
const ev = await pub.generic((eb) => {
|
||||
const newMuted = tags.filter(t => t.at(1) !== pubkey);
|
||||
const ev = await pub.generic(eb => {
|
||||
eb.kind(MUTED).content(content ?? "");
|
||||
for (const t of newMuted) {
|
||||
eb.tag(t);
|
||||
@ -34,7 +32,7 @@ export function useMute(pubkey: string) {
|
||||
const pub = login?.publisher();
|
||||
if (pub) {
|
||||
const newMuted = [...tags, ["p", pubkey]];
|
||||
const ev = await pub.generic((eb) => {
|
||||
const ev = await pub.generic(eb => {
|
||||
eb.kind(MUTED).content(content ?? "");
|
||||
for (const tag of newMuted) {
|
||||
eb.tag(tag);
|
||||
@ -54,12 +52,8 @@ export function LoggedInMuteButton({ pubkey }: { pubkey: string }) {
|
||||
const { isMuted, mute, unmute } = useMute(pubkey);
|
||||
|
||||
return (
|
||||
<AsyncButton
|
||||
type="button"
|
||||
className="btn delete-button"
|
||||
onClick={() => (isMuted ? unmute() : mute())}
|
||||
>
|
||||
{isMuted ? "Unmute" : "Mute"}
|
||||
<AsyncButton type="button" className="btn delete-button" onClick={() => (isMuted ? unmute() : mute())}>
|
||||
<FormattedMessage defaultMessage={isMuted ? "Unmute" : "Mute"} />
|
||||
</AsyncButton>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user