PWA Fundvelo der Caritas.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NavMenu.razor 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. @using cwebplusApp.Shared.Services;
  2. @using cwebplusApp.Components;
  3. @inject AppState AppState;
  4. @inject NavigationManager NavigationManager;
  5. @inject IStringLocalizer<Resources> i18n
  6. @inject IJSRuntime jsRuntime;
  7. @inject PageHistoryManager PageHistoryManager;
  8. @implements IDisposable;
  9. @if (HandleAppBarContainer()) {
  10. <div class="sidebar">
  11. <MatAppBarContainer>
  12. <MatAppBar Fixed="true">
  13. <MatAppBarRow>
  14. <MatAppBarSection>
  15. <MatIconButton Icon="menu" OnClick="@((e) => ButtonClicked())"></MatIconButton>
  16. @if (PageHistoryManager.CanGoBack()) {
  17. <MatIconButton Icon="keyboard_backspace" OnClick="@((e) => ButtonBackClicked())" Disabled="@BackButtonDisabled()"></MatIconButton>
  18. }
  19. <MatAppBarTitle Class="navBar-title">@LocationUrl</MatAppBarTitle>
  20. </MatAppBarSection>
  21. <MatAppBarSection align="@MatAppBarSectionAlign.End" Style="max-width:min-content">
  22. <NavLink rel="noopener" target="_blank" class="text-white small" href="https://www.caritas.ch" align="@MatAppBarSectionAlign.End" style="padding-right:1em">@i18n["Learnmore"]</NavLink>
  23. </MatAppBarSection>
  24. </MatAppBarRow>
  25. </MatAppBar>
  26. <MatAppBarContent>
  27. <MatDrawerContainer>
  28. <MatDrawer @bind-Opened="@Opened" Mode="@MatDrawerMode.Modal">
  29. <MatList>
  30. <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
  31. <MatListItem Class="@((Index == 1) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
  32. Href="caritas_services"
  33. @onclick="@((e) => ButtonClicked(1))">
  34. <MatIcon Icon="@MatIconNames.Apps"></MatIcon>
  35. <MatListItemText Style="padding-left:0.5em">@i18n["CaritasServices"]</MatListItemText>
  36. </MatListItem>
  37. </MatRipple>
  38. <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
  39. <MatListItem Class="@((Index == 2) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
  40. Href="account"
  41. @onclick="@((e) => ButtonClicked(2))">
  42. <MatIcon Icon="@MatIconNames.Person_outline"></MatIcon>
  43. <MatListItemText Style="padding-left:0.5em">@i18n["account"]</MatListItemText>
  44. </MatListItem>
  45. </MatRipple>
  46. <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
  47. <MatListItem Class="@((Index == 3) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
  48. Href="info"
  49. @onclick="@((e) => ButtonClicked(3))">
  50. <MatIcon Icon="@MatIconNames.Error_outline" Style="transform: rotate(180deg)"></MatIcon>
  51. <MatListItemText Style="padding-left:0.5em">@i18n["info"]</MatListItemText>
  52. </MatListItem>
  53. </MatRipple>
  54. <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
  55. <MatListItem Class="@((Index == 4) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
  56. href=""
  57. Match="NavLinkMatch.All"
  58. @onclick="@((e) => ButtonClicked(4))">
  59. <MatIcon Icon="@MatIconNames.Exit_to_app"></MatIcon>
  60. <MatListItemText Style="padding-left:0.5em">@i18n["Logout"]</MatListItemText>
  61. </MatListItem>
  62. </MatRipple>
  63. </MatList>
  64. </MatDrawer>
  65. </MatDrawerContainer>
  66. </MatAppBarContent>
  67. </MatAppBarContainer>
  68. </div>
  69. <OnlineStatusIndicator />
  70. }
  71. @code {
  72. private bool Opened = false;
  73. private static int Index = 1;
  74. private string locUrl;
  75. private string LocationUrl {
  76. get => locUrl;
  77. set {
  78. locUrl = value;
  79. StateHasChanged();
  80. }
  81. }
  82. public void Dispose() {
  83. AppState.OnChange -= StateHasChanged;
  84. NavigationManager.LocationChanged -= LocationChanged;
  85. }
  86. protected override void OnInitialized() {
  87. AppState.OnChange += StateHasChanged;
  88. NavigationManager.LocationChanged += LocationChanged;
  89. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  90. base.OnInitialized();
  91. }
  92. private void ButtonClicked() {
  93. Opened = !Opened;
  94. }
  95. private void ButtonClicked(int _Index) {
  96. Index = _Index;
  97. ButtonClicked();
  98. if (_Index == 4) {
  99. AppState.LoggedIn = false;
  100. }
  101. }
  102. private void ButtonBackClicked() {
  103. PageHistoryManager.NavigateBack();
  104. }
  105. private void LocationChanged(object sender, LocationChangedEventArgs e) {
  106. locUrl = i18n.GetString(e.Location.Replace(NavigationManager.BaseUri, ""));
  107. if (IsInServicesUrl(e)) {
  108. Index = 1;
  109. } else if (e.Location.Contains("account")) {
  110. Index = 2;
  111. } else if (e.Location.Contains("info")) {
  112. Index = 3;
  113. } else {
  114. Index = 4;
  115. }
  116. StateHasChanged();
  117. }
  118. private bool IsInServicesUrl(LocationChangedEventArgs e) {
  119. return (e.Location.Contains("caritas_services") || e.Location.Contains("lost_found") || e.Location.Contains("keydata")
  120. || e.Location.Contains("account/") || e.Location.Contains("conclusion_"));
  121. }
  122. private bool HandleAppBarContainer() {
  123. string uri = NavigationManager.Uri;
  124. string baseUri = NavigationManager.BaseUri;
  125. string delta = uri.Replace(baseUri, "");
  126. if (delta == null || delta.Equals("")) {
  127. Index = 4;
  128. return false;
  129. } else {
  130. if (delta.Equals("caritas_services")) {
  131. Index = 1;
  132. } else if (delta.Equals("account")) {
  133. Index = 2;
  134. } else if (delta.Equals("info")) {
  135. Index = 3;
  136. }
  137. return true;
  138. }
  139. }
  140. private bool BackButtonDisabled() {
  141. return !PageHistoryManager.CanGoBack();
  142. }
  143. }