From: Dessalines Date: Fri, 29 Oct 2021 02:31:12 +0000 (-0400) Subject: Mahanstreamer userpage (#471) X-Git-Url: http://these/git/%7B%60https:/README.ja.md?a=commitdiff_plain;h=8a80b9518949cb31f7d9602b4a67d9a78e46ed59;p=lemmy-ui.git Mahanstreamer userpage (#471) * Added user page block functionality * Add in suggested changes adding in suggested changes * fix lint * change var name * Update profile.tsx * Update profile.tsx * Some fixes. Co-authored-by: mahanstreamer <84676642+mahanstreamer@users.noreply.github.com> --- diff --git a/src/shared/components/person/profile.tsx b/src/shared/components/person/profile.tsx index eca26e8..0dfff14 100644 --- a/src/shared/components/person/profile.tsx +++ b/src/shared/components/person/profile.tsx @@ -3,6 +3,7 @@ import { Link } from "inferno-router"; import { AddAdminResponse, BanPersonResponse, + BlockPerson, BlockPersonResponse, CommentResponse, GetPersonDetails, @@ -58,6 +59,7 @@ interface ProfileState { sort: SortType; page: number; loading: boolean; + personBlocked: boolean; siteRes: GetSiteResponse; } @@ -85,6 +87,7 @@ export class Profile extends Component { view: Profile.getViewFromProps(this.props.match.view), sort: Profile.getSortTypeFromProps(this.props.match.sort), page: Profile.getPageFromProps(this.props.match.page), + personBlocked: false, siteRes: this.isoData.site_res, }; @@ -107,6 +110,7 @@ export class Profile extends Component { } setupTippy(); + this.setPersonBlock(); } fetchUserData() { @@ -128,6 +132,12 @@ export class Profile extends Component { ); } + setPersonBlock() { + this.state.personBlocked = UserService.Instance.myUserInfo.person_blocks + .map(a => a.target.id) + .includes(this.state.personRes?.person_view.person.id); + } + static getViewFromProps(view: string): PersonDetailsView { return view ? PersonDetailsView[view] : PersonDetailsView.Overview; } @@ -341,6 +351,24 @@ export class Profile extends Component { ); } + handleBlockPerson(personId: number) { + if (personId != 0) { + let blockUserForm: BlockPerson = { + person_id: personId, + block: true, + auth: authField(), + }; + WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm)); + } + } + handleUnblockPerson(recipientId: number) { + let blockUserForm: BlockPerson = { + person_id: recipientId, + block: false, + auth: authField(), + }; + WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm)); + } userInfo() { let pv = this.state.personRes?.person_view; @@ -395,11 +423,29 @@ export class Profile extends Component { {i18n.t("send_secure_message")} {i18n.t("send_message")} + {this.state.personBlocked ? ( + + ) : ( + + )} )} @@ -536,6 +582,7 @@ export class Profile extends Component { this.state.personRes = data; console.log(data); this.state.loading = false; + this.setPersonBlock(); this.setState(this.state); restoreScrollPosition(this.context); } else if (op == UserOperation.AddAdmin) { @@ -594,6 +641,8 @@ export class Profile extends Component { } else if (op == UserOperation.BlockPerson) { let data = wsJsonToRes(msg).data; updatePersonBlock(data); + this.setPersonBlock(); + this.setState(this.state); } } }