search bar working
continuous-integration/drone/push Build is passing Details

pull/65/head
Alexandre AGOSTINHO 2 years ago
parent e563ffed77
commit 715d847f5f

@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
@ -12,14 +14,28 @@ namespace Model.Managers
/// <summary>
/// The Main manager of the model.
/// </summary>
public class MasterManager
public class MasterManager : INotifyPropertyChanged
{
#region Attributes & Properties
public event PropertyChangedEventHandler? PropertyChanged;
private RecipeCollection _recipesInSearch = new RecipeCollection("");
/// <summary>
/// The currently connected user. 'null' if no user is connected.
/// </summary>
public User? CurrentConnectedUser { get; private set; }
public RecipeCollection RecipesInSearch
{
get => _recipesInSearch;
set
{
_recipesInSearch = value;
OnPropertyChange();
}
}
/// <summary>
/// The collection of all recipes loaded.
/// </summary>
@ -46,6 +62,7 @@ namespace Model.Managers
DataMgr = new DataManager(dataManager);
CurrentConnectedUser = null;
Recipes = DataMgr.GetRecipes("all recipes");
RecipesInSearch = DataMgr.GetRecipes("search on");
Users = DataMgr.GetUsers();
}
#endregion
@ -132,6 +149,13 @@ namespace Model.Managers
public RecipeCollection GetCurrentUserRecipes()
=> new RecipeCollection("User recipes",
DataMgr.GetRecipes().FindAll(r => r.AuthorMail == CurrentConnectedUser?.Mail).ToArray());
/// <summary>
/// Notify property change handler.
/// </summary>
/// <param name="propertyName">the name of the property that change.</param>
public void OnPropertyChange([CallerMemberName] string propertyName = "")
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}

@ -42,7 +42,6 @@
TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"
IsVisible="{Binding IsNotConnected, Converter={toolkit:InvertedBoolConverter} ,Source={x:Reference fl}}"/>
</StackLayout>
</VerticalStackLayout>

@ -4,10 +4,12 @@
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:local="clr-namespace:Views"
xmlns:model="clr-namespace:Model;assembly=Model"
x:Class="Views.Home">
x:Class="Views.Home"
x:Name="homepage">
<local:ContainerBase
IsNotConnected="True">
IsNotConnected="{Binding IsNotConnected, Source={x:Reference homepage}}"
NeedReturn="{Binding NeedReturn, Source={x:Reference homepage}}">
<!-- Flyout -->
<local:ContainerBase.MyFlyoutContent>

@ -11,19 +11,50 @@ namespace Views
public User? user => (App.Current as App).CurrentUser;
public RecipeCollection AllRecipe => (App.Current as App).AllRecipes;
public RecipeCollection RecipesDisplayed { get; private set; }
public RecipeCollection RecipesDisplayed { get; set; }
public static readonly BindableProperty IsNotConnectedProperty =
BindableProperty.Create("IsNotConnected", typeof(bool), typeof(bool));
public bool IsNotConnected
{
get => (bool)GetValue(IsNotConnectedProperty);
set => SetValue(IsNotConnectedProperty, value);
}
public static readonly BindableProperty NeedReturnProperty =
BindableProperty.Create("NeedReturn", typeof(bool), typeof(bool));
public bool NeedReturn
{
get => (bool)GetValue(NeedReturnProperty);
set => SetValue(NeedReturnProperty, value);
}
public Home()
{
RecipesDisplayed = AllRecipe;
RecipesDisplayed = MasterMgr.DataMgr.GetRecipes("Suggestions");
InitializeComponent();
BindingContext = this;
IsNotConnected = true;
NeedReturn = false;
}
public Home(RecipeCollection recipesDisplayed)
{
RecipesDisplayed = recipesDisplayed;
InitializeComponent();
BindingContext = this;
IsNotConnected = true;
NeedReturn = true;
}
private void SearchBar_SearchButtonPressed(object sender, EventArgs e)
private async void SearchBar_SearchButtonPressed(object sender, EventArgs e)
{
RecipesDisplayed = AllRecipe.ResearchByName((sender as SearchBar).Text);
string searchStr = (sender as SearchBar).Text;
await Navigation.PushModalAsync(new Home(AllRecipe.ResearchByName(searchStr)));
}
}
}

@ -14,7 +14,7 @@
Clicked="ImageButton_Clicked"/>
<Label
Grid.Row="1" HorizontalOptions="Center"
Grid.Row="1" HorizontalOptions="Center" VerticalOptions="Center"
Text="{Binding RecipeTitle, Source={x:Reference rCase}}"/>
</Grid>
</Border>

Loading…
Cancel
Save