Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnItemClick stored in ReplaySubject cause logout right after login #695

Closed
1 of 2 tasks
thomas-tewelde opened this issue Sep 6, 2018 · 3 comments · Fixed by #724
Closed
1 of 2 tasks

OnItemClick stored in ReplaySubject cause logout right after login #695

thomas-tewelde opened this issue Sep 6, 2018 · 3 comments · Fixed by #724

Comments

@thomas-tewelde
Copy link

thomas-tewelde commented Sep 6, 2018

Issue type

I'm submitting a ... (check one with "x")

  • bug report
  • feature request

Issue description

Current behavior:
@nnixaa I am subscribing to onItemClick then logout from the logout menu item is selected.

this.menuService.onItemClick()
    .pipe(takeUntil(this.ngUnsubscribe))
    .subscribe(item => {
      if (item.item.title === this.logoutMenuItem.title) {
        this.logout();
      }
    });

it successfully logs but on login again the onItemClick is triggered therefore logs out
user immediately. That's because from the code the clicked items are stored in ReplaySubject

const itemClick$ = new ReplaySubject<NbMenuBag>(1);

Expected behavior:
i want on logout the ReplaySubject cache to be cleared out.

Steps to reproduce:
May be add an option to pass a null value as the last clicked item, so that the user has
an option to pass null menu item. so when the subscription picks up the replay it won't do anything.

Related code:

Other information:

Angular, Nebular

    "@nebular/theme": "^2.0.0-rc.9"
@thomas-tewelde
Copy link
Author

thomas-tewelde commented Sep 6, 2018

my solution is to ignore replay with out user interaction

 private contentInit = false;
ngAfterContentInit() {
    this.contentInit = true;
  }
// trigger logout
    this.menuService.onItemClick()
    .pipe(takeUntil(this.ngUnsubscribe))
    .subscribe(item => {
      if (item.item.title === this.logoutMenuItem.title && this.contentInit === true) {
        this.logout();
      }
    });

i hope it helps someone.

@pdelorme
Copy link

I had the exact same problem.
Your solution is fixing it. Thanks !
However, this should be left as a open bug since onItemClick() doesnt behave as expected.

@nnixaa nnixaa reopened this Sep 11, 2018
nnixaa pushed a commit that referenced this issue Sep 20, 2018
…724)

BREAKING CHANGE:

The `NbMenuService` not reply the last click event.

To Update:
if you use the knowledge that the last click event is replied you can wrap `onItemClick` stream in the custom stream based on `ReplaySubject`.

Closes #695
@chris7716
Copy link

@thom7kick could you plz provide me some more detailed explanation of the solution :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants