Skip to content

Commit

Permalink
Added first cut of nip46, finalized recipe editor
Browse files Browse the repository at this point in the history
  • Loading branch information
chebizarro committed Feb 26, 2025
1 parent 8374f54 commit fe91d8d
Show file tree
Hide file tree
Showing 15 changed files with 658 additions and 327 deletions.
10 changes: 9 additions & 1 deletion lib/src/data/models/nostr_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extension RecipeEvent on NostrEvent {
String get author => _getTagValue('author') ?? pubkey;
List<String> get cuisine => _getTags('cuisine');
List<String> get categories => _getTags('category');
Map<String, String> get ingredients => _getTagMap('ingredient');
Map<String, String> get ingredients => _getIngredients('ingredient');
List<String> get tools => _getTags('tool');
List<String> get images => _getTags('image');
String? get prepTime => _getTagValue('prep_time');
Expand Down Expand Up @@ -42,6 +42,14 @@ extension RecipeEvent on NostrEvent {
return tagList != null ? Map.fromEntries(tagList) : {};
}

Map<String, String> _getIngredients(String key) {
final tagList = tags?.where((t) => t[0] == key).map((l) {
return MapEntry(l[2], l[1]);
});
return tagList != null ? Map.fromEntries(tagList) : {};
}


Recipe toRecipe() {
return Recipe(
id: id!,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/data/models/recipe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Recipe {
['alt', 'recipe:$title'],
...cuisine.map((e) => ['cuisine', e]),
...categories.map((e) => ['category', e]),
...ingredients.entries.map((e) => ['ingredient', e.key, e.value]),
...ingredients.entries.map((e) => ['ingredient', e.value, e.key]),
...tools.map((e) => ['tool', e]),
...images.map((e) => ['image', e]),
['prep_time', prepTime],
Expand Down
3 changes: 3 additions & 0 deletions lib/src/data/repositories/recipe_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ class RecipeRepository {
RecipeRepository(this._nostrService);

void subscribeToRecipes() {
_subscription?.cancel();

var filter = const NostrFilter(
kinds: [35000],
);

_subscription = _nostrService.subscribeToEvents(filter).listen((event) {
_events[event.id!] = event;
_eventStreamController.add(_events.values.toList());
Expand Down
Loading

0 comments on commit fe91d8d

Please sign in to comment.