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' ;
1616import { CoreSiteInfo } from '@classes/sites/unauthenticated-site' ;
1717import { IonRouterOutlet } from '@ionic/angular' ;
1818import { CoreSites } from '@services/sites' ;
1919import { CoreModals } from '@services/overlays/modals' ;
2020import CoreMainMenuPage from '@features/mainmenu/pages/menu/menu' ;
2121import { toBoolean } from '@/core/transforms/boolean' ;
2222import { 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} )
3738export 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