From 2abe399ebd714e9d657d90981c70c19880a4f1f5 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 11 Jun 2022 12:56:34 +0200 Subject: [PATCH] Bugfix/force reload accounts of user after change (#994) * Force reload of accounts after change * Update changelog --- CHANGELOG.md | 1 + apps/api/src/app/user/user.service.ts | 4 ++++ .../app/pages/accounts/accounts-page.component.ts | 15 +++++++++++++++ .../src/app/services/user/user-store.actions.ts | 1 + apps/client/src/app/services/user/user.service.ts | 6 +++--- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93be00b6a..723fd8aac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Reloaded the accounts of a user after creating, editing or deleting one - Excluded empty items in the activities filter ## 1.156.0 - 05.06.2022 diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts index d0c30386e..f3a0cab93 100644 --- a/apps/api/src/app/user/user.service.ts +++ b/apps/api/src/app/user/user.service.ts @@ -12,6 +12,7 @@ import { } from '@ghostfolio/common/permissions'; import { Injectable } from '@nestjs/common'; import { Prisma, Role, User, ViewMode } from '@prisma/client'; +import { sortBy } from 'lodash'; import { UserSettingsParams } from './interfaces/user-settings-params.interface'; import { UserSettings } from './interfaces/user-settings.interface'; @@ -185,6 +186,9 @@ export class UserService { } } + user.Account = sortBy(user.Account, (account) => { + return account.name; + }); user.permissions = currentPermissions.sort(); return user; diff --git a/apps/client/src/app/pages/accounts/accounts-page.component.ts b/apps/client/src/app/pages/accounts/accounts-page.component.ts index 60eb1463b..624c2d3db 100644 --- a/apps/client/src/app/pages/accounts/accounts-page.component.ts +++ b/apps/client/src/app/pages/accounts/accounts-page.component.ts @@ -133,6 +133,11 @@ export class AccountsPageComponent implements OnDestroy, OnInit { .pipe(takeUntil(this.unsubscribeSubject)) .subscribe({ next: () => { + this.userService + .get(true) + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe(); + this.fetchAccounts(); } }); @@ -179,6 +184,11 @@ export class AccountsPageComponent implements OnDestroy, OnInit { .pipe(takeUntil(this.unsubscribeSubject)) .subscribe({ next: () => { + this.userService + .get(true) + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe(); + this.fetchAccounts(); } }); @@ -220,6 +230,11 @@ export class AccountsPageComponent implements OnDestroy, OnInit { .pipe(takeUntil(this.unsubscribeSubject)) .subscribe({ next: () => { + this.userService + .get(true) + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe(); + this.fetchAccounts(); } }); diff --git a/apps/client/src/app/services/user/user-store.actions.ts b/apps/client/src/app/services/user/user-store.actions.ts index cbacd70d0..15dc555a4 100644 --- a/apps/client/src/app/services/user/user-store.actions.ts +++ b/apps/client/src/app/services/user/user-store.actions.ts @@ -1,4 +1,5 @@ export enum UserStoreActions { GetUser = 'GET_USER', + Initialize = 'INITIALIZE', RemoveUser = 'REMOVE_USER' } diff --git a/apps/client/src/app/services/user/user.service.ts b/apps/client/src/app/services/user/user.service.ts index 2e6652591..79c15e085 100644 --- a/apps/client/src/app/services/user/user.service.ts +++ b/apps/client/src/app/services/user/user.service.ts @@ -16,13 +16,13 @@ export class UserService extends ObservableStore { public constructor(private http: HttpClient) { super({ trackStateHistory: true }); - this.setState({ user: undefined }, 'INIT_STATE'); + this.setState({ user: undefined }, UserStoreActions.Initialize); } - public get() { + public get(force = false) { const state = this.getState(); - if (state?.user) { + if (state?.user && force !== true) { // Get from cache return of(state.user); } else {