]> Untitled Git - lemmy.git/commitdiff
Fixing an issue with comments clearing out forms. Fixes #1045
authorDessalines <tyhou13@gmx.com>
Sun, 2 Aug 2020 03:52:38 +0000 (23:52 -0400)
committerDessalines <tyhou13@gmx.com>
Sun, 2 Aug 2020 03:52:38 +0000 (23:52 -0400)
ui/src/components/inbox.tsx
ui/src/components/navbar.tsx
ui/src/components/private-message.tsx
ui/src/components/search.tsx
ui/src/components/user-details.tsx
ui/src/services/WebSocketService.ts

index eff7efcf18f91f40ed0f7544bcf3a7ebc752541f..ecc9223c3c0ac10503d4dde026f277eb05432b50 100644 (file)
@@ -275,21 +275,21 @@ export class Inbox extends Component<any, InboxState> {
     );
   }
 
-  all() {
-    let combined: Array<ReplyType> = [];
-
-    combined.push(...this.state.replies);
-    combined.push(...this.state.mentions);
-    combined.push(...this.state.messages);
-
-    // Sort it
-    combined.sort((a, b) => b.published.localeCompare(a.published));
+  combined(): Array<ReplyType> {
+    return [
+      ...this.state.replies,
+      ...this.state.mentions,
+      ...this.state.messages,
+    ].sort((a, b) => b.published.localeCompare(a.published));
+  }
 
+  all() {
     return (
       <div>
-        {combined.map(i =>
+        {this.combined().map(i =>
           isCommentType(i) ? (
             <CommentNodes
+              key={i.id}
               nodes={[{ comment: i }]}
               noIndent
               markable
@@ -298,7 +298,7 @@ export class Inbox extends Component<any, InboxState> {
               enableDownvotes={this.state.site.enable_downvotes}
             />
           ) : (
-            <PrivateMessage privateMessage={i} />
+            <PrivateMessage key={i.id} privateMessage={i} />
           )
         )}
       </div>
@@ -325,6 +325,7 @@ export class Inbox extends Component<any, InboxState> {
       <div>
         {this.state.mentions.map(mention => (
           <CommentNodes
+            key={mention.id}
             nodes={[{ comment: mention }]}
             noIndent
             markable
@@ -341,7 +342,7 @@ export class Inbox extends Component<any, InboxState> {
     return (
       <div>
         {this.state.messages.map(message => (
-          <PrivateMessage privateMessage={message} />
+          <PrivateMessage key={message.id} privateMessage={message} />
         ))}
       </div>
     );
@@ -565,7 +566,6 @@ export class Inbox extends Component<any, InboxState> {
       } else if (data.comment.creator_id == UserService.Instance.user.id) {
         toast(i18n.t('reply_sent'));
       }
-      this.setState(this.state);
     } else if (res.op == UserOperation.CreatePrivateMessage) {
       let data = res.data as PrivateMessageResponse;
       if (data.message.recipient_id == UserService.Instance.user.id) {
@@ -597,7 +597,10 @@ export class Inbox extends Component<any, InboxState> {
       this.state.replies.filter(r => !r.read).length +
       this.state.mentions.filter(r => !r.read).length +
       this.state.messages.filter(
-        r => !r.read && r.creator_id !== UserService.Instance.user.id
+        r =>
+          UserService.Instance.user &&
+          !r.read &&
+          r.creator_id !== UserService.Instance.user.id
       ).length
     );
   }
index 6418bb2223dbad3b6319c8d121950d799f21e75b..1eb1731938b86237cbbc83a39e196b3b1b8025f8 100644 (file)
@@ -431,6 +431,7 @@ export class Navbar extends Component<any, NavbarState> {
       // The login
       if (data.my_user) {
         UserService.Instance.user = data.my_user;
+        WebSocketService.Instance.userJoin();
         // On the first load, check the unreads
         if (this.state.isLoggedIn == false) {
           this.requestNotificationPermission();
index c3e0c2c25f40677531218e0fbc3578911b9de10b..4fa30a818a12b4735b472acd672e21f8cc0ab0ac 100644 (file)
@@ -45,7 +45,10 @@ export class PrivateMessage extends Component<
   }
 
   get mine(): boolean {
-    return UserService.Instance.user.id == this.props.privateMessage.creator_id;
+    return (
+      UserService.Instance.user &&
+      UserService.Instance.user.id == this.props.privateMessage.creator_id
+    );
   }
 
   render() {
@@ -113,6 +116,7 @@ export class PrivateMessage extends Component<
             <PrivateMessageForm
               privateMessage={message}
               onEdit={this.handlePrivateMessageEdit}
+              onCreate={this.handlePrivateMessageCreate}
               onCancel={this.handleReplyCancel}
             />
           )}
@@ -280,9 +284,14 @@ export class PrivateMessage extends Component<
     this.setState(this.state);
   }
 
-  handlePrivateMessageCreate() {
-    this.state.showReply = false;
-    this.setState(this.state);
-    toast(i18n.t('message_sent'));
+  handlePrivateMessageCreate(message: PrivateMessageI) {
+    if (
+      UserService.Instance.user &&
+      message.creator_id == UserService.Instance.user.id
+    ) {
+      this.state.showReply = false;
+      this.setState(this.state);
+      toast(i18n.t('message_sent'));
+    }
   }
 }
index 11429fb2e263070a127be26e2926676aeeca3ea6..2162edeba2cf0d4ed57deceddf1d2425238e8be0 100644 (file)
@@ -289,6 +289,7 @@ export class Search extends Component<any, SearchState> {
             <div class="col-12">
               {i.type_ == 'posts' && (
                 <PostListing
+                  key={(i.data as Post).id}
                   post={i.data as Post}
                   showCommunity
                   enableDownvotes={this.state.site.enable_downvotes}
@@ -297,6 +298,7 @@ export class Search extends Component<any, SearchState> {
               )}
               {i.type_ == 'comments' && (
                 <CommentNodes
+                  key={(i.data as Comment).id}
                   nodes={[{ comment: i.data as Comment }]}
                   locked
                   noIndent
index 913cb5e90be8368fb65d545c956d5a33f182da5c..5e9a58d225558e70f47de780214d287de56e3c12 100644 (file)
@@ -150,6 +150,7 @@ export class UserDetails extends Component<UserDetailsProps, UserDetailsState> {
             <div>
               {i.type === 'posts' ? (
                 <PostListing
+                  key={(i.data as Post).id}
                   post={i.data as Post}
                   admins={this.props.admins}
                   showCommunity
@@ -158,6 +159,7 @@ export class UserDetails extends Component<UserDetailsProps, UserDetailsState> {
                 />
               ) : (
                 <CommentNodes
+                  key={(i.data as Comment).id}
                   nodes={[{ comment: i.data as Comment }]}
                   admins={this.props.admins}
                   noBorder
index 03233ef9e3619f4dfd7cb2cc5281deaba3fd30ba..c73de21023a2a4319c932802521b19054fab16ad 100644 (file)
@@ -82,10 +82,6 @@ export class WebSocketService {
       this.ws.onopen = () => {
         console.log(`Connected to ${wsUri}`);
 
-        if (UserService.Instance.user) {
-          this.userJoin();
-        }
-
         if (!firstConnect) {
           let res: WebSocketJsonResponse = {
             reconnect: true,