]> Untitled Git - lemmy-ui.git/blobdiff - src/shared/components/person/profile.tsx
Adding Community Language fixes. #783 (#868)
[lemmy-ui.git] / src / shared / components / person / profile.tsx
index 9de6d0b967abe06c9380d90eb3f3ef81697d5b8b..47399843cab521e119195d8f15d02d9e1a2a8ad0 100644 (file)
@@ -121,15 +121,14 @@ export class Profile extends Component<any, ProfileState> {
 
     // Only fetch the data if coming from another route
     if (this.isoData.path == this.context.router.route.match.url) {
-      this.state.personRes = Some(
-        this.isoData.routeData[0] as GetPersonDetailsResponse
-      );
-      this.state.loading = false;
+      this.state = {
+        ...this.state,
+        personRes: Some(this.isoData.routeData[0] as GetPersonDetailsResponse),
+        loading: false,
+      };
     } else {
       this.fetchUserData();
     }
-
-    this.setPersonBlock();
   }
 
   fetchUserData() {
@@ -162,11 +161,12 @@ export class Profile extends Component<any, ProfileState> {
     UserService.Instance.myUserInfo.match({
       some: mui =>
         this.state.personRes.match({
-          some: res => {
-            this.state.personBlocked = mui.person_blocks
-              .map(a => a.target.id)
-              .includes(res.person_view.person.id);
-          },
+          some: res =>
+            this.setState({
+              personBlocked: mui.person_blocks
+                .map(a => a.target.id)
+                .includes(res.person_view.person.id),
+            }),
           none: void 0,
         }),
       none: void 0,
@@ -207,6 +207,7 @@ export class Profile extends Component<any, ProfileState> {
   }
 
   componentDidMount() {
+    this.setPersonBlock();
     setupTippy();
   }
 
@@ -237,20 +238,16 @@ export class Profile extends Component<any, ProfileState> {
   }
 
   get documentTitle(): string {
-    return this.state.siteRes.site_view.match({
-      some: siteView =>
-        this.state.personRes.match({
-          some: res =>
-            `@${res.person_view.person.name} - ${siteView.site.name}`,
-          none: "",
-        }),
+    return this.state.personRes.match({
+      some: res =>
+        `@${res.person_view.person.name} - ${this.state.siteRes.site_view.site.name}`,
       none: "",
     });
   }
 
   render() {
     return (
-      <div class="container">
+      <div className="container-lg">
         {this.state.loading ? (
           <h5>
             <Spinner large />
@@ -258,8 +255,8 @@ export class Profile extends Component<any, ProfileState> {
         ) : (
           this.state.personRes.match({
             some: res => (
-              <div class="row">
-                <div class="col-12 col-md-8">
+              <div className="row">
+                <div className="col-12 col-md-8">
                   <>
                     <HtmlTags
                       title={this.documentTitle}
@@ -281,11 +278,13 @@ export class Profile extends Component<any, ProfileState> {
                     enableNsfw={enableNsfw(this.state.siteRes)}
                     view={this.state.view}
                     onPageChange={this.handlePageChange}
+                    allLanguages={this.state.siteRes.all_languages}
+                    siteLanguages={this.state.siteRes.discussion_languages}
                   />
                 </div>
 
                 {!this.state.loading && (
-                  <div class="col-12 col-md-4">
+                  <div className="col-12 col-md-4">
                     {this.moderates()}
                     {this.amCurrentUser && this.follows()}
                   </div>
@@ -301,7 +300,7 @@ export class Profile extends Component<any, ProfileState> {
 
   viewRadios() {
     return (
-      <div class="btn-group btn-group-toggle flex-wrap mb-2">
+      <div className="btn-group btn-group-toggle flex-wrap mb-2">
         <label
           className={`btn btn-outline-secondary pointer
             ${this.state.view == PersonDetailsView.Overview && "active"}
@@ -363,7 +362,7 @@ export class Profile extends Component<any, ProfileState> {
 
     return (
       <div className="mb-2">
-        <span class="mr-3">{this.viewRadios()}</span>
+        <span className="mr-3">{this.viewRadios()}</span>
         <SortSelect
           sort={this.state.sort}
           onChange={this.handleSortChange}
@@ -406,14 +405,17 @@ export class Profile extends Component<any, ProfileState> {
               banner={pv.person.banner}
               icon={pv.person.avatar}
             />
-            <div class="mb-3">
-              <div class="">
-                <div class="mb-0 d-flex flex-wrap">
+            <div className="mb-3">
+              <div className="">
+                <div className="mb-0 d-flex flex-wrap">
                   <div>
-                    {pv.person.display_name && (
-                      <h5 class="mb-0">{pv.person.display_name}</h5>
-                    )}
-                    <ul class="list-inline mb-2">
+                    {pv.person.display_name.match({
+                      some: displayName => (
+                        <h5 className="mb-0">{displayName}</h5>
+                      ),
+                      none: <></>,
+                    })}
+                    <ul className="list-inline mb-2">
                       <li className="list-inline-item">
                         <PersonListing
                           person={pv.person}
@@ -428,6 +430,11 @@ export class Profile extends Component<any, ProfileState> {
                           {i18n.t("banned")}
                         </li>
                       )}
+                      {pv.person.deleted && (
+                        <li className="list-inline-item badge badge-danger">
+                          {i18n.t("deleted")}
+                        </li>
+                      )}
                       {pv.person.admin && (
                         <li className="list-inline-item badge badge-light">
                           {i18n.t("admin")}
@@ -531,7 +538,7 @@ export class Profile extends Component<any, ProfileState> {
                   none: <></>,
                 })}
                 <div>
-                  <ul class="list-inline mb-2">
+                  <ul className="list-inline mb-2">
                     <li className="list-inline-item badge badge-light">
                       {i18n.t("number_of_posts", {
                         count: pv.counts.post_count,
@@ -546,7 +553,7 @@ export class Profile extends Component<any, ProfileState> {
                     </li>
                   </ul>
                 </div>
-                <div class="text-muted">
+                <div className="text-muted">
                   {i18n.t("joined")}{" "}
                   <MomentTime
                     published={pv.person.published}
@@ -581,33 +588,36 @@ export class Profile extends Component<any, ProfileState> {
           <>
             {this.state.showBanDialog && (
               <form onSubmit={linkEvent(this, this.handleModBanSubmit)}>
-                <div class="form-group row col-12">
-                  <label class="col-form-label" htmlFor="profile-ban-reason">
+                <div className="form-group row col-12">
+                  <label
+                    className="col-form-label"
+                    htmlFor="profile-ban-reason"
+                  >
                     {i18n.t("reason")}
                   </label>
                   <input
                     type="text"
                     id="profile-ban-reason"
-                    class="form-control mr-2"
+                    className="form-control mr-2"
                     placeholder={i18n.t("reason")}
                     value={toUndefined(this.state.banReason)}
                     onInput={linkEvent(this, this.handleModBanReasonChange)}
                   />
-                  <label class="col-form-label" htmlFor={`mod-ban-expires`}>
+                  <label className="col-form-label" htmlFor={`mod-ban-expires`}>
                     {i18n.t("expires")}
                   </label>
                   <input
                     type="number"
                     id={`mod-ban-expires`}
-                    class="form-control mr-2"
+                    className="form-control mr-2"
                     placeholder={i18n.t("number_of_days")}
                     value={toUndefined(this.state.banExpireDays)}
                     onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
                   />
-                  <div class="form-group">
-                    <div class="form-check">
+                  <div className="form-group">
+                    <div className="form-check">
                       <input
-                        class="form-check-input"
+                        className="form-check-input"
                         id="mod-ban-remove-data"
                         type="checkbox"
                         checked={this.state.removeData}
@@ -617,7 +627,7 @@ export class Profile extends Component<any, ProfileState> {
                         )}
                       />
                       <label
-                        class="form-check-label"
+                        className="form-check-label"
                         htmlFor="mod-ban-remove-data"
                         title={i18n.t("remove_content_more")}
                       >
@@ -631,10 +641,10 @@ export class Profile extends Component<any, ProfileState> {
                 {/*   <label class="col-form-label">Expires</label> */}
                 {/*   <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
                 {/* </div> */}
-                <div class="form-group row">
+                <div className="form-group row">
                   <button
-                    type="cancel"
-                    class="btn btn-secondary mr-2"
+                    type="reset"
+                    className="btn btn-secondary mr-2"
                     aria-label={i18n.t("cancel")}
                     onClick={linkEvent(this, this.handleModBanSubmitCancel)}
                   >
@@ -642,7 +652,7 @@ export class Profile extends Component<any, ProfileState> {
                   </button>
                   <button
                     type="submit"
-                    class="btn btn-secondary"
+                    className="btn btn-secondary"
                     aria-label={i18n.t("ban")}
                   >
                     {i18n.t("ban")} {pv.person.name}
@@ -656,25 +666,28 @@ export class Profile extends Component<any, ProfileState> {
       });
   }
 
-  // TODO test this, make sure its good
   moderates() {
     return this.state.personRes
       .map(r => r.moderates)
       .match({
         some: moderates => {
           if (moderates.length > 0) {
-            <div class="card border-secondary mb-3">
-              <div class="card-body">
-                <h5>{i18n.t("moderates")}</h5>
-                <ul class="list-unstyled mb-0">
-                  {moderates.map(cmv => (
-                    <li>
-                      <CommunityLink community={cmv.community} />
-                    </li>
-                  ))}
-                </ul>
+            return (
+              <div className="card border-secondary mb-3">
+                <div className="card-body">
+                  <h5>{i18n.t("moderates")}</h5>
+                  <ul className="list-unstyled mb-0">
+                    {moderates.map(cmv => (
+                      <li key={cmv.community.id}>
+                        <CommunityLink community={cmv.community} />
+                      </li>
+                    ))}
+                  </ul>
+                </div>
               </div>
-            </div>;
+            );
+          } else {
+            return <></>;
           }
         },
         none: void 0,
@@ -687,18 +700,22 @@ export class Profile extends Component<any, ProfileState> {
       .match({
         some: follows => {
           if (follows.length > 0) {
-            <div class="card border-secondary mb-3">
-              <div class="card-body">
-                <h5>{i18n.t("subscribed")}</h5>
-                <ul class="list-unstyled mb-0">
-                  {follows.map(cfv => (
-                    <li>
-                      <CommunityLink community={cfv.community} />
-                    </li>
-                  ))}
-                </ul>
+            return (
+              <div className="card border-secondary mb-3">
+                <div className="card-body">
+                  <h5>{i18n.t("subscribed")}</h5>
+                  <ul className="list-unstyled mb-0">
+                    {follows.map(cfv => (
+                      <li key={cfv.community.id}>
+                        <CommunityLink community={cfv.community} />
+                      </li>
+                    ))}
+                  </ul>
+                </div>
               </div>
-            </div>;
+            );
+          } else {
+            return <></>;
           }
         },
         none: void 0,
@@ -715,8 +732,7 @@ export class Profile extends Component<any, ProfileState> {
     this.props.history.push(
       `${typeView}/view/${viewStr}/sort/${sortStr}/page/${page}`
     );
-    this.state.loading = true;
-    this.setState(this.state);
+    this.setState({ loading: true });
     this.fetchUserData();
   }
 
@@ -736,29 +752,24 @@ export class Profile extends Component<any, ProfileState> {
   }
 
   handleModBanShow(i: Profile) {
-    i.state.showBanDialog = true;
-    i.setState(i.state);
+    i.setState({ showBanDialog: true });
   }
 
   handleModBanReasonChange(i: Profile, event: any) {
-    i.state.banReason = event.target.value;
-    i.setState(i.state);
+    i.setState({ banReason: event.target.value });
   }
 
   handleModBanExpireDaysChange(i: Profile, event: any) {
-    i.state.banExpireDays = event.target.value;
-    i.setState(i.state);
+    i.setState({ banExpireDays: event.target.value });
   }
 
   handleModRemoveDataChange(i: Profile, event: any) {
-    i.state.removeData = event.target.checked;
-    i.setState(i.state);
+    i.setState({ removeData: event.target.checked });
   }
 
   handleModBanSubmitCancel(i: Profile, event?: any) {
     event.preventDefault();
-    i.state.showBanDialog = false;
-    i.setState(i.state);
+    i.setState({ showBanDialog: false });
   }
 
   handleModBanSubmit(i: Profile, event?: any) {
@@ -771,7 +782,7 @@ export class Profile extends Component<any, ProfileState> {
           // If its an unban, restore all their data
           let ban = !person.banned;
           if (ban == false) {
-            i.state.removeData = false;
+            i.setState({ removeData: false });
           }
           let form = new BanPerson({
             person_id: person.id,
@@ -783,8 +794,7 @@ export class Profile extends Component<any, ProfileState> {
           });
           WebSocketService.Instance.send(wsClient.banPerson(form));
 
-          i.state.showBanDialog = false;
-          i.setState(i.state);
+          i.setState({ showBanDialog: false });
         },
         none: void 0,
       });
@@ -809,15 +819,12 @@ export class Profile extends Component<any, ProfileState> {
         msg,
         GetPersonDetailsResponse
       );
-      this.state.personRes = Some(data);
-      this.state.loading = false;
+      this.setState({ personRes: Some(data), loading: false });
       this.setPersonBlock();
-      this.setState(this.state);
       restoreScrollPosition(this.context);
     } else if (op == UserOperation.AddAdmin) {
       let data = wsJsonToRes<AddAdminResponse>(msg, AddAdminResponse);
-      this.state.siteRes.admins = data.admins;
-      this.setState(this.state);
+      this.setState(s => ((s.siteRes.admins = data.admins), s));
     } else if (op == UserOperation.CreateCommentLike) {
       let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
       createCommentLikeRes(
@@ -858,7 +865,7 @@ export class Profile extends Component<any, ProfileState> {
       op == UserOperation.DeletePost ||
       op == UserOperation.RemovePost ||
       op == UserOperation.LockPost ||
-      op == UserOperation.StickyPost ||
+      op == UserOperation.FeaturePost ||
       op == UserOperation.SavePost
     ) {
       let data = wsJsonToRes<PostResponse>(msg, PostResponse);