Skip to content

Commit

Permalink
Add community blocking from feed by long press (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Jul 15, 2023
1 parent fc1aba1 commit 044d686
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/features/inbox/messages/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ export default function Message({ message }: MessageProps) {
useIonViewWillEnter(() => setFocused(true));
useIonViewDidLeave(() => setFocused(false));

const bind = useLongPress(() => {
presentReport(message);
});
const bind = useLongPress(
() => {
presentReport(message);
},
{ cancelOnMovement: true }
);

useEffect(() => {
if (
Expand Down
35 changes: 34 additions & 1 deletion src/features/labels/links/CommunityLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import Handle from "../Handle";
import { StyledLink } from "./shared";
import ItemIcon from "../img/ItemIcon";
import { css } from "@emotion/react";
import { useAppDispatch } from "../../../store";
import { useIonActionSheet, useIonToast } from "@ionic/react";
import { useLongPress } from "use-long-press";
import { blockCommunity } from "../../community/communitySlice";
import { buildBlocked } from "../../../helpers/toastMessages";

interface CommunityLinkProps {
community: Community;
Expand All @@ -15,16 +20,44 @@ interface CommunityLinkProps {

export default function CommunityLink({
community,
className,
showInstanceWhenRemote,
className,
}: CommunityLinkProps) {
const dispatch = useAppDispatch();
const [present] = useIonActionSheet();
const [presentToast] = useIonToast();

const bind = useLongPress(
() => {
present([
{
text: "Block Community",
role: "destructive",
handler: () => {
(async () => {
await dispatch(blockCommunity(true, community.id));

presentToast(buildBlocked(true, getHandle(community)));
})();
},
},
{
text: "Cancel",
role: "cancel",
},
]);
},
{ cancelOnMovement: true }
);

const buildGeneralBrowseLink = useBuildGeneralBrowseLink();

return (
<StyledLink
to={buildGeneralBrowseLink(`/c/${getHandle(community)}`)}
onClick={(e) => e.stopPropagation()}
className={className}
{...bind()}
>
<ItemIcon
item={community}
Expand Down

0 comments on commit 044d686

Please sign in to comment.