From 517c45f79f0ca22ab2c33a9b734d8dcd52b41c6b Mon Sep 17 00:00:00 2001 From: Szymon Uglis Date: Fri, 29 Nov 2024 21:24:01 +0100 Subject: [PATCH] Add Reloadable to tag module. Refactor reminder module --- lib/src/init.dart | 1 + lib/src/modules/reminder.dart | 9 ++------- lib/src/modules/tag.dart | 10 +++++++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/src/init.dart b/lib/src/init.dart index 65bc919..201db41 100644 --- a/lib/src/init.dart +++ b/lib/src/init.dart @@ -31,6 +31,7 @@ abstract class Reloadable { final reloadableModules = { 'EmojiReactModule': () => Injector.appInstance.get(), 'DocsModule': () => Injector.appInstance.get(), + 'TagModule': () => Injector.appInstance.get(), }; Future setupContainer(NyxxGateway client) async { diff --git a/lib/src/modules/reminder.dart b/lib/src/modules/reminder.dart index e91f2a9..080ea9a 100644 --- a/lib/src/modules/reminder.dart +++ b/lib/src/modules/reminder.dart @@ -65,19 +65,14 @@ class ReminderModule implements RequiresInitialization { @override Future init() async { reminders.addAll(await _reminderRepository.fetchReminders()); - await _processCurrent(); + + Timer.periodic(const Duration(seconds: 1), (t) => _executeScheduled()); _client.onMessageComponentInteraction .where((event) => event.interaction.data.type == MessageComponentType.button) .listen(_listenForReminderButtonEvent); } - Future _processCurrent() async { - await _executeScheduled(); - - Timer(const Duration(seconds: 1), _processCurrent); - } - Future _executeScheduled() async { final now = DateTime.now(); diff --git a/lib/src/modules/tag.dart b/lib/src/modules/tag.dart index 4608b93..bb618b8 100644 --- a/lib/src/modules/tag.dart +++ b/lib/src/modules/tag.dart @@ -6,7 +6,7 @@ import 'package:running_on_dart/src/repository/tag.dart'; import 'package:running_on_dart/src/settings.dart'; import 'package:running_on_dart/src/init.dart'; -class TagModule implements RequiresInitialization { +class TagModule implements RequiresInitialization, Reloadable { final List tags = []; final List usedEvents = []; @@ -18,6 +18,14 @@ class TagModule implements RequiresInitialization { _tagRepository.fetchTagUsage().then((events) => usedEvents.addAll(events)); } + @override + Future reload() { + tags.clear(); + usedEvents.clear(); + + return init(); + } + /// Create a new tag. Future createTag(Tag tag) async { await _tagRepository.addTag(tag);