summaryrefslogtreecommitdiffstats
path: root/ui/src/components/inbox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/components/inbox.tsx')
-rw-r--r--ui/src/components/inbox.tsx50
1 files changed, 32 insertions, 18 deletions
diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx
index 3b963a79..2bf1fb47 100644
--- a/ui/src/components/inbox.tsx
+++ b/ui/src/components/inbox.tsx
@@ -16,6 +16,7 @@ import {
GetPrivateMessagesForm,
PrivateMessagesResponse,
PrivateMessageResponse,
+ GetSiteResponse,
} from '../interfaces';
import { WebSocketService, UserService } from '../services';
import {
@@ -56,6 +57,7 @@ interface InboxState {
messages: Array<PrivateMessageI>;
sort: SortType;
page: number;
+ enableDownvotes: boolean;
}
export class Inbox extends Component<any, InboxState> {
@@ -68,6 +70,7 @@ export class Inbox extends Component<any, InboxState> {
messages: [],
sort: SortType.New,
page: 1,
+ enableDownvotes: undefined,
};
constructor(props: any, context: any) {
@@ -85,18 +88,13 @@ export class Inbox extends Component<any, InboxState> {
);
this.refetch();
+ WebSocketService.Instance.getSite();
}
componentWillUnmount() {
this.subscription.unsubscribe();
}
- componentDidMount() {
- document.title = `/u/${UserService.Instance.user.username} ${i18n.t(
- 'inbox'
- )} - ${WebSocketService.Instance.site.name}`;
- }
-
render() {
return (
<div class="container">
@@ -270,6 +268,7 @@ export class Inbox extends Component<any, InboxState> {
noIndent
markable
showContext
+ enableDownvotes={this.state.enableDownvotes}
/>
) : (
<PrivateMessage privateMessage={i} />
@@ -287,6 +286,7 @@ export class Inbox extends Component<any, InboxState> {
noIndent
markable
showContext
+ enableDownvotes={this.state.enableDownvotes}
/>
</div>
);
@@ -301,6 +301,7 @@ export class Inbox extends Component<any, InboxState> {
noIndent
markable
showContext
+ enableDownvotes={this.state.enableDownvotes}
/>
))}
</div>
@@ -328,12 +329,14 @@ export class Inbox extends Component<any, InboxState> {
{i18n.t('prev')}
</button>
)}
- <button
- class="btn btn-sm btn-secondary"
- onClick={linkEvent(this, this.nextPage)}
- >
- {i18n.t('next')}
- </button>
+ {this.unreadCount() > 0 && (
+ <button
+ class="btn btn-sm btn-secondary"
+ onClick={linkEvent(this, this.nextPage)}
+ >
+ {i18n.t('next')}
+ </button>
+ )}
</div>
);
}
@@ -522,19 +525,30 @@ export class Inbox extends Component<any, InboxState> {
let data = res.data as CommentResponse;
createCommentLikeRes(data, this.state.replies);
this.setState(this.state);
+ } else if (res.op == UserOperation.GetSite) {
+ let data = res.data as GetSiteResponse;
+ this.state.enableDownvotes = data.site.enable_downvotes;
+ this.setState(this.state);
+ document.title = `/u/${UserService.Instance.user.username} ${i18n.t(
+ 'inbox'
+ )} - ${data.site.name}`;
}
}
sendUnreadCount() {
- let count =
+ UserService.Instance.user.unreadCount = this.unreadCount();
+ UserService.Instance.sub.next({
+ user: UserService.Instance.user,
+ });
+ }
+
+ unreadCount(): number {
+ return (
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
- ).length;
- UserService.Instance.user.unreadCount = count;
- UserService.Instance.sub.next({
- user: UserService.Instance.user,
- });
+ ).length
+ );
}
}