]> Untitled Git - lemmy-ui.git/commitdiff
feat: Clean up the Create Private Message page a bit
authorJay Sitter <jay@jaysitter.com>
Sat, 24 Jun 2023 03:13:09 +0000 (23:13 -0400)
committerJay Sitter <jay@jaysitter.com>
Sat, 24 Jun 2023 03:13:09 +0000 (23:13 -0400)
src/shared/components/common/icon.tsx
src/shared/components/common/markdown-textarea.tsx
src/shared/components/private_message/create-private-message.tsx
src/shared/components/private_message/private-message-form.tsx

index 7aedee71f30839753e8803ef8f1d55d626d60aec..5b6ddf818677edde9e0c4279ed20b367936dba5d 100644 (file)
@@ -35,6 +35,7 @@ export class Icon extends Component<IconProps, any> {
 
 interface SpinnerProps {
   large?: boolean;
+  className?: string;
 }
 
 export class Spinner extends Component<SpinnerProps, any> {
@@ -46,7 +47,9 @@ export class Spinner extends Component<SpinnerProps, any> {
     return (
       <Icon
         icon="spinner"
-        classes={`spin ${this.props.large && "spinner-large"}`}
+        classes={classNames("spin", this.props.className, {
+          "spinner-large": this.props.large,
+        })}
       />
     );
   }
index 97d1d1424d626f87327ea3c2f28beea78fe5fa10..73946ea8e8a43cdcc3c7ab6ac4719c0f3814ad5c 100644 (file)
@@ -272,19 +272,6 @@ export class MarkdownTextArea extends Component<
             {/* A flex expander */}
             <div className="flex-grow-1"></div>
 
-            {this.props.buttonTitle && (
-              <button
-                type="submit"
-                className="btn btn-sm btn-secondary ms-2"
-                disabled={this.isDisabled}
-              >
-                {this.state.loading ? (
-                  <Spinner />
-                ) : (
-                  <span>{this.props.buttonTitle}</span>
-                )}
-              </button>
-            )}
             {this.props.replyType && (
               <button
                 type="button"
@@ -294,16 +281,26 @@ export class MarkdownTextArea extends Component<
                 {I18NextService.i18n.t("cancel")}
               </button>
             )}
-            {this.state.content && (
+            <button
+              type="button"
+              disabled={!this.state.content ? true : false}
+              className={`btn btn-sm btn-secondary ms-2 ${
+                this.state.previewMode && "active"
+              }`}
+              onClick={linkEvent(this, this.handlePreviewToggle)}
+            >
+              {this.state.previewMode
+                ? I18NextService.i18n.t("edit")
+                : I18NextService.i18n.t("preview")}
+            </button>
+            {this.props.buttonTitle && (
               <button
-                className={`btn btn-sm btn-secondary ms-2 ${
-                  this.state.previewMode && "active"
-                }`}
-                onClick={linkEvent(this, this.handlePreviewToggle)}
+                type="submit"
+                className="btn btn-sm btn-secondary ms-2"
+                disabled={this.isDisabled}
               >
-                {this.state.previewMode
-                  ? I18NextService.i18n.t("edit")
-                  : I18NextService.i18n.t("preview")}
+                {this.state.loading && <Spinner className="me-1" />}
+                {this.props.buttonTitle}
               </button>
             )}
           </div>
index 8afd3488425edec8641bc9545b3fd5b0f11a6411..840a442524dc3efdcef4ec7629fffdd71d35c414 100644 (file)
@@ -115,7 +115,9 @@ export class CreatePrivateMessage extends Component<
         return (
           <div className="row">
             <div className="col-12 col-lg-6 offset-lg-3 mb-4">
-              <h5>{I18NextService.i18n.t("create_private_message")}</h5>
+              <h1 className="h4">
+                {I18NextService.i18n.t("create_private_message")}
+              </h1>
               <PrivateMessageForm
                 onCreate={this.handlePrivateMessageCreate}
                 recipient={res.person_view.person}
index 338584b393ea3e6c1aa077c7dc2b0c83bd679719..12fd9bd23a9206bfb98ad5607dd6a026dc510af2 100644 (file)
@@ -11,7 +11,7 @@ import {
 import { relTags } from "../../config";
 import { I18NextService } from "../../services";
 import { setupTippy } from "../../tippy";
-import { Icon, Spinner } from "../common/icon";
+import { Icon } from "../common/icon";
 import { MarkdownTextArea } from "../common/markdown-textarea";
 import NavigationPrompt from "../common/navigation-prompt";
 import { PersonListing } from "../person/person-listing";
@@ -28,7 +28,6 @@ interface PrivateMessageFormState {
   content?: string;
   loading: boolean;
   previewMode: boolean;
-  showDisclaimer: boolean;
   submitted: boolean;
 }
 
@@ -39,7 +38,6 @@ export class PrivateMessageForm extends Component<
   state: PrivateMessageFormState = {
     loading: false,
     previewMode: false,
-    showDisclaimer: false,
     content: this.props.privateMessageView
       ? this.props.privateMessageView.private_message.content
       : undefined,
@@ -71,97 +69,69 @@ export class PrivateMessageForm extends Component<
 
   render() {
     return (
-      <form
-        className="private-message-form"
-        onSubmit={linkEvent(this, this.handlePrivateMessageSubmit)}
-      >
+      <form className="private-message-form">
         <NavigationPrompt
           when={
             !this.state.loading && !!this.state.content && !this.state.submitted
           }
         />
         {!this.props.privateMessageView && (
-          <div className="mb-3 row">
+          <div className="mb-3 row align-items-baseline">
             <label className="col-sm-2 col-form-label">
               {capitalizeFirstLetter(I18NextService.i18n.t("to"))}
             </label>
 
-            <div className="col-sm-10 form-control-plaintext">
+            <div className="col-sm-10">
               <PersonListing person={this.props.recipient} />
             </div>
           </div>
         )}
+        <div className="alert alert-warning small">
+          <Icon icon="alert-triangle" classes="icon-inline me-1" />
+          <T parent="span" i18nKey="private_message_disclaimer">
+            #
+            <a
+              className="alert-link"
+              rel={relTags}
+              href="https://element.io/get-started"
+            >
+              #
+            </a>
+          </T>
+        </div>
         <div className="mb-3 row">
           <label className="col-sm-2 col-form-label">
             {I18NextService.i18n.t("message")}
-            <button
-              className="btn btn-link text-warning d-inline-block"
-              onClick={linkEvent(this, this.handleShowDisclaimer)}
-              data-tippy-content={I18NextService.i18n.t(
-                "private_message_disclaimer"
-              )}
-              aria-label={I18NextService.i18n.t("private_message_disclaimer")}
-            >
-              <Icon icon="alert-triangle" classes="icon-inline" />
-            </button>
           </label>
           <div className="col-sm-10">
             <MarkdownTextArea
+              onSubmit={() => {
+                this.handlePrivateMessageSubmit(this, event);
+              }}
               initialContent={this.state.content}
               onContentChange={this.handleContentChange}
               allLanguages={[]}
               siteLanguages={[]}
               hideNavigationWarnings
+              buttonTitle={
+                this.props.privateMessageView
+                  ? capitalizeFirstLetter(I18NextService.i18n.t("save"))
+                  : capitalizeFirstLetter(I18NextService.i18n.t("send_message"))
+              }
             />
           </div>
         </div>
 
-        {this.state.showDisclaimer && (
-          <div className="mb-3 row">
-            <div className="offset-sm-2 col-sm-10">
-              <div className="alert alert-danger" role="alert">
-                <T i18nKey="private_message_disclaimer">
-                  #
-                  <a
-                    className="alert-link"
-                    rel={relTags}
-                    href="https://element.io/get-started"
-                  >
-                    #
-                  </a>
-                </T>
-              </div>
-            </div>
-          </div>
-        )}
-        <div className="mb-3 row">
-          <div className="offset-sm-2 col-sm-10">
+        <div className="mb-3 d-flex justify-content-end">
+          {this.props.privateMessageView && (
             <button
-              type="submit"
-              className="btn btn-secondary me-2"
-              disabled={this.state.loading}
+              type="button"
+              className="btn btn-secondary w-auto"
+              onClick={linkEvent(this, this.handleCancel)}
             >
-              {this.state.loading ? (
-                <Spinner />
-              ) : this.props.privateMessageView ? (
-                capitalizeFirstLetter(I18NextService.i18n.t("save"))
-              ) : (
-                capitalizeFirstLetter(I18NextService.i18n.t("send_message"))
-              )}
+              {I18NextService.i18n.t("cancel")}
             </button>
-            {this.props.privateMessageView && (
-              <button
-                type="button"
-                className="btn btn-secondary"
-                onClick={linkEvent(this, this.handleCancel)}
-              >
-                {I18NextService.i18n.t("cancel")}
-              </button>
-            )}
-            <ul className="d-inline-block float-right list-inline mb-1 text-muted font-weight-bold">
-              <li className="list-inline-item"></li>
-            </ul>
-          </div>
+          )}
         </div>
       </form>
     );
@@ -200,8 +170,4 @@ export class PrivateMessageForm extends Component<
     event.preventDefault();
     i.setState({ previewMode: !i.state.previewMode });
   }
-
-  handleShowDisclaimer(i: PrivateMessageForm) {
-    i.setState({ showDisclaimer: !i.state.showDisclaimer });
-  }
 }