PWA Fundvelo der Caritas.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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