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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. if (e.Location.Contains("caritas_services")) {
  79. Index = 1;
  80. } else if(e.Location.Contains("account")) {
  81. Index = 2;
  82. } else if (e.Location.Contains("info")) {
  83. Index = 3;
  84. } else {
  85. Index = 4;
  86. }
  87. }
  88. bool handleAppBarContainer() {
  89. string uri = NavigationManager.Uri;
  90. string baseUri = NavigationManager.BaseUri;
  91. string delta = uri.Replace(baseUri, "");
  92. if (delta == null || delta.Equals("")) {
  93. Index = 4;
  94. return false;
  95. } else {
  96. if (delta.Equals("caritas_services")) {
  97. Index = 1;
  98. } else if (delta.Equals("account")) {
  99. Index = 2;
  100. } else if (delta.Equals("info")) {
  101. Index = 3;
  102. }
  103. return true;
  104. }
  105. }
  106. }