Skip to content

Commit 0a86c0a

Browse files
committed
Merge branch 'maui' of https://github.com/powersync-ja/powersync-dotnet into maui
2 parents 924e8fe + df00aea commit 0a86c0a

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

demos/TodoSQLite/Data/NodeConnector.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ namespace TodoSQLite.Data;
1313

1414
public class NodeConnector : IPowerSyncBackendConnector
1515
{
16-
private readonly HttpClient httpClient;
16+
private static readonly string StorageFilePath = "user_id.txt"; // Simulating local storage
17+
private readonly HttpClient _httpClient;
1718

1819
public string BackendUrl { get; }
1920
public string PowerSyncUrl { get; }
20-
public string UserId { get; }
21+
public string UserId { get; private set; }
2122
private string? clientId;
2223

2324
public NodeConnector()
2425
{
25-
httpClient = new HttpClient();
26+
_httpClient = new HttpClient();
2627

2728
// Load or generate User ID
2829
UserId = LoadOrGenerateUserId();
@@ -35,15 +36,22 @@ public NodeConnector()
3536

3637
public string LoadOrGenerateUserId()
3738
{
38-
return "8ba3ec38-6cc8-449c-88c0-9275987ea5d2";
39+
if (File.Exists(StorageFilePath))
40+
{
41+
return File.ReadAllText(StorageFilePath);
42+
}
43+
44+
string newUserId = Guid.NewGuid().ToString();
45+
File.WriteAllText(StorageFilePath, newUserId);
46+
return newUserId;
3947
}
4048

4149
public async Task<PowerSyncCredentials?> FetchCredentials()
4250
{
43-
var tokenEndpoint = "api/auth/token";
44-
var url = $"{BackendUrl}/{tokenEndpoint}?user_id={UserId}";
51+
string tokenEndpoint = "api/auth/token";
52+
string url = $"{BackendUrl}/{tokenEndpoint}?user_id={UserId}";
4553

46-
var response = await httpClient.GetAsync(url);
54+
HttpResponseMessage response = await _httpClient.GetAsync(url);
4755
if (!response.IsSuccessStatusCode)
4856
{
4957
throw new Exception($"Received {response.StatusCode} from {tokenEndpoint}: {await response.Content.ReadAsStringAsync()}");
@@ -98,7 +106,7 @@ public async Task UploadData(IPowerSyncDatabase database)
98106
var payload = JsonSerializer.Serialize(new { batch });
99107
var content = new StringContent(payload, Encoding.UTF8, "application/json");
100108

101-
HttpResponseMessage response = await httpClient.PostAsync($"{BackendUrl}/api/data", content);
109+
HttpResponseMessage response = await _httpClient.PostAsync($"{BackendUrl}/api/data", content);
102110

103111
if (!response.IsSuccessStatusCode)
104112
{

demos/TodoSQLite/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# .NET MAUI ToDo List Demo App
2+
3+
## To test (we currently recommend testing on iOS):
4+
1. You need to have one of our Node.js self-host demos ([Postgres](https://github.com/powersync-ja/self-host-demo/tree/main/demos/nodejs) | [MongoDB](https://github.com/powersync-ja/self-host-demo/tree/main/demos/nodejs-mongodb) | [MySQL](https://github.com/powersync-ja/self-host-demo/tree/main/demos/nodejs-mysql)) running, as it provides the PowerSync server that this demo's SDK connects to.
5+
2. In the root directly run:
6+
1. `dotnet run --project Tools/Setup`
7+
2. `dotnet restore`
8+
3. cd into this directory: `* cd demos/TodoSQLite `
9+
4. run `dotnet build -t:Run -f:net8.0-ios`
10+
1. Or specify an iOS simulator identifier e.g.: `dotnet build -t:Run -f:net8.0-ios -p:_DeviceName=:v2:udid=B1CA156A-56FC-4C3C-B35D-4BC349111FDF`
11+
5. Changes made to the backend's source DB (inspect via a tool like `psql`) or to the self-hosted aapp's web UI will be synced to this iOS client (and vice versa)
12+
13+
## Current known issues:
14+
* Switching from offline to online mode isn't yet handled
15+
* Android has some instability
16+

demos/TodoSQLite/Views/TodoListPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected override async void OnAppearing()
2323
{
2424
base.OnAppearing();
2525

26-
await database.Db.Watch("select * from todos", null, new WatchHandler<TodoItem>
26+
await database.Db.Watch("select * from todos where list_id = ?", [selectedList.ID], new WatchHandler<TodoItem>
2727
{
2828
OnResult = (results) =>
2929
{

0 commit comments

Comments
 (0)