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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. @inject AppState AppState;
  2. @inject NavigationManager NavigationManager;
  3. @implements IDisposable;
  4. @if (handleAppBarContainer()) {
  5. <div class="sidebar">
  6. <MatAppBarContainer>
  7. <MatAppBar Fixed="true">
  8. <MatAppBarRow>
  9. <MatAppBarSection>
  10. <MatIconButton Icon="menu" OnClick="@((e) => ButtonClicked())"></MatIconButton>
  11. <MatAppBarTitle>CaritasPWA</MatAppBarTitle>
  12. </MatAppBarSection>
  13. <MatAppBarSection Align="@MatAppBarSectionAlign.End">
  14. <NavLink class="text-white" href="http://www.caritas.ch" Align="@MatAppBarSectionAlign.End" Style="padding-right:1em">About</NavLink>
  15. </MatAppBarSection>
  16. </MatAppBarRow>
  17. </MatAppBar>
  18. <MatAppBarContent>
  19. <MatDrawerContainer>
  20. <MatDrawer @bind-Opened="@Opened" Mode="@MatDrawerMode.Modal">
  21. <MatList>
  22. <MatListItem Class="@((Index == 1) ? "bg-primary-color text-white" : "")"
  23. Href="caritas_services"
  24. @onclick="@((e) => ButtonClicked(1))">
  25. <MatIcon Icon="@MatIconNames.Apps"></MatIcon>
  26. <MatListItemText Style="padding-left:0.5em">Caritas Dienste</MatListItemText>
  27. </MatListItem>
  28. <MatListItem Class="@((Index == 2) ? "bg-primary-color text-white" : "")"
  29. Href="account"
  30. @onclick="@((e) => ButtonClicked(2))">
  31. <MatIcon Icon="@MatIconNames.Person_outline"></MatIcon>
  32. <MatListItemText Style="padding-left:0.5em">Konto</MatListItemText>
  33. </MatListItem>
  34. <MatListItem Class="@((Index == 3) ? "bg-primary-color text-white" : "")"
  35. Href="info"
  36. @onclick="@((e) => ButtonClicked(3))">
  37. <MatIcon Icon="@MatIconNames.Error_outline" Style="transform: rotate(180deg)"></MatIcon>
  38. <MatListItemText Style="padding-left:0.5em">Info</MatListItemText>
  39. </MatListItem>
  40. <MatListItem Class="@((Index == 4) ? "bg-primary-color text-white" : "")"
  41. href=""
  42. Match="NavLinkMatch.All"
  43. @onclick="@((e) => ButtonClicked(4))">
  44. <MatIcon Icon="@MatIconNames.Exit_to_app"></MatIcon>
  45. <MatListItemText Style="padding-left:0.5em">Logout</MatListItemText>
  46. </MatListItem>
  47. </MatList>
  48. </MatDrawer>
  49. </MatDrawerContainer>
  50. </MatAppBarContent>
  51. </MatAppBarContainer>
  52. </div>
  53. }
  54. @code
  55. {
  56. bool Opened = false;
  57. static int Index = 1;
  58. void ButtonClicked() {
  59. Opened = !Opened;
  60. }
  61. void ButtonClicked(int _Index) {
  62. Index = _Index;
  63. ButtonClicked();
  64. if (_Index == 4) {
  65. AppState.LoggedIn = false;
  66. }
  67. }
  68. protected override void OnInitialized() {
  69. AppState.OnChange += StateHasChanged;
  70. NavigationManager.LocationChanged += LocationChanged;
  71. base.OnInitialized();
  72. }
  73. public void Dispose() {
  74. AppState.OnChange -= StateHasChanged;
  75. NavigationManager.LocationChanged -= LocationChanged;
  76. }
  77. void LocationChanged(object sender, LocationChangedEventArgs e) {
  78. string navigationMethod = e.IsNavigationIntercepted ? "HTML" : "code";
  79. System.Diagnostics.Debug.WriteLine($"Notified of navigation via {navigationMethod} to {e.Location}");
  80. if (e.Location.Contains("caritas_services")) {
  81. Index = 1;
  82. } else if(e.Location.Contains("account")) {
  83. Index = 2;
  84. } else if (e.Location.Contains("info")) {
  85. Index = 3;
  86. } else {
  87. Index = 4;
  88. }
  89. }
  90. bool handleAppBarContainer() {
  91. string uri = NavigationManager.Uri;
  92. string baseUri = NavigationManager.BaseUri;
  93. string delta = uri.Replace(baseUri, "");
  94. if (delta == null || delta.Equals("")) {
  95. Index = 4;
  96. return false;
  97. } else {
  98. if (delta.Equals("caritas_services")) {
  99. Index = 1;
  100. } else if (delta.Equals("account")) {
  101. Index = 2;
  102. } else if (delta.Equals("info")) {
  103. Index = 3;
  104. }
  105. return true;
  106. }
  107. }
  108. }