-
Notifications
You must be signed in to change notification settings - Fork 2
Some additional code cleanup #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thanks for merging my last PR! This one doesn't have any bug fixes in it per se, so it's of course up to you whether you want to merge it in or not (or cherry pick some of the changes that you want in). |
Cleanup and fixes are appreciated and encouraged! Thanks for spending the time to help! |
{ | ||
todo.Completed = e.Value; | ||
todo.CompletedAt = DateTime.UtcNow.ToString("o"); | ||
todo.CompletedAt = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is likely the only issue I have. Since we use the ISO format across our demos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, maybe - but then it seems like you'd have to do something like this:
public async Task SaveItemAsync(TodoItem item)
{
if (item.ID != "")
{
await Db.Execute(
@"UPDATE todos
SET description = ?,
completed = ?,
completed_at = CASE
WHEN ? = 1 AND ? IS NULL THEN datetime()
ELSE NULL
END,
completed_by = ?
WHERE id = ?",
[
item.Description,
item.Completed ? 1 : 0,
item.Completed ? 1 : 0,
item.CompletedAt,
item.Completed ? UserId : null,
item.ID
]);
}
else
{
await Db.Execute(
@"INSERT INTO todos
(id, list_id, description, created_at, created_by, completed, completed_at, completed_by)
VALUES (uuid(), ?, ?, datetime(), ?, ?,
CASE
WHEN ? = 1 AND ? IS NULL THEN datetime()
ELSE NULL
END, ?)",
[
item.ListId,
item.Description,
UserId,
item.Completed ? 1 : 0,
item.Completed ? 1 : 0,
item.CompletedAt,
item.Completed ? UserId : null
]);
}
}
because you only want to set CompletedAt if the item is newly marked as Completed; and to my mind that's too much business logic in the database class.
FYI I changed that date formatting in the code-behind to make it consistent with the format that datetime() is writing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative would be to add a dedicated method that has sql intended only for marking as complete I guess (which would also use datetime()).
Additional code cleanup
NodeConnector.cs
PowerSyncData.cs
completed_by
if item is marked as incomplete.completed_by
on INSERT for consistency's sake.TodoItem.cs
ListsPage.xaml.cs and TodoListPage.xaml.cs