Skip to content

Commit b600526

Browse files
committed
fix: adjust Recipe Details into a single FeedView
1 parent 572a0e2 commit b600526

File tree

5 files changed

+389
-401
lines changed

5 files changed

+389
-401
lines changed

Chefs/App.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args)
3838
ConfigureAppBuilder(builder);
3939
MainWindow = builder.Window;
4040

41+
4142
#if DEBUG
4243
MainWindow.UseStudio();
4344
#endif

Chefs/Business/Models/Nutrition.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ public partial record Nutrition
55
{
66
internal Nutrition(NutritionData? nutritionData)
77
{
8-
Protein = nutritionData?.Protein;
9-
Carbs = nutritionData?.Carbs;
10-
Fat = nutritionData?.Fat;
11-
ProteinBase = nutritionData?.ProteinBase;
12-
CarbsBase = nutritionData?.CarbsBase;
13-
FatBase = nutritionData?.FatBase;
8+
Protein = 30;
9+
Carbs = 101;
10+
Fat = 30;
11+
ProteinBase = 110;
12+
CarbsBase = 300;
13+
FatBase = 75;
1414
}
1515

1616
public double? Protein { get; }
Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
using System.Runtime.InteropServices;
2-
using System.Text;
3-
using Chefs.Business.Services.Recipes;
41
using Chefs.Business.Services.Sharing;
5-
using Chefs.Business.Services.Users;
6-
using Windows.ApplicationModel.DataTransfer;
7-
using WinRT;
8-
using WinRT.Interop;
92

103
namespace Chefs.Presentation;
114

@@ -14,57 +7,68 @@ public partial record RecipeDetailsModel
147
private readonly INavigator _navigator;
158
private readonly IRecipeService _recipeService;
169
private readonly IUserService _userService;
17-
private readonly IMessenger _messenger;
1810
private readonly IShareService _shareService;
11+
private readonly RecipeFeedProvider _recipeFeed;
1912

2013
public RecipeDetailsModel(
2114
Recipe recipe,
2215
INavigator navigator,
2316
IRecipeService recipeService,
2417
IUserService userService,
25-
IMessenger messenger,
2618
IShareService shareService)
2719
{
2820
_navigator = navigator;
2921
_recipeService = recipeService;
3022
_userService = userService;
31-
_messenger = messenger;
3223
_shareService = shareService;
3324

3425
Recipe = recipe;
26+
_recipeFeed = new RecipeFeedProvider(recipe, _recipeService, _userService);
3527
}
3628

3729
public Recipe Recipe { get; }
38-
public IState<bool> IsFavorited => State.Value(this, () => Recipe.IsFavorite);
3930

40-
public IState<User> User => State.Async(this, async ct => await _userService.GetById(Recipe.UserId, ct))
41-
.Observe(_messenger, u => u.Id);
31+
public IFeed<RecipeInfo> RecipeDetails => _recipeFeed.Feed;
4232

43-
public IFeed<User> CurrentUser => Feed.Async(_userService.GetCurrent);
44-
public IListFeed<Ingredient> Ingredients => ListFeed.Async(async ct => await _recipeService.GetIngredients(Recipe.Id, ct));
45-
public IListFeed<Step> Steps => ListFeed.Async(async ct => await _recipeService.GetSteps(Recipe.Id, ct));
33+
public async ValueTask Like(Review review, CancellationToken ct)
34+
=> await _recipeService.LikeReview(review, ct);
4635

47-
public IListState<Review> Reviews => ListState
48-
.Async(this, async ct => await _recipeService.GetReviews(Recipe.Id, ct))
49-
.Observe(_messenger, r => r.Id);
36+
public async ValueTask Dislike(Review review, CancellationToken ct)
37+
=> await _recipeService.DislikeReview(review, ct);
5038

51-
public async ValueTask Like(Review review, CancellationToken ct) =>
52-
await _recipeService.LikeReview(review, ct);
39+
public async ValueTask LiveCooking(RecipeInfo recipeDetails)
40+
=> await _navigator.NavigateDataAsync(this, data: new LiveCookingParameter(recipeDetails.Recipe, recipeDetails.Steps));
5341

54-
public async ValueTask Dislike(Review review, CancellationToken ct) =>
55-
await _recipeService.DislikeReview(review, ct);
42+
public async ValueTask Favorite(RecipeInfo recipeDetails, CancellationToken ct)
43+
=> await _recipeService.Favorite(recipeDetails.Recipe, ct);
5644

57-
public async ValueTask LiveCooking(IImmutableList<Step> steps) =>
58-
await _navigator.NavigateRouteAsync(this, "LiveCooking", data: new LiveCookingParameter(Recipe, steps));
45+
public async Task Share(RecipeInfo recipeDetails, CancellationToken ct)
46+
=> await _shareService.ShareRecipe(recipeDetails.Recipe, recipeDetails.Steps, ct);
5947

60-
public async ValueTask Favorite(CancellationToken ct)
48+
private class RecipeFeedProvider(Recipe recipe, IRecipeService recipeService, IUserService userService)
6149
{
62-
await _recipeService.Favorite(Recipe, ct);
63-
await IsFavorited.UpdateAsync(s => !s);
64-
}
50+
public IFeed<RecipeInfo> Feed => Uno.Extensions.Reactive.Feed
51+
.Combine(Recipe, User, Ingredients, Steps, Reviews)
52+
.Select(ToRecipeInfo);
6553

66-
public async Task Share(CancellationToken ct)
67-
{
68-
await _shareService.ShareRecipe(Recipe, await Steps, ct);
54+
private IFeed<Recipe> Recipe => State.Value(this, () => recipe);
55+
56+
private IFeed<User> User => Recipe.SelectAsync(async (r, ct) => await userService.GetById(r.UserId, ct));
57+
58+
private IFeed<IImmutableList<Ingredient>> Ingredients => Recipe.SelectAsync(async (r, ct) => await recipeService.GetIngredients(r.Id, ct));
59+
60+
private IFeed<IImmutableList<Step>> Steps => Recipe.SelectAsync(async (r, ct) => await recipeService.GetSteps(r.Id, ct));
61+
62+
private IFeed<IImmutableList<Review>> Reviews => Recipe.SelectAsync(async (r, ct) => await recipeService.GetReviews(r.Id, ct));
63+
64+
private RecipeInfo ToRecipeInfo((Recipe recipe, User user, IImmutableList<Ingredient> ingredients, IImmutableList<Step> steps, IImmutableList<Review> reviews) values)
65+
=> new RecipeInfo(
66+
values.recipe,
67+
values.user,
68+
values.steps,
69+
values.ingredients,
70+
values.reviews);
6971
}
72+
73+
public record RecipeInfo(Recipe Recipe, User User, IImmutableList<Step> Steps, IImmutableList<Ingredient> Ingredients, IImmutableList<Review> Reviews);
7074
}

Chefs/Styles/FeedView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,4 @@
351351
</Setter.Value>
352352
</Setter>
353353
</Style>
354-
</ResourceDictionary>
354+
</ResourceDictionary>

0 commit comments

Comments
 (0)