- Block (Guideline 1.2, UGC): useBlockPet hook (native confirm Alert, blocks.create). PostCard "..." on other pets' posts now offers Report / Block; pet profile gets a header "..." with Report pet / Block (hidden for any of the owner's own pets), navigating back after a block. Feed, comments and DMs already enforce blocks server-side; explore and search don't yet (server follow-up). - Delete account (Guideline 5.1.1(v)): new delete-account screen reached from a quiet link below Log out in Settings. Mirrors web's DeleteAccountDialog (warning list + type a pet name) and calls the same POST /api/account/delete with the Clerk bearer token, then clears the query cache and signs out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
import { Alert } from "react-native";
|
|
import { useTranslation } from "react-i18next";
|
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
import { useTRPC } from "../api/trpc";
|
|
|
|
type BlockTarget = { id: string; name: string };
|
|
|
|
/**
|
|
* Port of web's src/components/safety/BlockDialog.tsx (SAFE-01) as a native
|
|
* confirm Alert instead of a dialog component. Required for App Store
|
|
* Guideline 1.2 (UGC apps must let users block abusive accounts).
|
|
*
|
|
* The block itself is enforced server-side: feed.getFeed filters blocked
|
|
* pets, comments/DMs reject blocked pairs. Explore/search don't filter blocks
|
|
* yet (server change) — invalidating them here is harmless groundwork.
|
|
*
|
|
* `onBlocked` lets a caller leave a screen that shows the blocked pet (the
|
|
* pet profile navigates back).
|
|
*/
|
|
export function useBlockPet(onBlocked?: () => void) {
|
|
const { t } = useTranslation();
|
|
const trpc = useTRPC();
|
|
const queryClient = useQueryClient();
|
|
|
|
const blockMutation = useMutation(
|
|
trpc.blocks.create.mutationOptions({
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries(trpc.feed.pathFilter());
|
|
queryClient.invalidateQueries(trpc.explore.pathFilter());
|
|
queryClient.invalidateQueries(trpc.search.pathFilter());
|
|
queryClient.invalidateQueries(trpc.posts.pathFilter());
|
|
queryClient.invalidateQueries(trpc.follows.pathFilter());
|
|
onBlocked?.();
|
|
},
|
|
onError: () => Alert.alert(t("block.errorToast")),
|
|
})
|
|
);
|
|
|
|
const confirmBlock = (blockerPetId: string, target: BlockTarget) => {
|
|
Alert.alert(t("block.title", { petName: target.name }), t("block.description", { petName: target.name }), [
|
|
{ text: t("block.cancel"), style: "cancel" },
|
|
{
|
|
text: t("block.confirm"),
|
|
style: "destructive",
|
|
onPress: () =>
|
|
blockMutation.mutate(
|
|
{ blockerPetId, blockedPetId: target.id },
|
|
{ onSuccess: () => Alert.alert(t("block.successToast", { petName: target.name })) }
|
|
),
|
|
},
|
|
]);
|
|
};
|
|
|
|
return { confirmBlock, isBlocking: blockMutation.isPending };
|
|
}
|