| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- @inject AppState AppState;
- @inject NavigationManager NavigationManager;
- @implements IDisposable;
-
- @if (handleAppBarContainer()) {
- <div class="sidebar">
- <MatAppBarContainer>
- <MatAppBar Fixed="true">
- <MatAppBarRow>
- <MatAppBarSection>
- <MatIconButton Icon="menu" OnClick="@((e) => ButtonClicked())"></MatIconButton>
- <MatAppBarTitle>CaritasPWA</MatAppBarTitle>
- </MatAppBarSection>
- <MatAppBarSection Align="@MatAppBarSectionAlign.End">
- <NavLink class="text-white" href="http://www.caritas.ch" Align="@MatAppBarSectionAlign.End" Style="padding-right:1em">About</NavLink>
- </MatAppBarSection>
- </MatAppBarRow>
- </MatAppBar>
- <MatAppBarContent>
- <MatDrawerContainer>
- <MatDrawer @bind-Opened="@Opened" Mode="@MatDrawerMode.Modal">
- <MatList>
- <MatListItem Class="@((Index == 1) ? "bg-primary-color text-white" : "")"
- Href="caritas_services"
- @onclick="@((e) => ButtonClicked(1))">
- <MatIcon Icon="@MatIconNames.Apps"></MatIcon>
- <MatListItemText Style="padding-left:0.5em">Caritas Dienste</MatListItemText>
- </MatListItem>
- <MatListItem Class="@((Index == 2) ? "bg-primary-color text-white" : "")"
- Href="account"
- @onclick="@((e) => ButtonClicked(2))">
- <MatIcon Icon="@MatIconNames.Person_outline"></MatIcon>
- <MatListItemText Style="padding-left:0.5em">Konto</MatListItemText>
- </MatListItem>
- <MatListItem Class="@((Index == 3) ? "bg-primary-color text-white" : "")"
- Href="info"
- @onclick="@((e) => ButtonClicked(3))">
- <MatIcon Icon="@MatIconNames.Error_outline" Style="transform: rotate(180deg)"></MatIcon>
- <MatListItemText Style="padding-left:0.5em">Info</MatListItemText>
- </MatListItem>
- <MatListItem Class="@((Index == 4) ? "bg-primary-color text-white" : "")"
- href=""
- Match="NavLinkMatch.All"
- @onclick="@((e) => ButtonClicked(4))">
- <MatIcon Icon="@MatIconNames.Exit_to_app"></MatIcon>
- <MatListItemText Style="padding-left:0.5em">Logout</MatListItemText>
- </MatListItem>
- </MatList>
- </MatDrawer>
- </MatDrawerContainer>
-
- </MatAppBarContent>
- </MatAppBarContainer>
- </div>
- }
-
-
- @code
- {
- bool Opened = false;
-
- static int Index = 1;
-
- void ButtonClicked() {
- Opened = !Opened;
- }
-
- void ButtonClicked(int _Index) {
- Index = _Index;
- ButtonClicked();
- if (_Index == 4) {
- AppState.LoggedIn = false;
- }
- }
-
- protected override void OnInitialized() {
- AppState.OnChange += StateHasChanged;
- NavigationManager.LocationChanged += LocationChanged;
- base.OnInitialized();
- }
-
- public void Dispose() {
- AppState.OnChange -= StateHasChanged;
- NavigationManager.LocationChanged -= LocationChanged;
- }
-
-
- void LocationChanged(object sender, LocationChangedEventArgs e) {
- string navigationMethod = e.IsNavigationIntercepted ? "HTML" : "code";
- System.Diagnostics.Debug.WriteLine($"Notified of navigation via {navigationMethod} to {e.Location}");
- if (e.Location.Contains("caritas_services")) {
- Index = 1;
- } else if(e.Location.Contains("account")) {
- Index = 2;
- } else if (e.Location.Contains("info")) {
- Index = 3;
- } else {
- Index = 4;
- }
- }
-
- bool handleAppBarContainer() {
- string uri = NavigationManager.Uri;
- string baseUri = NavigationManager.BaseUri;
- string delta = uri.Replace(baseUri, "");
-
- if (delta == null || delta.Equals("")) {
- Index = 4;
- return false;
- } else {
- if (delta.Equals("caritas_services")) {
- Index = 1;
- } else if (delta.Equals("account")) {
- Index = 2;
- } else if (delta.Equals("info")) {
- Index = 3;
- }
- return true;
- }
- }
-
- }
|