Skip to content

Commit

Permalink
Add Reloadable to tag module. Refactor reminder module
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha committed Nov 29, 2024
1 parent 3731c07 commit 517c45f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/src/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ abstract class Reloadable {
final reloadableModules = <String, Reloadable Function()>{
'EmojiReactModule': () => Injector.appInstance.get<EmojiReactModule>(),
'DocsModule': () => Injector.appInstance.get<DocsModule>(),
'TagModule': () => Injector.appInstance.get<TagModule>(),
};

Future<void> setupContainer(NyxxGateway client) async {
Expand Down
9 changes: 2 additions & 7 deletions lib/src/modules/reminder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,14 @@ class ReminderModule implements RequiresInitialization {
@override
Future<void> 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<void> _processCurrent() async {
await _executeScheduled();

Timer(const Duration(seconds: 1), _processCurrent);
}

Future<void> _executeScheduled() async {
final now = DateTime.now();

Expand Down
10 changes: 9 additions & 1 deletion lib/src/modules/tag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tag> tags = [];
final List<TagUsedEvent> usedEvents = [];

Expand All @@ -18,6 +18,14 @@ class TagModule implements RequiresInitialization {
_tagRepository.fetchTagUsage().then((events) => usedEvents.addAll(events));
}

@override
Future<void> reload() {
tags.clear();
usedEvents.clear();

return init();
}

/// Create a new tag.
Future<void> createTag(Tag tag) async {
await _tagRepository.addTag(tag);
Expand Down

0 comments on commit 517c45f

Please sign in to comment.