Fixing an issue with comments clearing out forms. Fixes #1045

This commit is contained in:
Dessalines 2020-08-01 23:52:38 -04:00
parent dee5c302a8
commit c76e72b747
6 changed files with 36 additions and 23 deletions

View file

@ -275,21 +275,21 @@ export class Inbox extends Component<any, InboxState> {
);
}
combined(): Array<ReplyType> {
return [
...this.state.replies,
...this.state.mentions,
...this.state.messages,
].sort((a, b) => b.published.localeCompare(a.published));
}
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));
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
);
}

View 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();

View 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'));
}
}
}

View 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

View 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

View 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,