PWA Fundvelo der Caritas.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

NavMenu.razor 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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.Location)) {
  107. Index = 1;
  108. } else if (e.Location.Contains("account")) {
  109. Index = 2;
  110. } else if (e.Location.Contains("extras")) {
  111. Index = 3;
  112. } else if (e.Location.Contains("info")) {
  113. Index = 4;
  114. } else {
  115. Index = 0;
  116. }
  117. StateHasChanged();
  118. }
  119. private bool IsInServicesUrl(string location) {
  120. return (location.Contains("caritas_services") || location.Contains("lost_found") || location.Contains("keydata")
  121. || location.Contains("account/") || location.Contains("conclusion_"));
  122. }
  123. private bool HandleAppBarContainer() {
  124. string uri = NavigationManager.Uri;
  125. string baseUri = NavigationManager.BaseUri;
  126. string delta = uri.Replace(baseUri, "");
  127. if (delta == null || delta.Equals("")) {
  128. return false;
  129. } else {
  130. if (IsInServicesUrl(delta)) {
  131. Index = 1;
  132. } else if (delta.Equals("account")) {
  133. Index = 2;
  134. } else if (delta.Equals("extras")) {
  135. Index = 3;
  136. } else if (delta.Equals("info")) {
  137. Index = 4;
  138. } else {
  139. Index = 0;
  140. }
  141. return true;
  142. }
  143. }
  144. private bool BackButtonDisabled() {
  145. return !PageHistoryManager.CanGoBack();
  146. }
  147. }