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.
SAE-2.01/MCTG/Views/ContentPages/MyPosts.xaml.cs

52 lines
1.5 KiB

using CommunityToolkit.Maui.Storage;
using Model;
namespace Views;
public partial class MyPosts : ContentPage
{
public MasterManager Master => (Application.Current as App).Master;
private readonly RecipeCollection _recipesDisplayed;
public ReadOnlyObservableRecipeCollection RecipesDisplayed { get; private set; }
public Recipe Recipe => Master.Recipe.CurrentSelected;
public MyPosts()
{
_recipesDisplayed = Master.Recipe.GetRecipeByAuthor(Master.User.CurrentConnected.Mail);
RecipesDisplayed = new ReadOnlyObservableRecipeCollection(_recipesDisplayed);
InitializeComponent();
BindingContext = this;
}
private void MyInformations_Clicked(object sender, EventArgs e)
{
Navigation.PopModalAsync();
}
private void AddRecipe_Clicked(object sender, EventArgs e)
{
Navigation.PushModalAsync(new AddRecipe());
}
private async void ExportRecipe_Clicked(object sender, EventArgs e)
{
var result = await FolderPicker.Default.PickAsync(FileSystem.Current.AppDataDirectory, new CancellationToken());
Master.Recipe.CurrentSelected = (Recipe)(sender as MenuFlyoutItem).BindingContext;
if (result.IsSuccessful)
{
Master.Data.Export(Recipe, Path.Combine(result.Folder.Path, $"{Recipe.Id}.{Recipe.Title.Replace(" ", "")}.json"));
await DisplayAlert("Export", "Recipe was successfully exported.", "Ok");
}
else
{
await DisplayAlert("Export", "Unable to export recipe.", "Ok");
}
}
}