From: Dessalines Date: Sun, 2 Aug 2020 03:52:38 +0000 (-0400) Subject: Fixing an issue with comments clearing out forms. Fixes #1045 X-Git-Url: http://these/git/%22%7Burl%7D/%7B%60%24%7BghostArchiveUrl%7D/static/%7B%7D/inbox?a=commitdiff_plain;h=c76e72b7476ad740f6f8893464105cd00a6eed22;p=lemmy.git Fixing an issue with comments clearing out forms. Fixes #1045 --- diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx index eff7efcf..ecc9223c 100644 --- a/ui/src/components/inbox.tsx +++ b/ui/src/components/inbox.tsx @@ -275,21 +275,21 @@ export class Inbox extends Component { ); } - all() { - let combined: Array = []; - - 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 { + return [ + ...this.state.replies, + ...this.state.mentions, + ...this.state.messages, + ].sort((a, b) => b.published.localeCompare(a.published)); + } + all() { return (
- {combined.map(i => + {this.combined().map(i => isCommentType(i) ? ( { enableDownvotes={this.state.site.enable_downvotes} /> ) : ( - + ) )}
@@ -325,6 +325,7 @@ export class Inbox extends Component {
{this.state.mentions.map(mention => ( { return (
{this.state.messages.map(message => ( - + ))}
); @@ -565,7 +566,6 @@ export class Inbox extends Component { } 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 { 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 ); } diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx index 6418bb22..1eb17319 100644 --- a/ui/src/components/navbar.tsx +++ b/ui/src/components/navbar.tsx @@ -431,6 +431,7 @@ export class Navbar extends Component { // 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(); diff --git a/ui/src/components/private-message.tsx b/ui/src/components/private-message.tsx index c3e0c2c2..4fa30a81 100644 --- a/ui/src/components/private-message.tsx +++ b/ui/src/components/private-message.tsx @@ -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< )} @@ -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')); + } } } diff --git a/ui/src/components/search.tsx b/ui/src/components/search.tsx index 11429fb2..2162edeb 100644 --- a/ui/src/components/search.tsx +++ b/ui/src/components/search.tsx @@ -289,6 +289,7 @@ export class Search extends Component {
{i.type_ == 'posts' && ( { )} {i.type_ == 'comments' && ( {
{i.type === 'posts' ? ( { /> ) : ( { console.log(`Connected to ${wsUri}`); - if (UserService.Instance.user) { - this.userJoin(); - } - if (!firstConnect) { let res: WebSocketJsonResponse = { reconnect: true,