mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-26 14:21:13 +00:00
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>
This commit is contained in:
parent
5fb0cdc5b5
commit
8a80b95189
1 changed files with 50 additions and 1 deletions
|
@ -3,6 +3,7 @@ import { Link } from "inferno-router";
|
||||||
import {
|
import {
|
||||||
AddAdminResponse,
|
AddAdminResponse,
|
||||||
BanPersonResponse,
|
BanPersonResponse,
|
||||||
|
BlockPerson,
|
||||||
BlockPersonResponse,
|
BlockPersonResponse,
|
||||||
CommentResponse,
|
CommentResponse,
|
||||||
GetPersonDetails,
|
GetPersonDetails,
|
||||||
|
@ -58,6 +59,7 @@ interface ProfileState {
|
||||||
sort: SortType;
|
sort: SortType;
|
||||||
page: number;
|
page: number;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
personBlocked: boolean;
|
||||||
siteRes: GetSiteResponse;
|
siteRes: GetSiteResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +87,7 @@ export class Profile extends Component<any, ProfileState> {
|
||||||
view: Profile.getViewFromProps(this.props.match.view),
|
view: Profile.getViewFromProps(this.props.match.view),
|
||||||
sort: Profile.getSortTypeFromProps(this.props.match.sort),
|
sort: Profile.getSortTypeFromProps(this.props.match.sort),
|
||||||
page: Profile.getPageFromProps(this.props.match.page),
|
page: Profile.getPageFromProps(this.props.match.page),
|
||||||
|
personBlocked: false,
|
||||||
siteRes: this.isoData.site_res,
|
siteRes: this.isoData.site_res,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -107,6 +110,7 @@ export class Profile extends Component<any, ProfileState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
setupTippy();
|
setupTippy();
|
||||||
|
this.setPersonBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchUserData() {
|
fetchUserData() {
|
||||||
|
@ -128,6 +132,12 @@ export class Profile extends Component<any, ProfileState> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
static getViewFromProps(view: string): PersonDetailsView {
|
||||||
return view ? PersonDetailsView[view] : PersonDetailsView.Overview;
|
return view ? PersonDetailsView[view] : PersonDetailsView.Overview;
|
||||||
}
|
}
|
||||||
|
@ -341,6 +351,24 @@ export class Profile extends Component<any, ProfileState> {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
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() {
|
userInfo() {
|
||||||
let pv = this.state.personRes?.person_view;
|
let pv = this.state.personRes?.person_view;
|
||||||
|
@ -395,11 +423,29 @@ export class Profile extends Component<any, ProfileState> {
|
||||||
{i18n.t("send_secure_message")}
|
{i18n.t("send_secure_message")}
|
||||||
</a>
|
</a>
|
||||||
<Link
|
<Link
|
||||||
className={"d-flex align-self-start btn btn-secondary"}
|
className={"d-flex align-self-start btn btn-secondary mr-2"}
|
||||||
to={`/create_private_message/recipient/${pv.person.id}`}
|
to={`/create_private_message/recipient/${pv.person.id}`}
|
||||||
>
|
>
|
||||||
{i18n.t("send_message")}
|
{i18n.t("send_message")}
|
||||||
</Link>
|
</Link>
|
||||||
|
{this.state.personBlocked ? (
|
||||||
|
<button
|
||||||
|
className={"d-flex align-self-start btn btn-secondary"}
|
||||||
|
onClick={linkEvent(
|
||||||
|
pv.person.id,
|
||||||
|
this.handleUnblockPerson
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{i18n.t("unblock_user")}
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
className={"d-flex align-self-start btn btn-secondary"}
|
||||||
|
onClick={linkEvent(pv.person.id, this.handleBlockPerson)}
|
||||||
|
>
|
||||||
|
{i18n.t("block_user")}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -536,6 +582,7 @@ export class Profile extends Component<any, ProfileState> {
|
||||||
this.state.personRes = data;
|
this.state.personRes = data;
|
||||||
console.log(data);
|
console.log(data);
|
||||||
this.state.loading = false;
|
this.state.loading = false;
|
||||||
|
this.setPersonBlock();
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
restoreScrollPosition(this.context);
|
restoreScrollPosition(this.context);
|
||||||
} else if (op == UserOperation.AddAdmin) {
|
} else if (op == UserOperation.AddAdmin) {
|
||||||
|
@ -594,6 +641,8 @@ export class Profile extends Component<any, ProfileState> {
|
||||||
} else if (op == UserOperation.BlockPerson) {
|
} else if (op == UserOperation.BlockPerson) {
|
||||||
let data = wsJsonToRes<BlockPersonResponse>(msg).data;
|
let data = wsJsonToRes<BlockPersonResponse>(msg).data;
|
||||||
updatePersonBlock(data);
|
updatePersonBlock(data);
|
||||||
|
this.setPersonBlock();
|
||||||
|
this.setState(this.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue