Skip to content

Commit aebdc6f

Browse files
committed
fix: adjust Recipe Details into a single FeedView
1 parent fa653cf commit aebdc6f

File tree

4 files changed

+385
-387
lines changed

4 files changed

+385
-387
lines changed

Chefs/App.xaml.cs

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

44+
4445
#if DEBUG
4546
MainWindow.UseStudio();
4647
#endif
Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Runtime.InteropServices;
22
using System.Text;
33
using Chefs.Services.Sharing;
4+
using Uno.Extensions.Reactive;
45
using Windows.ApplicationModel.DataTransfer;
56
using WinRT;
67
using WinRT.Interop;
@@ -14,6 +15,7 @@ public partial record RecipeDetailsModel
1415
private readonly IUserService _userService;
1516
private readonly IMessenger _messenger;
1617
private readonly IShareService _shareService;
18+
private readonly RecipeFeedProvider _recipeFeed;
1719

1820
public RecipeDetailsModel(
1921
Recipe recipe,
@@ -30,39 +32,51 @@ public RecipeDetailsModel(
3032
_shareService = shareService;
3133

3234
Recipe = recipe;
35+
_recipeFeed = new(recipe, _recipeService, _userService);
3336
}
3437

3538
public Recipe Recipe { get; }
36-
public IState<bool> IsFavorited => State.Value(this, () => Recipe.IsFavorite);
3739

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

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

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

49-
public async ValueTask Like(Review review, CancellationToken ct) =>
50-
await _recipeService.LikeReview(review, ct);
48+
public async ValueTask LiveCooking(RecipeInfo recipeDetails)
49+
=> await _navigator.NavigateDataAsync(this, data: new LiveCookingParameter(recipeDetails.Recipe, recipeDetails.Steps));
5150

52-
public async ValueTask Dislike(Review review, CancellationToken ct) =>
53-
await _recipeService.DislikeReview(review, ct);
51+
public async ValueTask Favorite(Recipe recipe, CancellationToken ct)
52+
=> await _recipeService.Favorite(recipe, ct);
5453

55-
public async ValueTask LiveCooking(IImmutableList<Step> steps) =>
56-
await _navigator.NavigateRouteAsync(this, "LiveCooking", data: new LiveCookingParameter(Recipe, steps));
54+
public async Task Share(Recipe recipe, IImmutableList<Step> steps, CancellationToken ct)
55+
=> await _shareService.ShareRecipe(recipe, steps, ct);
5756

58-
public async ValueTask Favorite(CancellationToken ct)
57+
private class RecipeFeedProvider(Recipe recipe, IRecipeService recipeService, IUserService userService)
5958
{
60-
await _recipeService.Favorite(Recipe, ct);
61-
await IsFavorited.UpdateAsync(s => !s);
62-
}
59+
public IFeed<RecipeInfo> Feed => Uno.Extensions.Reactive.Feed.Combine(_recipe, _user, _ingredients, _steps, _reviews)
60+
.Select(ToRecipeInfo);
6361

64-
public async Task Share(CancellationToken ct)
65-
{
66-
await _shareService.ShareRecipe(Recipe, await Steps, ct);
62+
private IFeed<Recipe> _recipe => State.Value(this, () => recipe);
63+
64+
private IFeed<User> _user => _recipe.SelectAsync(async (r, ct) => await userService.GetById(r.UserId, ct));
65+
66+
private IFeed<IImmutableList<Ingredient>> _ingredients => _recipe.SelectAsync(async (r, ct) => await recipeService.GetIngredients(r.Id, ct));
67+
68+
private IFeed<IImmutableList<Step>> _steps => _recipe.SelectAsync(async (r, ct) => await recipeService.GetSteps(r.Id, ct));
69+
70+
private IFeed<IImmutableList<Review>> _reviews => _recipe.SelectAsync(async (r, ct) => await recipeService.GetReviews(r.Id, ct));
71+
72+
private RecipeInfo ToRecipeInfo((Recipe recipe, User user, IImmutableList<Ingredient> ingredients, IImmutableList<Step> steps, IImmutableList<Review> reviews) values)
73+
=> new RecipeInfo(
74+
values.recipe,
75+
values.user,
76+
values.steps,
77+
values.ingredients,
78+
values.reviews);
6779
}
80+
81+
public record RecipeInfo(Recipe Recipe, User User, IImmutableList<Step> Steps, IImmutableList<Ingredient> Ingredients, IImmutableList<Review> Reviews);
6882
}

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)