add vote system to recipe page

pull/26/head
maxime.BATISTA@etu.uca.fr 2 years ago
parent 03d02a606b
commit d1c96f65d5

Before

Width:  |  Height:  |  Size: 900 B

After

Width:  |  Height:  |  Size: 900 B

Before

Width:  |  Height:  |  Size: 972 B

After

Width:  |  Height:  |  Size: 972 B

@ -0,0 +1,3 @@
<svg width="100" height="100" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M51.5995 80.3367L50 79.3286L48.4005 80.3367L22.2873 96.7941L22.2659 96.8076L22.2446 96.8215C21.9992 96.9821 21.8349 97.0077 21.6743 96.9984C21.3995 96.9824 21.2189 96.9085 21.0502 96.7824C20.8413 96.6262 20.6768 96.4268 20.5477 96.1179C20.486 95.9704 20.4227 95.7098 20.5093 95.2285L27.3779 64.1254L27.7519 62.4318L26.4707 61.2626L3.45013 40.2535C3.44969 40.2531 3.44925 40.2527 3.44882 40.2523C3.09118 39.9244 3.05657 39.7374 3.0485 39.6896C2.97181 39.2347 2.98924 38.8339 3.07836 38.4608C3.1053 38.348 3.15083 38.2442 3.32949 38.0972C3.4795 37.9739 3.69984 37.8554 4.10721 37.8104L34.5497 35.0206L36.3769 34.8532L37.0602 33.1504L48.8398 3.79549C48.9872 3.45789 49.1405 3.3261 49.2757 3.24647C49.6382 3.03307 49.8673 3 50 3C50.1327 3 50.3618 3.03307 50.7243 3.24647C50.8595 3.32611 51.0128 3.45791 51.1602 3.79559L62.9398 33.1504L63.6231 34.8532L65.4502 35.0206L95.8928 37.8104C96.3002 37.8554 96.5205 37.9739 96.6705 38.0972C96.8492 38.2442 96.8947 38.348 96.9216 38.4608C97.0108 38.8339 97.0282 39.2347 96.9515 39.6896C96.9434 39.7375 96.9088 39.9248 96.5502 40.2533C96.5501 40.2533 96.55 40.2534 96.5499 40.2535L73.5293 61.2626L72.2481 62.4318L72.6221 64.1254L79.4907 95.2285C79.5774 95.7098 79.514 95.9704 79.4523 96.1179C79.3232 96.4268 79.1587 96.6262 78.9498 96.7824C78.7811 96.9085 78.6005 96.9824 78.3257 96.9984C78.1651 97.0077 78.0008 96.9821 77.7554 96.8215L77.7341 96.8076L77.7127 96.7941L51.5995 80.3367Z" stroke="#FFD600" stroke-width="6"/>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

@ -0,0 +1,3 @@
<svg width="100" height="100" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M50 82.8747L23.8869 99.3321C23.1381 99.8219 22.3426 100.042 21.5002 99.9933C20.6578 99.9443 19.9091 99.6749 19.2539 99.1851C18.5987 98.6953 18.1074 98.0586 17.7798 97.2749C17.4522 96.4912 17.382 95.6096 17.5692 94.63L24.4485 63.4785L1.42399 42.4659C0.675224 41.7802 0.230646 41.021 0.0902527 40.1883C-0.0501404 39.3557 -0.0267415 38.5475 0.160449 37.7638C0.34764 36.9801 0.768819 36.3189 1.42399 35.7801C2.07916 35.2413 2.87472 34.923 3.81067 34.825L34.276 32.0331L46.069 2.64494C46.4434 1.76329 47.0049 1.10206 47.7537 0.661234C48.5025 0.220411 49.2512 0 50 0C50.7488 0 51.4975 0.220411 52.2463 0.661234C52.9951 1.10206 53.5566 1.76329 53.931 2.64494L65.724 32.0331L96.1893 34.825C97.1253 34.923 97.9209 35.2413 98.576 35.7801C99.2312 36.3189 99.6524 36.9801 99.8396 37.7638C100.027 38.5475 100.05 39.3557 99.9098 40.1883C99.7694 41.021 99.3248 41.7802 98.576 42.4659L75.5516 63.4785L82.4308 94.63C82.618 95.6096 82.5478 96.4912 82.2202 97.2749C81.8926 98.0586 81.4013 98.6953 80.7461 99.1851C80.0909 99.6749 79.3422 99.9443 78.4998 99.9933C77.6574 100.042 76.8619 99.8219 76.1131 99.3321L50 82.8747Z" fill="#FFD600"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

