mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-26 14:21:13 +00:00
fix: Fix bug where user could not block person from profile page (#2151)
* fix: Fix bug where user could not block person from profile page * fix: Fix linting errors * chore: Replace arrow function with regular function
This commit is contained in:
parent
aec61ec5d1
commit
951c8afebc
1 changed files with 24 additions and 22 deletions
|
@ -155,6 +155,16 @@ const Moderates = ({ moderates }: { moderates?: CommunityModeratorView[] }) =>
|
||||||
const Follows = () =>
|
const Follows = () =>
|
||||||
getCommunitiesListing("subscribed", UserService.Instance.myUserInfo?.follows);
|
getCommunitiesListing("subscribed", UserService.Instance.myUserInfo?.follows);
|
||||||
|
|
||||||
|
function isPersonBlocked(personRes: RequestState<GetPersonDetailsResponse>) {
|
||||||
|
return (
|
||||||
|
(personRes.state === "success" &&
|
||||||
|
UserService.Instance.myUserInfo?.person_blocks.some(
|
||||||
|
({ target: { id } }) => id === personRes.data.person_view.person.id,
|
||||||
|
)) ??
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export class Profile extends Component<
|
export class Profile extends Component<
|
||||||
RouteComponentProps<{ username: string }>,
|
RouteComponentProps<{ username: string }>,
|
||||||
ProfileState
|
ProfileState
|
||||||
|
@ -211,10 +221,12 @@ export class Profile extends Component<
|
||||||
|
|
||||||
// Only fetch the data if coming from another route
|
// Only fetch the data if coming from another route
|
||||||
if (FirstLoadService.isFirstLoad) {
|
if (FirstLoadService.isFirstLoad) {
|
||||||
|
const personRes = this.isoData.routeData.personResponse;
|
||||||
this.state = {
|
this.state = {
|
||||||
...this.state,
|
...this.state,
|
||||||
personRes: this.isoData.routeData.personResponse,
|
personRes,
|
||||||
isIsomorphic: true,
|
isIsomorphic: true,
|
||||||
|
personBlocked: isPersonBlocked(personRes),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,17 +246,18 @@ export class Profile extends Component<
|
||||||
const { page, sort, view } = getProfileQueryParams();
|
const { page, sort, view } = getProfileQueryParams();
|
||||||
|
|
||||||
this.setState({ personRes: { state: "loading" } });
|
this.setState({ personRes: { state: "loading" } });
|
||||||
this.setState({
|
const personRes = await HttpService.client.getPersonDetails({
|
||||||
personRes: await HttpService.client.getPersonDetails({
|
|
||||||
username: this.props.match.params.username,
|
username: this.props.match.params.username,
|
||||||
sort,
|
sort,
|
||||||
saved_only: view === PersonDetailsView.Saved,
|
saved_only: view === PersonDetailsView.Saved,
|
||||||
page,
|
page,
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
}),
|
});
|
||||||
|
this.setState({
|
||||||
|
personRes,
|
||||||
|
personBlocked: isPersonBlocked(personRes),
|
||||||
});
|
});
|
||||||
restoreScrollPosition(this.context);
|
restoreScrollPosition(this.context);
|
||||||
this.setPersonBlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get amCurrentUser() {
|
get amCurrentUser() {
|
||||||
|
@ -258,19 +271,6 @@ export class Profile extends Component<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setPersonBlock() {
|
|
||||||
const mui = UserService.Instance.myUserInfo;
|
|
||||||
const res = this.state.personRes;
|
|
||||||
|
|
||||||
if (mui && res.state === "success") {
|
|
||||||
this.setState({
|
|
||||||
personBlocked: mui.person_blocks.some(
|
|
||||||
({ target: { id } }) => id === res.data.person_view.person.id,
|
|
||||||
),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async fetchInitialData({
|
static async fetchInitialData({
|
||||||
client,
|
client,
|
||||||
path,
|
path,
|
||||||
|
@ -791,6 +791,7 @@ export class Profile extends Component<
|
||||||
});
|
});
|
||||||
if (res.state === "success") {
|
if (res.state === "success") {
|
||||||
updatePersonBlock(res.data);
|
updatePersonBlock(res.data);
|
||||||
|
this.setState({ personBlocked: res.data.blocked });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -826,6 +827,7 @@ export class Profile extends Component<
|
||||||
const blockPersonRes = await HttpService.client.blockPerson(form);
|
const blockPersonRes = await HttpService.client.blockPerson(form);
|
||||||
if (blockPersonRes.state === "success") {
|
if (blockPersonRes.state === "success") {
|
||||||
updatePersonBlock(blockPersonRes.data);
|
updatePersonBlock(blockPersonRes.data);
|
||||||
|
this.setState({ personBlocked: blockPersonRes.data.blocked });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue