+25
-22
src/components/moderation/block-account-prompt.tsx
+25
-22
src/components/moderation/block-account-prompt.tsx
···
3
3
import type { AppBskyActorDefs, At } from '@atcute/client/lexicons';
4
4
import { QueryClient, createMutation } from '@mary/solid-query';
5
5
6
-
import { updateProfileShadow, useProfileShadow } from '~/api/cache/profile-shadow';
6
+
import { type ProfileShadowView, updateProfileShadow, useProfileShadow } from '~/api/cache/profile-shadow';
7
7
import { createListMetaQuery } from '~/api/queries/list';
8
8
import { parseCanonicalResourceUri } from '~/api/types/at-uri';
9
9
import { getCurrentDate } from '~/api/utils/misc';
···
22
22
import * as Prompt from '../prompt';
23
23
24
24
export interface BlockAccountPrompt {
25
-
/** Expected to be static */
26
25
profile: AppBskyActorDefs.ProfileViewDetailed;
27
26
}
28
27
29
28
const BlockAccountPrompt = (props: BlockAccountPrompt) => {
30
-
const profile = props.profile;
31
-
const shadow = useProfileShadow(props.profile);
29
+
const profile = () => props.profile;
30
+
const shadow = useProfileShadow(profile);
32
31
33
32
return (
34
33
<Switch>
35
-
<Match when={/* @once */ profile.viewer?.blockingByList}>
36
-
<BlockedByList {...props} />
34
+
<Match when={profile().viewer?.blockingByList}>
35
+
<BlockedByList profile={profile()} shadow={shadow()} />
37
36
</Match>
38
37
39
38
<Match when={shadow().blockUri}>
40
-
<UnblockPrompt {...props} />
39
+
<UnblockPrompt profile={profile()} shadow={shadow()} />
41
40
</Match>
42
41
43
42
<Match when>
44
-
<BlockPrompt {...props} />
43
+
<BlockPrompt profile={profile()} shadow={shadow()} />
45
44
</Match>
46
45
</Switch>
47
46
);
···
49
48
50
49
export default BlockAccountPrompt;
51
50
52
-
const BlockPrompt = ({ profile }: BlockAccountPrompt) => {
51
+
interface BlockAccountPromptInnerProps extends BlockAccountPrompt {
52
+
shadow: ProfileShadowView;
53
+
}
54
+
55
+
const BlockPrompt = (props: BlockAccountPromptInnerProps) => {
53
56
const { close } = useModalContext();
54
57
55
58
const { currentAccount } = useSession();
···
63
66
record: {
64
67
$type: 'app.bsky.graph.block',
65
68
createdAt: getCurrentDate(),
66
-
subject: profile.did,
69
+
subject: props.profile.did,
67
70
},
68
71
});
69
72
},
70
73
onSuccess(ret) {
71
74
close();
72
-
updateProfileShadow(queryClient, profile.did, { blockUri: ret.uri });
75
+
updateProfileShadow(queryClient, props.profile.did, { blockUri: ret.uri });
73
76
74
77
setTimeout(() => {
75
-
resetThreadQueries(queryClient, profile.did);
78
+
resetThreadQueries(queryClient, props.profile.did);
76
79
}, 1_500);
77
80
},
78
81
onError() {
···
82
85
83
86
return (
84
87
<Prompt.Container maxWidth="md" disabled={mutation.isPending}>
85
-
<Prompt.Title>{/* @once */ `Block @${profile.handle.toLowerCase()}?`}</Prompt.Title>
88
+
<Prompt.Title>{/* @once */ `Block @${props.profile.handle.toLowerCase()}?`}</Prompt.Title>
86
89
87
90
<Prompt.Description>Here's what happens if you do:</Prompt.Description>
88
91
···
122
125
);
123
126
};
124
127
125
-
const UnblockPrompt = ({ profile }: BlockAccountPrompt) => {
128
+
const UnblockPrompt = (props: BlockAccountPromptInnerProps) => {
126
129
const { close } = useModalContext();
127
130
128
131
const { rpc } = useAgent();
129
-
const { repo, rkey } = parseCanonicalResourceUri(profile.viewer!.blocking!);
130
132
131
133
const mutation = createMutation((queryClient) => ({
132
134
async mutationFn() {
135
+
const { repo, rkey } = parseCanonicalResourceUri(props.shadow.blockUri!);
136
+
133
137
return await deleteRecord(rpc, {
134
138
repo: repo as At.Did,
135
139
collection: 'app.bsky.graph.block',
···
138
142
},
139
143
onSuccess() {
140
144
close();
141
-
updateProfileShadow(queryClient, profile.did, { blockUri: undefined });
145
+
updateProfileShadow(queryClient, props.profile.did, { blockUri: undefined });
142
146
143
147
setTimeout(() => {
144
-
resetThreadQueries(queryClient, profile.did);
148
+
resetThreadQueries(queryClient, props.profile.did);
145
149
}, 1_500);
146
150
},
147
151
onError() {
···
151
155
152
156
return (
153
157
<Prompt.Container maxWidth="md" disabled={mutation.isPending}>
154
-
<Prompt.Title>{/* @once */ `Unblock @${profile.handle.toLowerCase()}?`}</Prompt.Title>
158
+
<Prompt.Title>{/* @once */ `Unblock @${props.profile.handle.toLowerCase()}?`}</Prompt.Title>
155
159
156
160
<Prompt.Description>Here's what happens if you do:</Prompt.Description>
157
161
···
191
195
);
192
196
};
193
197
194
-
const BlockedByList = ({ profile }: BlockAccountPrompt) => {
198
+
const BlockedByList = (props: BlockAccountPromptInnerProps) => {
195
199
const { close } = useModalContext();
196
200
197
-
const listBasic = profile.viewer!.blockingByList!;
198
-
const query = createListMetaQuery(() => listBasic.uri);
201
+
const query = createListMetaQuery(() => props.profile.viewer!.blockingByList!.uri);
199
202
200
203
return (
201
204
<Prompt.Container>
202
-
<Prompt.Title>{/* @once */ `Can't unblock @${profile.handle.toLowerCase()}`}</Prompt.Title>
205
+
<Prompt.Title>{/* @once */ `Can't unblock @${props.profile.handle.toLowerCase()}`}</Prompt.Title>
203
206
<Prompt.Description>
204
207
You've currently opted to block all accounts that are in this moderation list:
205
208
</Prompt.Description>