Skip to content

Commit 302639c

Browse files
committed
uno sample runs, and is almost functional, though without behaviors.
1 parent 27b8985 commit 302639c

File tree

6 files changed

+50
-36
lines changed

6 files changed

+50
-36
lines changed

samples/todoapp/TodoApp.Uno/TodoApp.Uno/App.xaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ protected async override void OnLaunched(LaunchActivatedEventArgs args)
9494
{
9595
// TODO: Register your services
9696
//services.AddSingleton<IMyService, MyService>();
97-
services.AddTransient<TodoListViewModel>();
98-
services.AddScoped<IDbInitializer, DbContextInitializer>();
9997
services.AddDbContext<AppDbContext>(options => options.UseSqlite(this.dbConnection));
98+
services.AddScoped<IDbInitializer, DbContextInitializer>();
99+
services.AddTransient<TodoListViewModel>();
100+
100101
})
101102
.UseNavigation(RegisterRoutes)
102103
);

samples/todoapp/TodoApp.Uno/TodoApp.Uno/Database/AppDbContext.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,34 @@
1313

1414
namespace TodoApp.Uno.Database;
1515

16-
public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
16+
//public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
17+
public class AppDbContext(DbContextOptions<AppDbContext> options) : OfflineDbContext(options)
1718
{
1819
public DbSet<TodoItem> TodoItems => Set<TodoItem>();
1920

20-
//protected override void OnDatasyncInitialization(DatasyncOfflineOptionsBuilder optionsBuilder)
21-
//{
22-
// HttpClientOptions clientOptions = new()
23-
// {
24-
// Endpoint = new Uri("https://localhost:44315/"),
25-
// HttpPipeline = [new LoggingHandler()]
26-
// };
27-
// _ = optionsBuilder.UseHttpClientOptions(clientOptions);
28-
//}
21+
protected override void OnDatasyncInitialization(DatasyncOfflineOptionsBuilder optionsBuilder)
22+
{
23+
HttpClientOptions clientOptions = new()
24+
{
25+
Endpoint = new Uri("https://localhost:44315/"),
26+
HttpPipeline = [new LoggingHandler()]
27+
};
28+
_ = optionsBuilder.UseHttpClientOptions(clientOptions);
29+
}
2930

3031
public async Task SynchronizeAsync(CancellationToken cancellationToken = default)
3132
{
32-
//PushResult pushResult = await this.PushAsync(cancellationToken);
33-
//if (!pushResult.IsSuccessful)
34-
//{
35-
// throw new ApplicationException($"Push failed: {pushResult.FailedRequests.FirstOrDefault().Value.ReasonPhrase}");
36-
//}
33+
PushResult pushResult = await this.PushAsync(cancellationToken);
34+
if (!pushResult.IsSuccessful)
35+
{
36+
throw new ApplicationException($"Push failed: {pushResult.FailedRequests.FirstOrDefault().Value.ReasonPhrase}");
37+
}
3738

38-
//PullResult pullResult = await this.PullAsync(cancellationToken);
39-
//if (!pullResult.IsSuccessful)
40-
//{
41-
// throw new ApplicationException($"Pull failed: {pullResult.FailedRequests.FirstOrDefault().Value.ReasonPhrase}");
42-
//}
39+
PullResult pullResult = await this.PullAsync(cancellationToken);
40+
if (!pullResult.IsSuccessful)
41+
{
42+
throw new ApplicationException($"Pull failed: {pullResult.FailedRequests.FirstOrDefault().Value.ReasonPhrase}");
43+
}
4344
}
4445
}
4546

samples/todoapp/TodoApp.Uno/TodoApp.Uno/ViewModels/TodoListViewModel.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ public async Task AddItemAsync(CancellationToken cancellationToken = default)
4040
{
4141
Id = Guid.NewGuid().ToString("N"),
4242
Title = Title,
43-
Deleted = false,
44-
IsComplete = false,
45-
UpdatedAt = DateTimeOffset.Now,
46-
Version = "1"
4743
};
4844

4945
// Add te item to the database

samples/todoapp/TodoApp.Uno/TodoApp.Uno/Views/TodoListPage.xaml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,22 @@
4242
ScrollViewer.VerticalScrollBarVisibility="Auto">
4343
<ListView.ItemTemplate>
4444
<DataTemplate>
45-
<CheckBox Margin="10"
46-
Command="{Binding ViewModel.EditItemCommand, ElementName=ThisPage}"
47-
CommandParameter="{Binding Id}"
48-
Content="{Binding Title}"
49-
IsChecked="{Binding IsComplete}" />
45+
<StackPanel Orientation="Horizontal">
46+
47+
<CheckBox Margin="10"
48+
Command="{Binding ViewModel.EditItemCommand, ElementName=ThisPage}"
49+
CommandParameter="{Binding Id}"
50+
Content="{Binding Title}"
51+
IsChecked="{Binding IsComplete}" />
52+
53+
<TextBlock Margin="10"
54+
Text="Version: " />
55+
<TextBlock Margin="10"
56+
Text="{Binding Version}" />
57+
58+
<TextBlock Margin="10"
59+
Text="{Binding UpdatedAt}" />
60+
</StackPanel>
5061
</DataTemplate>
5162
</ListView.ItemTemplate>
5263
</ListView>

samples/todoapp/TodoApp.Uno/TodoApp.Uno/Views/TodoListPage.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public TodoListPage()
3535
// on loaded override
3636
private async void TodoListPage_Loaded(object sender, RoutedEventArgs e)
3737
{
38-
if (ViewModel.LoadPageCommand.CanExecute(null))
39-
{
40-
await ViewModel.LoadPageCommand.ExecuteAsync(null);
41-
}
38+
//if (ViewModel.LoadPageCommand.CanExecute(null))
39+
//{
40+
// await ViewModel.LoadPageCommand.ExecuteAsync(null);
41+
//}
4242
}
4343

4444
private void TextBox_KeyDown(object sender, KeyRoutedEventArgs e)

samples/todoapp/TodoApp.WinUI3/Views/TodoListPage.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@
5757
IsChecked="{Binding IsComplete}" />
5858

5959
<TextBlock Margin="10"
60-
Text="{Binding Version}" />
60+
Text="Version: " />
61+
<TextBlock Margin="10"
62+
Text="{Binding Version}" />
63+
64+
<TextBlock Margin="10"
65+
Text="{Binding UpdatedAt}" />
6166
</StackPanel>
6267
</DataTemplate>
6368
</ListView.ItemTemplate>

0 commit comments

Comments
 (0)