@ -50,14 +50,16 @@
<ItemGroup> <ItemGroup>
<None Remove="Resources\Fonts\Poppins-Bold.ttf" /> <None Remove="Resources\Fonts\Poppins-Bold.ttf" />
<None Remove="Resources\Fonts\Poppins-Medium.ttf" /> <None Remove="Resources\Fonts\Poppins-Medium.ttf" />
<None Remove="Resources\Images\earth_off.svg" />
<None Remove="Resources\Images\earth_on.svg" />
<None Remove="Resources\Images\email_icon.svg" /> <None Remove="Resources\Images\email_icon.svg" />
<None Remove="Resources\Images\facebook_logo.svg" /> <None Remove="Resources\Images\facebook_logo.svg" />
<None Remove="Resources\Images\hearth_off.svg" />
<None Remove="Resources\Images\hearth_on.svg" />
<None Remove="Resources\Images\minus.svg" /> <None Remove="Resources\Images\minus.svg" />
<None Remove="Resources\Images\password_icon.svg" /> <None Remove="Resources\Images\password_icon.svg" />
<None Remove="Resources\Images\plus.svg" /> <None Remove="Resources\Images\plus.svg" />
<None Remove="Resources\Images\search_options.svg" /> <None Remove="Resources\Images\search_options.svg" />
<None Remove="Resources\Images\star_empty.svg" />
<None Remove="Resources\Images\star_full.svg" />
<None Remove="Resources\Images\user.svg" /> <None Remove="Resources\Images\user.svg" />
<None Remove="Resources\Images\visibility_off.svg" /> <None Remove="Resources\Images\visibility_off.svg" />
<None Remove="Resources\Images\visibility_on.svg" /> <None Remove="Resources\Images\visibility_on.svg" />

@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ShoopNCook.Views.RecipePage" x:Class="ShoopNCook.Views.RecipePage"
Title="RecipePage" Title="RecipePage"
x:Name="RecipeViewPage"
BackgroundColor="{StaticResource BackgroundPrimary}"> BackgroundColor="{StaticResource BackgroundPrimary}">
<Grid <Grid
@ -13,7 +14,7 @@
<!--Main content--> <!--Main content-->
<ScrollView> <ScrollView>
<Grid <Grid
RowDefinitions="*, Auto, 10*"> RowDefinitions="*, Auto, Auto, 0.5*">
<FlexLayout <FlexLayout
Grid.Row="0" Grid.Row="0"
Direction="Row" Direction="Row"
@ -30,7 +31,7 @@
<ImageButton <ImageButton
x:Name="Favorite" x:Name="Favorite"
Source="earth_off.svg" Source="hearth_off.svg"
Margin="0, 0, 5, 0" Margin="0, 0, 5, 0"
Clicked="OnFavorite"/> Clicked="OnFavorite"/>
</FlexLayout> </FlexLayout>
@ -99,6 +100,51 @@
x:Name="StepList"/> x:Name="StepList"/>
</VerticalStackLayout> </VerticalStackLayout>
<!--Stars-->
<HorizontalStackLayout
Grid.Row="3">
<HorizontalStackLayout
x:Name="Stars"
Spacing="2"
Margin="10, 0, 0, 0">
<ImageButton
WidthRequest="30"
Command="{Binding StarCommand, Source={x:Reference RecipeViewPage}}"
CommandParameter="1"/>
<ImageButton
WidthRequest="30"
Command="{Binding StarCommand, Source={x:Reference RecipeViewPage}}"
CommandParameter="2"/>
<ImageButton
WidthRequest="30"
Command="{Binding StarCommand, Source={x:Reference RecipeViewPage}}"
CommandParameter="3"/>
<ImageButton
WidthRequest="30"
Command="{Binding StarCommand, Source={x:Reference RecipeViewPage}}"
CommandParameter="4"/>
<ImageButton
WidthRequest="30"
Command="{Binding StarCommand, Source={x:Reference RecipeViewPage}}"
CommandParameter="5"/>
</HorizontalStackLayout>
<Border
Margin="12, 0, 0, 0"
Stroke="Transparent"
StrokeShape="RoundRectangle 150">
<Button
FontFamily="PoppinsMedium"
TextColor="White"
BackgroundColor="{StaticResource Selected}"
VerticalOptions="Center"
HorizontalOptions="Center"
Text="Submit"/>
</Border>
</HorizontalStackLayout>
</Grid> </Grid>
</ScrollView> </ScrollView>
@ -149,7 +195,7 @@
StrokeShape="RoundRectangle 100" StrokeShape="RoundRectangle 100"
BackgroundColor="{StaticResource Selected}"> BackgroundColor="{StaticResource Selected}">
<ImageButton <ImageButton
Source="add.svg" Source="plus.svg"
WidthRequest="40" WidthRequest="40"
HeightRequest="40" HeightRequest="40"
Clicked="OnPlus"/> Clicked="OnPlus"/>

