Skip to content

Commit 795b31f

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 959b0a3 commit 795b31f

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

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

Lines changed: 17 additions & 18 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,
@@ -19,36 +19,34 @@ public MainModel(
1919
_logger = logger;
2020
}
2121

22-
23-
2422
public IState<string> Title => State<string>.Value(this, () => _navigator.Route?.ToString() ?? string.Empty);
23+
private async void Main_OnRouteChanged(object? sender, RouteChangedEventArgs e)
24+
{
25+
await Title.SetAsync(e.Navigator?.Route?.ToString());
26+
}
2527

26-
private async ValueTask<IImmutableList<string>> GetMembersAsync(CancellationToken ct)
27-
=> _listMembers;
28-
28+
#region MembersView-Value
2929
private readonly IImmutableList<string> _listMembers = ImmutableList.Create(
3030
[
3131
"Hans",
3232
"Lisa",
3333
"Anke",
3434
"Tom"
3535
]);
36-
private async void Main_OnRouteChanged(object? sender, RouteChangedEventArgs e)
37-
{
38-
await Title.SetAsync(e.Navigator?.Route?.ToString());
39-
}
4036

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

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

43+
public IState<string> SelectedMember => State<string>.Value(this, () => string.Empty);
44+
#endregion
4645
public IState<string> ModifiedMemberName => State<string>.Empty(this);
47-
//.ForEach(RenameMemberAsync);
4846

4947
public async ValueTask RenameMemberAsync(
50-
[FeedParameter(nameof(ModifiedMemberName))]string? modName,
51-
[FeedParameter(nameof(SelectedMember))]string? replaceMember,
48+
[FeedParameter(nameof(ModifiedMemberName))] string? modName,
49+
[FeedParameter(nameof(SelectedMember))] string? replaceMember,
5250
CancellationToken ct)
5351
{
5452

@@ -57,12 +55,13 @@ public async ValueTask RenameMemberAsync(
5755
if (string.IsNullOrWhiteSpace(modName))
5856
return;
5957

60-
await DashboardList.UpdateAllAsync(
58+
await Members.UpdateAllAsync(
6159
match: item => item == replaceMember,
6260
updater: _ => modName,
6361
ct: ct
6462
);
6563

66-
await DashboardList.TrySelectAsync(modName, ct);
64+
await Members.TrySelectAsync(modName, ct);
6765
}
66+
6867
}

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.SimpleMemberSelectionApp/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
}

0 commit comments

Comments
 (0)