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 Models.Endpoint;
using LocalEndpoint; using LocalEndpoint;
public partial class App : Application, ConnectionObserver public partial class App : Application, ConnectionObserver, IApp
{ {
private IEndpoint Endpoint = new LocalEndpoint(); private IEndpoint Endpoint = new LocalEndpoint();
private UserNotifier Notifier = new ConsoleUserNotifier();
public UserNotifier Notifier => new ConsoleUserNotifier();
public App() public App()
{ {
InitializeComponent(); InitializeComponent();
ForceLogin(); //start in login state
}
public void OnAccountConnected(Account account)
Shell shell = new ConnectAppShell(this, Endpoint.AccountManager, Notifier); {
shell.GoToAsync("//Splash"); Shell shell = new MainAppShell(account, this);
shell.GoToAsync("//Main");
MainPage = shell; MainPage = shell;
} }
public void OnAccountConnected(Account account) public void ForceLogin()
{ {
Shell shell = new MainAppShell(account, Notifier); Shell shell = new ConnectAppShell(this, Endpoint.AccountManager, Notifier);
shell.GoToAsync("//MainPage"); shell.GoToAsync("//Splash");
MainPage = shell; 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; namespace ShoopNCook;
using Microsoft.Maui.Controls; using Microsoft.Maui.Controls;
using Models; using Models;
using ShoopNCook.Controllers;
using ShoopNCook.Pages; using ShoopNCook.Pages;
public partial class MainAppShell : Shell public partial class MainAppShell : Shell
{ {
public MainAppShell(Account account, UserNotifier notifier) public MainAppShell(Account account, IApp app)
{ {
InitializeComponent(); InitializeComponent();
HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, notifier)); HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, app));
FavoritesTab.ContentTemplate = new DataTemplate(() => new FavoritesPage(account, notifier)); FavoritesTab.ContentTemplate = new DataTemplate(() => new FavoritesPage(account, app));
MyListTab.ContentTemplate = new DataTemplate(() => new MyListPage(account, notifier)); MyListTab.ContentTemplate = new DataTemplate(() => new MyListPage(account, app));
MoreTab.ContentTemplate = new DataTemplate(() => new MorePage(account, notifier)); MoreTab.ContentTemplate = new DataTemplate(() => new MorePage(account, new MorePageController(app)));
} }
} }

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

@ -24,6 +24,8 @@
WidthRequest="65" WidthRequest="65"
HeightRequest="65"/> HeightRequest="65"/>
</Border> </Border>
<Label Style="{StaticResource h1}" x:Name="ProfilePictureName"/>
</FlexLayout> </FlexLayout>
<Grid <Grid
ColumnDefinitions="*,Auto" ColumnDefinitions="*,Auto"

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

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

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

Loading…
Cancel
Save