Skip to content

Commit

Permalink
https://github.com/ecency/vision-next/issues/230
Browse files Browse the repository at this point in the history
Fixed mute user profile statement
  • Loading branch information
dkildar committed Feb 1, 2025
1 parent 67cc5d3 commit df24b1d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
22 changes: 10 additions & 12 deletions src/api/mutations/account-following.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { broadcastPostingJSON, formatError } from "@/api/operations";
import { error } from "@/features/shared";
import { error, success } from "@/features/shared";
import { AccountRelationship } from "@/api/bridge";
import { QueryIdentifiers } from "@/core/react-query";
import * as ls from "@/utils/local-storage";
import i18next from "i18next";
import { useGetRelationshipBtwAccounts } from "../queries";

export function useFollow(follower: string, following: string) {
const queryClient = useQueryClient();
Expand All @@ -26,12 +27,6 @@ export function useFollow(follower: string, following: string) {
error(...formatError(err));
},
onSuccess: ([_, isFollow]) => {
let mutedList = ls.get("muted-list");
if (mutedList) {
mutedList = mutedList.filter((item: string) => item !== following);
}
ls.set("muted-list", mutedList);

queryClient.setQueryData<AccountRelationship | null>(
[QueryIdentifiers.GET_RELATIONSHIP_BETWEEN_ACCOUNTS, follower, following],
(data) => {
Expand All @@ -54,6 +49,8 @@ export function useFollow(follower: string, following: string) {
export function useIgnore(follower?: string, following?: string) {
const queryClient = useQueryClient();

const { data } = useGetRelationshipBtwAccounts(follower, following);

return useMutation({
mutationKey: ["follow-account", "ignore", follower, following],
mutationFn: () => {
Expand All @@ -73,9 +70,10 @@ export function useIgnore(follower?: string, following?: string) {
error(...formatError(err));
},
onSuccess: () => {
const mutedList = ls.get("muted-list");
if (mutedList) {
ls.set("muted-list", mutedList.concat([following]));
if (data?.ignores === true) {
success(i18next.t("events.unmuted"));
} else {
success(i18next.t("events.muted"));
}

queryClient.setQueryData<AccountRelationship | null>(
Expand All @@ -87,7 +85,7 @@ export function useIgnore(follower?: string, following?: string) {

return {
follows: data.follows,
ignores: true,
ignores: !data?.ignores,
is_blacklisted: data.is_blacklisted,
follows_blacklists: data.follows_blacklists
};
Expand Down
4 changes: 4 additions & 0 deletions src/features/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -2547,5 +2547,9 @@
"edit-wave": "Edit wave",
"reply": "Reply",
"replying": "Replying..."
},
"events": {
"muted": "User has muted",
"unmuted": "User has unmuted"
}
}
25 changes: 21 additions & 4 deletions src/features/shared/follow-controls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { useGlobalStore } from "@/core/global-store";
import { useFollow, useIgnore } from "@/api/mutations";
import i18next from "i18next";
import { LoginRequired } from "@/features/shared";
import { UilBell, UilBellSlash } from "@tooni/iconscout-unicons-react";
import { StyledTooltip } from "@ui/tooltip";

interface Props {
targetUsername: string;
Expand All @@ -20,13 +22,28 @@ interface ButtonProps {

function MuteButton({ disabled, following }: ButtonProps) {
const activeUser = useGlobalStore((state) => state.activeUser);
const { mutateAsync: ignore } = useIgnore(activeUser?.username, following);

const { data } = useGetRelationshipBtwAccounts(activeUser?.username, following);
const { mutateAsync: ignore, isPending } = useIgnore(activeUser?.username, following);

return activeUser?.username !== following ? (
<LoginRequired>
<Button size="sm" style={{ marginRight: "5px" }} disabled={disabled} onClick={() => ignore()}>
{i18next.t("follow-controls.mute")}
</Button>
<StyledTooltip
content={
data?.ignores === true ? i18next.t("entry-menu.unmute") : i18next.t("entry-menu.mute")
}
>
<Button
isLoading={isPending}
size="sm"
noPadding={true}
className="w-[32px] mr-1"
disabled={disabled}
onClick={() => ignore()}
appearance={data?.ignores === true ? "secondary" : "primary"}
icon={data?.ignores === true ? <UilBell /> : <UilBellSlash />}
/>
</StyledTooltip>
</LoginRequired>
) : (
<></>
Expand Down

0 comments on commit df24b1d

Please sign in to comment.