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 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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="@MatIconNames.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. Disabled="true"
  49. Href="extras"
  50. @onclick="@((e) => ButtonClicked(3))">
  51. <MatIcon Icon="@MatIconNames.View_quilt"></MatIcon>
  52. <MatListItemText Style="padding-left:0.5em">@i18n["Extras"]</MatListItemText>
  53. </MatListItem>
  54. </MatRipple>
  55. <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
  56. <MatListItem Class="@((Index == 4) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
  57. Href="info"
  58. @onclick="@((e) => ButtonClicked(4))">
  59. <MatIcon Icon="@MatIconNames.Error_outline" Style="transform: rotate(180deg)"></MatIcon>
  60. <MatListItemText Style="padding-left:0.5em">@i18n["info"]</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. base.OnInitialized();
  88. AppState.OnChange += StateHasChanged;
  89. NavigationManager.LocationChanged += LocationChanged;
  90. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  91. locUrl = i18n.GetString(NavigationManager.Uri.Replace(NavigationManager.BaseUri, ""));
  92. StateHasChanged();
  93. }
  94. private void ButtonClicked() {
  95. Opened = !Opened;
  96. }
  97. private void ButtonClicked(int _Index) {
  98. Index = _Index;
  99. ButtonClicked();
  100. }
  101. private void ButtonBackClicked() {
  102. PageHistoryManager.NavigateBack();
  103. }
  104. private void LocationChanged(object sender, LocationChangedEventArgs e) {
  105. locUrl = i18n.GetString(e.Location.Replace(NavigationManager.BaseUri, ""));
  106. if (IsInServicesUrl(e)) {
  107. Index = 1;
  108. } else if (e.Location.Contains("account")) {
  109. Index = 2;
  110. } else if (e.Location.Contains("info")) {
  111. Index = 4;
  112. } else {
  113. Index = 3;
  114. }
  115. StateHasChanged();
  116. }
  117. private bool IsInServicesUrl(LocationChangedEventArgs e) {
  118. return (e.Location.Contains("caritas_services") || e.Location.Contains("lost_found") || e.Location.Contains("keydata")
  119. || e.Location.Contains("account/") || e.Location.Contains("conclusion_"));
  120. }
  121. private bool HandleAppBarContainer() {
  122. string uri = NavigationManager.Uri;
  123. string baseUri = NavigationManager.BaseUri;
  124. string delta = uri.Replace(baseUri, "");
  125. if (delta.Equals("caritas_services")) {
  126. Index = 1;
  127. } else if (delta.Equals("account")) {
  128. Index = 2;
  129. } else if (delta.Equals("info")) {
  130. Index = 4;
  131. } else {
  132. Index = 3;
  133. }
  134. return true;
  135. }
  136. private bool BackButtonDisabled() {
  137. return !PageHistoryManager.CanGoBack();
  138. }
  139. }