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

pull/1049/head
Dessalines 4 years ago
parent dee5c302a8
commit c76e72b747

@ -275,21 +275,21 @@ export class Inbox extends Component<any, InboxState> {
); );
} }
all() { combined(): Array<ReplyType> {
let combined: Array<ReplyType> = []; return [
...this.state.replies,
combined.push(...this.state.replies); ...this.state.mentions,
combined.push(...this.state.mentions); ...this.state.messages,
combined.push(...this.state.messages); ].sort((a, b) => b.published.localeCompare(a.published));
}
// Sort it
combined.sort((a, b) => b.published.localeCompare(a.published));
all() {
return ( return (
<div> <div>
{combined.map(i => {this.combined().map(i =>
isCommentType(i) ? ( isCommentType(i) ? (
<CommentNodes <CommentNodes
key={i.id}
nodes={[{ comment: i }]} nodes={[{ comment: i }]}
noIndent noIndent
markable markable
@ -298,7 +298,7 @@ export class Inbox extends Component<any, InboxState> {
enableDownvotes={this.state.site.enable_downvotes} enableDownvotes={this.state.site.enable_downvotes}
/> />
) : ( ) : (
<PrivateMessage privateMessage={i} /> <PrivateMessage key={i.id} privateMessage={i} />
) )
)} )}
</div> </div>
@ -325,6 +325,7 @@ export class Inbox extends Component<any, InboxState> {
<div> <div>
{this.state.mentions.map(mention => ( {this.state.mentions.map(mention => (
<CommentNodes <CommentNodes
key={mention.id}
nodes={[{ comment: mention }]} nodes={[{ comment: mention }]}
noIndent noIndent
markable markable
@ -341,7 +342,7 @@ export class Inbox extends Component<any, InboxState> {
return ( return (
<div> <div>
{this.state.messages.map(message => ( {this.state.messages.map(message => (
<PrivateMessage privateMessage={message} /> <PrivateMessage key={message.id} privateMessage={message} />
))} ))}
</div> </div>
); );
@ -565,7 +566,6 @@ export class Inbox extends Component<any, InboxState> {
} else if (data.comment.creator_id == UserService.Instance.user.id) { } else if (data.comment.creator_id == UserService.Instance.user.id) {
toast(i18n.t('reply_sent')); toast(i18n.t('reply_sent'));
} }
this.setState(this.state);
} else if (res.op == UserOperation.CreatePrivateMessage) { } else if (res.op == UserOperation.CreatePrivateMessage) {
let data = res.data as PrivateMessageResponse; let data = res.data as PrivateMessageResponse;
if (data.message.recipient_id == UserService.Instance.user.id) { 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.replies.filter(r => !r.read).length +
this.state.mentions.filter(r => !r.read).length + this.state.mentions.filter(r => !r.read).length +
this.state.messages.filter( 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 ).length
); );
} }

@ -431,6 +431,7 @@ export class Navbar extends Component<any, NavbarState> {
// The login // The login
if (data.my_user) { if (data.my_user) {
UserService.Instance.user = data.my_user; UserService.Instance.user = data.my_user;
WebSocketService.Instance.userJoin();
// On the first load, check the unreads // On the first load, check the unreads
if (this.state.isLoggedIn == false) { if (this.state.isLoggedIn == false) {
this.requestNotificationPermission(); this.requestNotificationPermission();

@ -45,7 +45,10 @@ export class PrivateMessage extends Component<
} }
get mine(): boolean { 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() { render() {
@ -113,6 +116,7 @@ export class PrivateMessage extends Component<
<PrivateMessageForm <PrivateMessageForm
privateMessage={message} privateMessage={message}
onEdit={this.handlePrivateMessageEdit} onEdit={this.handlePrivateMessageEdit}
onCreate={this.handlePrivateMessageCreate}
onCancel={this.handleReplyCancel} onCancel={this.handleReplyCancel}
/> />
)} )}
@ -280,9 +284,14 @@ export class PrivateMessage extends Component<
this.setState(this.state); this.setState(this.state);
} }
handlePrivateMessageCreate() { handlePrivateMessageCreate(message: PrivateMessageI) {
this.state.showReply = false; if (
this.setState(this.state); UserService.Instance.user &&
toast(i18n.t('message_sent')); message.creator_id == UserService.Instance.user.id
) {
this.state.showReply = false;
this.setState(this.state);
toast(i18n.t('message_sent'));
}
} }
} }

@ -289,6 +289,7 @@ export class Search extends Component<any, SearchState> {
<div class="col-12"> <div class="col-12">
{i.type_ == 'posts' && ( {i.type_ == 'posts' && (
<PostListing <PostListing
key={(i.data as Post).id}
post={i.data as Post} post={i.data as Post}
showCommunity showCommunity
enableDownvotes={this.state.site.enable_downvotes} enableDownvotes={this.state.site.enable_downvotes}
@ -297,6 +298,7 @@ export class Search extends Component<any, SearchState> {
)} )}
{i.type_ == 'comments' && ( {i.type_ == 'comments' && (
<CommentNodes <CommentNodes
key={(i.data as Comment).id}
nodes={[{ comment: i.data as Comment }]} nodes={[{ comment: i.data as Comment }]}
locked locked
noIndent noIndent

@ -150,6 +150,7 @@ export class UserDetails extends Component<UserDetailsProps, UserDetailsState> {
<div> <div>
{i.type === 'posts' ? ( {i.type === 'posts' ? (
<PostListing <PostListing
key={(i.data as Post).id}
post={i.data as Post} post={i.data as Post}
admins={this.props.admins} admins={this.props.admins}
showCommunity showCommunity
@ -158,6 +159,7 @@ export class UserDetails extends Component<UserDetailsProps, UserDetailsState> {
/> />
) : ( ) : (
<CommentNodes <CommentNodes
key={(i.data as Comment).id}
nodes={[{ comment: i.data as Comment }]} nodes={[{ comment: i.data as Comment }]}
admins={this.props.admins} admins={this.props.admins}
noBorder noBorder

@ -82,10 +82,6 @@ export class WebSocketService {
this.ws.onopen = () => { this.ws.onopen = () => {
console.log(`Connected to ${wsUri}`); console.log(`Connected to ${wsUri}`);
if (UserService.Instance.user) {
this.userJoin();
}
if (!firstConnect) { if (!firstConnect) {
let res: WebSocketJsonResponse = { let res: WebSocketJsonResponse = {
reconnect: true, reconnect: true,

Loading…
Cancel
Save