fix logout
continuous-integration/drone/push Build is passing Details

pull/40/head
Maxime BATISTA 2 years ago
parent 7a0eb8d0da
commit bf95cc70a5

@ -4,26 +4,30 @@ using Models;
using Models.Endpoint;
using LocalEndpoint;
public partial class App : Application, ConnectionObserver
public partial class App : Application, ConnectionObserver, IApp
{
private IEndpoint Endpoint = new LocalEndpoint();
private UserNotifier Notifier = new ConsoleUserNotifier();
public UserNotifier Notifier => new ConsoleUserNotifier();
public App()
{
InitializeComponent();
ForceLogin(); //start in login state
}
Shell shell = new ConnectAppShell(this, Endpoint.AccountManager, Notifier);
shell.GoToAsync("//Splash");
public void OnAccountConnected(Account account)
{
Shell shell = new MainAppShell(account, this);
shell.GoToAsync("//Main");
MainPage = shell;
}
public void OnAccountConnected(Account account)
public void ForceLogin()
{
Shell shell = new MainAppShell(account, Notifier);
shell.GoToAsync("//MainPage");
Shell shell = new ConnectAppShell(this, Endpoint.AccountManager, Notifier);
shell.GoToAsync("//Splash");
MainPage = shell;
}
}

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShoopNCook.Controllers
{
public class MorePageController
{
private readonly IApp app;
public MorePageController(IApp app) {
this.app = app;
}
public void Logout()
{
app.Notifier.Notice("You have been loged out.");
app.ForceLogin();
}
}
}

@ -0,0 +1,16 @@
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShoopNCook
{
public interface IApp
{
public UserNotifier Notifier { get; }
public void ForceLogin();
}
}

@ -1,16 +1,17 @@
namespace ShoopNCook;
using Microsoft.Maui.Controls;
using Models;
using ShoopNCook.Controllers;
using ShoopNCook.Pages;
public partial class MainAppShell : Shell
{
public MainAppShell(Account account, UserNotifier notifier)
public MainAppShell(Account account, IApp app)
{
InitializeComponent();
HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, notifier));
FavoritesTab.ContentTemplate = new DataTemplate(() => new FavoritesPage(account, notifier));
MyListTab.ContentTemplate = new DataTemplate(() => new MyListPage(account, notifier));
MoreTab.ContentTemplate = new DataTemplate(() => new MorePage(account, notifier));
HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, app));
FavoritesTab.ContentTemplate = new DataTemplate(() => new FavoritesPage(account, app));
MyListTab.ContentTemplate = new DataTemplate(() => new MyListPage(account, app));
MoreTab.ContentTemplate = new DataTemplate(() => new MorePage(account, new MorePageController(app)));
}
}

@ -4,7 +4,7 @@ namespace ShoopNCook.Pages;
public partial class FavoritesPage : ContentPage
{
public FavoritesPage(Account account, UserNotifier notifier)
public FavoritesPage(Account account, IApp app)
{
InitializeComponent();
}

@ -14,7 +14,7 @@
AlignItems="Center"
AlignContent="Center"
Margin="20,35,20,20">
<Border
Style="{StaticResource SecondaryBorder}"
BackgroundColor="{StaticResource BackgroundSecondary}"
@ -23,10 +23,12 @@
x:Name="ProfilePictureImage"
WidthRequest="65"
HeightRequest="65"/>
</Border>
</Border>
<Label Style="{StaticResource h1}" x:Name="ProfilePictureName"/>
</FlexLayout>
<Grid
ColumnDefinitions="*,Auto"
ColumnDefinitions="*,Auto"
Grid.Row="1"
Margin="20">

@ -4,10 +4,11 @@ namespace ShoopNCook.Pages;
public partial class HomePage : ContentPage
{
public HomePage(Account account, UserNotifier notifier)
public HomePage(Account account, IApp app)
{
InitializeComponent();
ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
ProfilePictureName.Text = account.User.Name;
}
private async void OnSyncButtonClicked(object sender, EventArgs e)
{

@ -1,16 +1,21 @@
using Models;
using ShoopNCook.Controllers;
namespace ShoopNCook.Pages;
public partial class MorePage : ContentPage
{
public MorePage(Account account, UserNotifier notifier)
private readonly MorePageController controller;
public MorePage(Account account, MorePageController controller)
{
InitializeComponent();
ProfileImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
ProfileName.Text = account.User.Name;
this.controller = controller;
}
private async void OnMyRecipesButtonTapped(object sender, EventArgs e)
{
await Shell.Current.Navigation.PushAsync(new MyRecipesPage());
@ -21,9 +26,9 @@ public partial class MorePage : ContentPage
await Shell.Current.Navigation.PushAsync(new ProfilePage());
}
private async void OnLogoutButtonTapped(object sender, EventArgs e)
private void OnLogoutButtonTapped(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("//Login");
controller.Logout();
}
private async void OnShareButtonClicked(object sender, EventArgs e)
{

@ -4,7 +4,7 @@ namespace ShoopNCook.Pages;
public partial class MyListPage : ContentPage
{
public MyListPage(Account account, UserNotifier notifier)
public MyListPage(Account account, IApp app)
{
InitializeComponent();
}

Loading…
Cancel
Save