Skip to content

Commit

Permalink
feat: update sort + habit last time
Browse files Browse the repository at this point in the history
  • Loading branch information
Quedow committed Nov 3, 2024
1 parent a931f0e commit e5c42f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
22 changes: 12 additions & 10 deletions lib/database/database_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,24 @@ class DatabaseService {
});
}

Future<List<Task>> getTasks([bool? isDone]) async {
return await isar.tasks.where().anyDueDateTime().filter().optional(
isDone != null,
(task) => task.isDoneEqualTo(isDone!),
).findAll();
Future<List<Task>> getTasks(bool isDone) async {
var query = isar.tasks.where().anyDueDateTime().filter().isDoneEqualTo(isDone);

return !isDone
? await query.findAll()
: await query.sortByDueDateTimeDesc().findAll();
}

Future<List<Habit>> getHabits() async {
return await isar.habits.where().findAll();
}

Future<List<Routine>> getRoutines([bool? isDone]) async {
return await isar.routines.where().anyDueDateTime().filter().optional(
isDone != null,
(routine) => routine.isDoneEqualTo(isDone!),
).findAll();
Future<List<Routine>> getRoutines(bool isDone) async {
var query = isar.routines.where().anyDueDateTime().filter().isDoneEqualTo(isDone);

return !isDone
? await query.findAll()
: await query.sortByDueDateTimeDesc().findAll();
}

Future<List<int>> getDoneRates() async {
Expand Down
6 changes: 4 additions & 2 deletions lib/provider/quest_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ class QuestProvider with ChangeNotifier {
}

Future<void> incrementHabitCounter(Habit habit, int increment) async {
DateTime now = DateTime.now();
habit.counter += increment;
habit.lastDateTime = now;
if (increment > 0) {
DateTime now = DateTime.now();
habit.lastDateTime = now;
}
await _db.insertOrUpdateHabit(habit);
notifyListeners();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:jiffy/jiffy.dart';

abstract class Functions {
static String getDate(DateTime date) {
return DateFormat('MM/dd/yyyy').format(date);
return DateFormat('dd/MM/yyyy').format(date);
}

static String getTime(DateTime date) {
Expand Down

0 comments on commit e5c42f6

Please sign in to comment.