Skip to content

Commit 588dc7d

Browse files
committed
MOBILE-4842 menu: User menu button to signals
1 parent 758673e commit 588dc7d

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@if ((alwaysShow || (isMainScreen && menuPage?.tabsPlacement() === 'bottom')) && siteInfo) {
2-
<core-user-avatar [site]="siteInfo" class="core-bar-button-image clickable" [linkProfile]="false"
1+
@if (showButton()) {
2+
<core-user-avatar [site]="siteInfo()" class="core-bar-button-image clickable" [linkProfile]="false"
33
(ariaButtonClick)="openUserMenu($event)" [attr.aria-label]="'core.user.useraccount' | translate" />
44
}

src/core/features/mainmenu/components/user-menu-button/user-menu-button.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { Component, Input, OnInit, inject } from '@angular/core';
15+
import { Component, OnInit, inject, input, linkedSignal, signal } from '@angular/core';
1616
import { CoreSiteInfo } from '@classes/sites/unauthenticated-site';
1717
import { IonRouterOutlet } from '@ionic/angular';
1818
import { CoreSites } from '@services/sites';
1919
import { CoreModals } from '@services/overlays/modals';
2020
import CoreMainMenuPage from '@features/mainmenu/pages/menu/menu';
2121
import { toBoolean } from '@/core/transforms/boolean';
2222
import { CoreSharedModule } from '@/core/shared.module';
23+
import { CoreMainMenuPlacement } from '@features/mainmenu/constants';
2324

2425
/**
2526
* Component to display an avatar on the header to open user menu.
@@ -36,23 +37,43 @@ import { CoreSharedModule } from '@/core/shared.module';
3637
})
3738
export class CoreMainMenuUserButtonComponent implements OnInit {
3839

39-
@Input({ transform: toBoolean }) alwaysShow = false;
40+
readonly alwaysShow = input(false, { transform: toBoolean });
4041

41-
siteInfo?: CoreSiteInfo;
42-
isMainScreen = false;
42+
readonly siteInfo = signal<CoreSiteInfo | undefined>(undefined);
43+
readonly showButton = linkedSignal(() => this.shouldShowButton());
4344

4445
protected routerOutlet = inject(IonRouterOutlet);
4546
protected menuPage = inject(CoreMainMenuPage, { optional: true });
4647

4748
constructor() {
48-
this.siteInfo = CoreSites.getCurrentSite()?.getInfo();
49+
this.siteInfo.set(CoreSites.getCurrentSite()?.getInfo());
4950
}
5051

5152
/**
5253
* @inheritdoc
5354
*/
5455
ngOnInit(): void {
55-
this.isMainScreen = !this.routerOutlet.canGoBack();
56+
this.showButton.set(this.shouldShowButton());
57+
}
58+
59+
/**
60+
* Determine if the button should be shown.
61+
*
62+
* @returns True if the button should be shown, false otherwise.
63+
*/
64+
protected shouldShowButton(): boolean {
65+
if (!this.siteInfo()) {
66+
return false;
67+
}
68+
69+
if (this.alwaysShow()) {
70+
return true;
71+
}
72+
73+
const isMainScreen = !this.routerOutlet.canGoBack();
74+
const tabsPlacement = this.menuPage?.tabsPlacement();
75+
76+
return isMainScreen && tabsPlacement === CoreMainMenuPlacement.BOTTOM;
5677
}
5778

5879
/**

0 commit comments

Comments
 (0)