Skip to content

Commit 1966171

Browse files
committed
fix(UpdateAllAsync): Implement simple type update with UpdateAllAsync in the most usable way to get
as string does not implement any KeyEquatable we can not use UpdateItemAsync but this way we don't have to not use Updating at all which would mean to fallback to Remove and Add the item instead
1 parent 5df6e9c commit 1966171

File tree

4 files changed

+37
-28
lines changed

4 files changed

+37
-28
lines changed

src/DevTKSS.Uno.MvuxListApp/Presentation/MainModel.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace DevTKSS.Uno.MvuxListApp.Presentation;
55
public partial record MainModel
66
{
77
private readonly ILogger _logger;
8-
private INavigator _navigator;
8+
private readonly INavigator _navigator;
99
private readonly IRouteNotifier _routeNotifier;
1010
public MainModel(
1111
IOptions<AppConfig> appInfo,
@@ -22,33 +22,33 @@ public MainModel(
2222

2323

2424
public IState<string> Title => State<string>.Value(this, () => _navigator.Route?.ToString() ?? string.Empty);
25+
private async void Main_OnRouteChanged(object? sender, RouteChangedEventArgs e)
26+
{
27+
await Title.SetAsync(e.Navigator?.Route?.ToString());
28+
}
2529

26-
private async ValueTask<IImmutableList<string>> GetMembersAsync(CancellationToken ct)
27-
=> _listMembers;
28-
30+
#region MembersView-Value
2931
private readonly IImmutableList<string> _listMembers = ImmutableList.Create(
3032
[
3133
"Hans",
3234
"Lisa",
3335
"Anke",
3436
"Tom"
3537
]);
36-
private async void Main_OnRouteChanged(object? sender, RouteChangedEventArgs e)
37-
{
38-
await Title.SetAsync(e.Navigator?.Route?.ToString());
39-
}
4038

41-
public IListState<string> DashboardList => ListState<string>.Async(this,GetMembersAsync)
42-
.Selection(SelectedMember);
39+
private async ValueTask<IImmutableList<string>> GetMembersAsync(CancellationToken ct)
40+
=> _listMembers;
4341

44-
public IState<string> SelectedMember => State<string>.Value(this,() => string.Empty);
42+
public IListState<string> Members => ListState<string>.Async(this, GetMembersAsync)
43+
.Selection(SelectedMember);
4544

45+
public IState<string> SelectedMember => State<string>.Value(this, () => string.Empty);
46+
#endregion
4647
public IState<string> ModifiedMemberName => State<string>.Empty(this);
47-
//.ForEach(RenameMemberAsync);
4848

4949
public async ValueTask RenameMemberAsync(
50-
[FeedParameter(nameof(ModifiedMemberName))]string? modName,
51-
[FeedParameter(nameof(SelectedMember))]string? replaceMember,
50+
[FeedParameter(nameof(ModifiedMemberName))] string? modName,
51+
[FeedParameter(nameof(SelectedMember))] string? replaceMember,
5252
CancellationToken ct)
5353
{
5454

@@ -57,12 +57,13 @@ public async ValueTask RenameMemberAsync(
5757
if (string.IsNullOrWhiteSpace(modName))
5858
return;
5959

60-
await DashboardList.UpdateAllAsync(
60+
await Members.UpdateAllAsync(
6161
match: item => item == replaceMember,
6262
updater: _ => modName,
6363
ct: ct
6464
);
6565

66-
await DashboardList.TrySelectAsync(modName, ct);
66+
await Members.TrySelectAsync(modName, ct);
6767
}
68+
6869
}

src/DevTKSS.Uno.MvuxListApp/Presentation/MainPage.xaml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,40 @@
77
xmlns:um="using:Uno.Material"
88
NavigationCacheMode="Required"
99
Background="{ThemeResource BackgroundBrush}">
10-
<ScrollViewer IsTabStop="True">
10+
<ScrollViewer>
11+
<!-- #region MembersView -->
1112
<Grid utu:SafeArea.Insets="VisibleBounds">
13+
1214
<Grid.RowDefinitions>
1315
<RowDefinition Height="Auto" />
1416
<RowDefinition />
1517
</Grid.RowDefinitions>
18+
1619
<utu:NavigationBar Content="{Binding Title}" />
1720

1821
<StackPanel Grid.Row="1"
1922
HorizontalAlignment="Center"
2023
VerticalAlignment="Center"
2124
Spacing="16">
2225

23-
<TextBlock Grid.Row="1"
24-
HorizontalAlignment="Center"
25-
TextAlignment="Center"
26-
Text="{Binding Path=SelectedMember,Mode=OneWay}" />
26+
<TextBlock x:Name="SelectedMemberTextBlock"
27+
HorizontalAlignment="Center"
28+
TextAlignment="Center"
29+
Text="{Binding Path=SelectedMember, Mode=OneWay}" />
30+
31+
<ListView x:Name="MembersListView"
32+
HorizontalAlignment="Center"
33+
MinWidth="200"
34+
ItemsSource="{Binding Path=Members}" />
2735

28-
<ListView HorizontalAlignment="Center" MinWidth="200" Grid.Row="2"
29-
ItemsSource="{Binding DashboardList}" />
36+
<TextBox x:Name="ModifiableMemberNameBox"
37+
PlaceholderText="Change the Name of the selected Member:"
38+
Text="{Binding Path=ModifiedMemberName, Mode=TwoWay}"/>
3039

31-
<TextBox PlaceholderText="Change the Name of the selected Member:"
32-
Text="{Binding ModifiedMemberName, Mode=TwoWay}"/>
3340
<Button Content="Change Name"
3441
Command="{Binding Path=RenameMemberAsync}" />
3542
</StackPanel>
3643
</Grid>
44+
<!-- #endregion -->
3745
</ScrollViewer>
3846
</Page>

src/DevTKSS.Uno.XamlNavigationApp-1/Presentation/DashboardModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public DashboardModel()
1717

1818
public IState<string> DashboardTitle => State<string>.Value(this, () => "Hallo vom Dashboard");
1919

20-
public IListState<string> DashboardList => ListState.Async(this, GetMembers)
21-
.Selection(SelectedMember);
20+
public IListState<string> Members => ListState.Async(this, GetMembers)
21+
.Selection(SelectedMember);
2222

2323
public IState<string> SelectedMember => State<string>.Empty(this);
2424
}

src/DevTKSS.Uno.XamlNavigationApp-1/Presentation/DashboardPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</TextBlock>
2828

2929
<ListView Grid.Row="2"
30-
ItemsSource="{Binding DashboardList}" />
30+
ItemsSource="{Binding Members}" />
3131

3232
</Grid>
3333
</Page>

0 commit comments

Comments
 (0)