@ -1,16 +1,23 @@
using Microsoft.Maui.Controls; using Microsoft.Maui.Controls;
using System.Windows.Input;
namespace ShoopNCook.Views; namespace ShoopNCook.Views;
public partial class RecipePage : ContentPage public partial class RecipePage : ContentPage
{ {
private uint note;
private uint nbPers; private uint nbPers;
private bool isFavorite; private bool isFavorite;
public ICommand StarCommand => new Command<string>(count =>
{
SetNote(uint.Parse(count));
});
public RecipePage() : public RecipePage() :
this("Recipe Sample", 32, 250, this("Recipe Sample", 32, 250,
true, 1, true, 2, 0,
new List<IngredientView> { new List<IngredientView> {
new IngredientView("Chocolate", 25, "g"), new IngredientView("Chocolate", 25, "g"),
new IngredientView("Flour", 250, "g"), new IngredientView("Flour", 250, "g"),
@ -26,13 +33,15 @@ public partial class RecipePage : ContentPage
uint energy, uint energy,
bool isFavorite, bool isFavorite,
uint nbPers, uint nbPers,
uint note,
List<IngredientView> ingredients, List<IngredientView> ingredients,
List<string> steps List<string> steps
) )
{ {
InitializeComponent(); InitializeComponent();
this.nbPers = nbPers; SetNbPers(nbPers);
this.isFavorite = isFavorite; SetFavorite(isFavorite);
SetNote(note);
CookTime.Text = cookTime.ToString(); CookTime.Text = cookTime.ToString();
Energy.Text = energy.ToString(); Energy.Text = energy.ToString();
@ -52,36 +61,55 @@ public partial class RecipePage : ContentPage
} }
} }
private void SetNote(uint note)
{
this.note = note;
int i = 1;
foreach (ImageButton img in Stars.Children)
{
if (i <= note)
{
img.Source = ImageSource.FromFile("star_full.svg");
i++;
}
else
{
img.Source = ImageSource.FromFile("star_empty.svg");
}
}
}
private void OnFavorite(object o, EventArgs e) private void OnFavorite(object o, EventArgs e)
{ {
isFavorite = !isFavorite; SetFavorite(!isFavorite);
if (isFavorite) }
private void SetFavorite(bool isFavorite)
{
this.isFavorite = isFavorite;
if (isFavorite)
{ {
Favorite.Source = ImageSource.FromFile("earth_on.svg"); Favorite.Source = ImageSource.FromFile("hearth_on.svg");
} }
else else
{ {
Favorite.Source = ImageSource.FromFile("earth_off.svg"); Favorite.Source = ImageSource.FromFile("hearth_off.svg");
} }
} }
private void OnPlus(object o, EventArgs e) private void OnPlus(object o, EventArgs e)
{ {
UpdateCounter(++nbPers); SetNbPers(nbPers + 1);
} }
private void OnMinus(object o, EventArgs e) private void OnMinus(object o, EventArgs e)
{ {
if (nbPers <= 1) SetNbPers(nbPers - 1);
return;
nbPers--;
UpdateCounter(nbPers);
} }
private void UpdateCounter(uint counter) private void SetNbPers(uint nbPers)
{ {
NbPersLabel.Text = counter.ToString(); this.nbPers = nbPers <= 1 ? 1 : nbPers;
NbPersLabel.Text = this.nbPers.ToString();
} }
} }
Loading…
Cancel
Save