1- using System . Runtime . InteropServices ;
2- using System . Text ;
3- using Chefs . Business . Services . Recipes ;
41using Chefs . Business . Services . Sharing ;
5- using Chefs . Business . Services . Users ;
6- using Windows . ApplicationModel . DataTransfer ;
7- using WinRT ;
8- using WinRT . Interop ;
92
103namespace 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}
0 commit comments