Skip to content

Commit

Permalink
example: check channel query state before closing the menu
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Sep 11, 2024
1 parent 00d76ce commit e882781
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
16 changes: 15 additions & 1 deletion docusaurus/docs/Angular/code-examples/responsive-layout.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,21 @@ Lastly, implement auto close behavior for the channel list:

```html
<stream-channel-list
(click)="isMenuOpen = false"
(click)="closeMenu()"
class="channel-list menu-{{ isMenuOpen ? 'open' : 'close' }}"
></stream-channel-list>
```

```ts
closeMenu() {
let isChannelQuieryInProgress = false;
this.channelService.channelQueryState$.pipe(take(1)).subscribe((state) => {
if (state?.state === 'in-progress') {
isChannelQuieryInProgress = true;
}
});
if (!isChannelQuieryInProgress) {
this.isMenuOpen = false;
}
}
```
12 changes: 10 additions & 2 deletions projects/sample-app/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ViewChild,
} from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { map, take } from 'rxjs/operators';
import {
ChatClientService,
ChannelService,
Expand Down Expand Up @@ -78,6 +78,14 @@ export class AppComponent implements AfterViewInit {
}

closeMenu() {
this.isMenuOpen = false;
let isChannelQuieryInProgress = false;
this.channelService.channelQueryState$.pipe(take(1)).subscribe((state) => {
if (state?.state === 'in-progress') {
isChannelQuieryInProgress = true;
}
});
if (!isChannelQuieryInProgress) {
this.isMenuOpen = false;
}
}
}

0 comments on commit e882781

Please sign in to comment.