mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-05 16:39:55 +00:00
Fixing unread indicator on link click. Fixes #527
This commit is contained in:
parent
f1392dc9a7
commit
774518e4fe
5 changed files with 14 additions and 8 deletions
2
ui/src/components/inbox.tsx
vendored
2
ui/src/components/inbox.tsx
vendored
|
@ -443,9 +443,9 @@ export class Inbox extends Component<any, InboxState> {
|
||||||
this.state.messages.filter(
|
this.state.messages.filter(
|
||||||
r => !r.read && r.creator_id !== UserService.Instance.user.id
|
r => !r.read && r.creator_id !== UserService.Instance.user.id
|
||||||
).length;
|
).length;
|
||||||
|
UserService.Instance.user.unreadCount = count;
|
||||||
UserService.Instance.sub.next({
|
UserService.Instance.sub.next({
|
||||||
user: UserService.Instance.user,
|
user: UserService.Instance.user,
|
||||||
unreadCount: count,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
8
ui/src/components/navbar.tsx
vendored
8
ui/src/components/navbar.tsx
vendored
|
@ -60,8 +60,10 @@ export class Navbar extends Component<any, NavbarState> {
|
||||||
// Subscribe to user changes
|
// Subscribe to user changes
|
||||||
this.userSub = UserService.Instance.sub.subscribe(user => {
|
this.userSub = UserService.Instance.sub.subscribe(user => {
|
||||||
this.state.isLoggedIn = user.user !== undefined;
|
this.state.isLoggedIn = user.user !== undefined;
|
||||||
this.state.unreadCount = user.unreadCount;
|
if (this.state.isLoggedIn) {
|
||||||
this.requestNotificationPermission();
|
this.state.unreadCount = user.user.unreadCount;
|
||||||
|
this.requestNotificationPermission();
|
||||||
|
}
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -304,9 +306,9 @@ export class Navbar extends Component<any, NavbarState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
sendUnreadCount() {
|
sendUnreadCount() {
|
||||||
|
UserService.Instance.user.unreadCount = this.state.unreadCount;
|
||||||
UserService.Instance.sub.next({
|
UserService.Instance.sub.next({
|
||||||
user: UserService.Instance.user,
|
user: UserService.Instance.user,
|
||||||
unreadCount: this.state.unreadCount,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
ui/src/components/post.tsx
vendored
4
ui/src/components/post.tsx
vendored
|
@ -156,6 +156,10 @@ export class Post extends Component<any, PostState> {
|
||||||
auth: null,
|
auth: null,
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.editComment(form);
|
WebSocketService.Instance.editComment(form);
|
||||||
|
UserService.Instance.user.unreadCount--;
|
||||||
|
UserService.Instance.sub.next({
|
||||||
|
user: UserService.Instance.user,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
ui/src/interfaces.ts
vendored
1
ui/src/interfaces.ts
vendored
|
@ -93,6 +93,7 @@ export interface User {
|
||||||
lang: string;
|
lang: string;
|
||||||
avatar?: string;
|
avatar?: string;
|
||||||
show_avatars: boolean;
|
show_avatars: boolean;
|
||||||
|
unreadCount?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserView {
|
export interface UserView {
|
||||||
|
|
7
ui/src/services/UserService.ts
vendored
7
ui/src/services/UserService.ts
vendored
|
@ -7,9 +7,8 @@ import { Subject } from 'rxjs';
|
||||||
export class UserService {
|
export class UserService {
|
||||||
private static _instance: UserService;
|
private static _instance: UserService;
|
||||||
public user: User;
|
public user: User;
|
||||||
public sub: Subject<{ user: User; unreadCount: number }> = new Subject<{
|
public sub: Subject<{ user: User }> = new Subject<{
|
||||||
user: User;
|
user: User;
|
||||||
unreadCount: number;
|
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
|
@ -32,7 +31,7 @@ export class UserService {
|
||||||
this.user = undefined;
|
this.user = undefined;
|
||||||
Cookies.remove('jwt');
|
Cookies.remove('jwt');
|
||||||
setTheme();
|
setTheme();
|
||||||
this.sub.next({ user: undefined, unreadCount: 0 });
|
this.sub.next({ user: undefined });
|
||||||
console.log('Logged out.');
|
console.log('Logged out.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +44,7 @@ export class UserService {
|
||||||
if (this.user.theme != 'darkly') {
|
if (this.user.theme != 'darkly') {
|
||||||
setTheme(this.user.theme);
|
setTheme(this.user.theme);
|
||||||
}
|
}
|
||||||
this.sub.next({ user: this.user, unreadCount: 0 });
|
this.sub.next({ user: this.user });
|
||||||
console.log(this.user);
|
console.log(this.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue