Fix follow and mute button not updating when switching accounts

This commit is contained in:
hzrd149 2023-09-19 07:23:05 -05:00
parent af973af93e
commit d5a50d0c6f
6 changed files with 15 additions and 8 deletions

View File

@ -0,0 +1,5 @@
---
"nostrudel": patch
---
Fix follow and mute button not updating when switching accounts

View File

@ -34,7 +34,6 @@ import useUserContactList from "../hooks/use-user-contact-list";
import replaceableEventLoaderService from "../services/replaceable-event-requester";
import useAsyncErrorHandler from "../hooks/use-async-error-handler";
import NewListModal from "../views/lists/components/new-list-modal";
import useUserMuteList from "../hooks/use-user-mute-list";
import useUserMuteFunctions from "../hooks/use-user-mute-functions";
function UsersLists({ pubkey }: { pubkey: string }) {
@ -129,13 +128,13 @@ export const UserFollowButton = ({ pubkey, showLists, ...props }: UserFollowButt
const signed = await requestSignature(draft);
const pub = new NostrPublishAction("Follow", clientRelaysService.getWriteUrls(), signed);
replaceableEventLoaderService.handleEvent(signed);
});
}, [contacts, requestSignature]);
const handleUnfollow = useAsyncErrorHandler(async () => {
const draft = draftRemovePerson(contacts || createEmptyContactList(), pubkey);
const signed = await requestSignature(draft);
const pub = new NostrPublishAction("Unfollow", clientRelaysService.getWriteUrls(), signed);
replaceableEventLoaderService.handleEvent(signed);
});
}, [contacts, requestSignature]);
if (showLists) {
return (

View File

@ -3,7 +3,7 @@ import { DependencyList, useCallback } from "react";
export default function useAsyncErrorHandler<T = any>(
fn: () => Promise<T>,
deps: DependencyList = [],
deps: DependencyList,
): () => Promise<T | undefined> {
const toast = useToast();

View File

@ -19,13 +19,13 @@ export default function useUserMuteFunctions(pubkey: string) {
const signed = await requestSignature(draft);
new NostrPublishAction("Mute", clientRelaysService.getWriteUrls(), signed);
replaceableEventLoaderService.handleEvent(signed);
});
}, [requestSignature, muteList]);
const unmute = useAsyncErrorHandler(async () => {
const draft = draftRemovePerson(muteList || createEmptyMuteList(), pubkey);
const signed = await requestSignature(draft);
new NostrPublishAction("Unmute", clientRelaysService.getWriteUrls(), signed);
replaceableEventLoaderService.handleEvent(signed);
});
}, [requestSignature, muteList]);
return { isMuted, mute, unmute };
}

View File

@ -26,6 +26,7 @@ import RelaySelectionProvider, { useRelaySelectionRelays } from "../../providers
import useRelaysChanged from "../../hooks/use-relays-changed";
import TimelinePage, { useTimelinePageEventFilter } from "../../components/timeline-page";
import TimelineViewTypeButtons from "../../components/timeline-page/timeline-view-type";
import useClientSideMuteFilter from "../../hooks/use-client-side-mute-filter";
function EditableControls() {
const { isEditing, getSubmitButtonProps, getCancelButtonProps, getEditButtonProps } = useEditableControls();
@ -52,12 +53,14 @@ function HashTagPage() {
const { isOpen: showReplies, onToggle } = useDisclosure();
const timelinePageEventFilter = useTimelinePageEventFilter();
const muteFilter = useClientSideMuteFilter();
const eventFilter = useCallback(
(event: NostrEvent) => {
if (muteFilter(event)) return false;
if (!showReplies && isReply(event)) return false;
return timelinePageEventFilter(event);
},
[showReplies],
[showReplies, muteFilter, timelinePageEventFilter],
);
const timeline = useTimelineLoader(
`${hashtag}-hashtag`,

View File

@ -26,7 +26,7 @@ export default function UserCard({ pubkey, relay, list, ...props }: UserCardProp
const draft = draftRemovePerson(list, pubkey);
const signed = await requestSignature(draft);
const pub = new NostrPublishAction("Remove from list", clientRelaysService.getWriteUrls(), signed);
}, [list]);
}, [list, requestSignature]);
return (
<Card>