Web: People: MyProfile refactoring

This commit is contained in:
Alexey Safronov 2021-05-13 11:26:55 +03:00
parent 28cbbc1671
commit 16deb72acc

View File

@ -14,17 +14,7 @@ import { SectionBodyContent, SectionHeaderContent } from "../Profile/Section";
class My extends React.Component { class My extends React.Component {
componentDidMount() { componentDidMount() {
const { const { fetchProfile, profile, location, t, setDocumentTitle } = this.props;
match,
fetchProfile,
profile,
location,
t,
setDocumentTitle,
} = this.props;
let { userId } = match.params;
if (!userId) userId = "@self";
setDocumentTitle(t("Profile")); setDocumentTitle(t("Profile"));
this.documentElement = document.getElementsByClassName("hidingHeader"); this.documentElement = document.getElementsByClassName("hidingHeader");
@ -39,7 +29,7 @@ class My extends React.Component {
toastr.success(t("ChangeEmailSuccess")); toastr.success(t("ChangeEmailSuccess"));
} }
if (!profile) { if (!profile) {
fetchProfile(userId); fetchProfile("@self");
} }
if (!profile && this.documentElement) { if (!profile && this.documentElement) {
@ -49,39 +39,31 @@ class My extends React.Component {
} }
} }
componentDidUpdate(prevProps) {
const { match, fetchProfile, profile } = this.props;
const { userId } = match.params;
const prevUserId = prevProps.match.params.userId;
if (userId !== undefined && userId !== prevUserId) {
fetchProfile(userId);
}
if (profile && this.documentElement) {
for (var i = 0; i < this.documentElement.length; i++) {
this.documentElement[i].style.transition = "";
}
}
}
componentWillUnmount() { componentWillUnmount() {
this.props.resetProfile(); this.props.resetProfile();
} }
render() { render() {
//console.log("Profile render"); //console.log("My Profile render");
const { profile } = this.props; const { profile, tReady } = this.props;
return ( return (
<PageLayout withBodyAutoFocus> <PageLayout withBodyAutoFocus>
<PageLayout.SectionHeader> <PageLayout.SectionHeader>
{profile ? <SectionHeaderContent /> : <Loaders.SectionHeader />} {profile && tReady ? (
<SectionHeaderContent isMy={true} />
) : (
<Loaders.SectionHeader />
)}
</PageLayout.SectionHeader> </PageLayout.SectionHeader>
<PageLayout.SectionBody> <PageLayout.SectionBody>
{profile ? <SectionBodyContent /> : <Loaders.ProfileView />} {profile && tReady ? (
<SectionBodyContent isMy={true} />
) : (
<Loaders.ProfileView />
)}
</PageLayout.SectionBody> </PageLayout.SectionBody>
</PageLayout> </PageLayout>
); );
@ -93,14 +75,12 @@ My.propTypes = {
history: PropTypes.object.isRequired, history: PropTypes.object.isRequired,
match: PropTypes.object.isRequired, match: PropTypes.object.isRequired,
profile: PropTypes.object, profile: PropTypes.object,
isAdmin: PropTypes.bool,
language: PropTypes.string, language: PropTypes.string,
}; };
const MyProfile = withRouter( const MyProfile = withRouter(
inject(({ auth, peopleStore }) => ({ inject(({ auth, peopleStore }) => ({
setDocumentTitle: auth.setDocumentTitle, setDocumentTitle: auth.setDocumentTitle,
isAdmin: auth.isAdmin,
language: auth.language, language: auth.language,
resetProfile: peopleStore.targetUserStore.resetTargetUser, resetProfile: peopleStore.targetUserStore.resetTargetUser,
fetchProfile: peopleStore.targetUserStore.getTargetUser, fetchProfile: peopleStore.targetUserStore.getTargetUser,