Add Dashboard widget
Hello ! First of all, I want to thank you all for this amazing app which have had a lot of improvements recently.
I’ve just had an idea I want to share with you : did you already think about a dashboard widget for this app ? I’ve thought about something like "Recipe of the day" which would randomly propose one recipe each day.
Any opinion about this ?
Of course, it’s not an urgent feature.
Thank you again, it’s one of my favorite apps here !!
Great idea, I would add the following:
I like my recipes being seasonal. Maybe add a field with te best period (eg. June to October) for the recipe and have the widget propose 1 at random from that season.
I can open a new issue if you prefer having this separate.
We should differentiate between data that is important and a core part for the recipe and data that is only handling displaying the recipe (here for a widget).
E.g., a season for a recipe is best suited to be a keyword and fits well with the already existing structure. At which time a recipe containing a certain keyword is shown in a dashboard widget should not be part of the recipe data model but rather a setting of the dashboard widget.
I think it’s okay to use this issue to collect some ideas of what a Cookbook dashboard widget could look like.
I know this is older, but it's something I'm interesting it.
From my perspective, I would believe the widget should be random recipes, since "recent", "most used", etc isn't tracked. I also don't believe favorites make sense because from my understanding, widgets can't scroll.
I think it would be best used to serve random recipes at a glance so you can look at it and see if you would like to cook any of the "recommendations" at a glance.
I really just picture it with recipe image, name, and total time.
This could be expanded upon where breakfast, lunch, and dinner(Main Course) categories are dynamically "recommended" based on time of day.
I do not have PHP background, so what I have may require heavy criticism because I am heavily relying on Claude for this......
Here is the Widget as I am currently working on it (it is currently "snack time"):
It implements time-based recipe recommendations in the following way:
private function bucketForHour(int $h): string {
if ($h >= 5 && $h < 11) return 'breakfast';
if ($h >= 11 && $h < 15) return 'lunch';
if ($h >= 15 && $h < 17) return 'snack';
if ($h >= 17 && $h < 22) return 'dinner';
return 'snack';
}
It uses both categories and labels, normalizes them, then uses them to determine what to recommend. The list is cached for 5 minutes:
public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems {
try {
$preferred = $this->getPreferredTagsForBucket($bucket);
$filtered = array_values(array_filter($recipes, function (array $r) use ($preferred) {
//Check both categories and keywords
$categoriesNorm = $this->normTags($r['categories'] ?? []);
$keywordsNorm = $this->normTags($r['keywords'] ?? []);
$allTags = array_merge($categoriesNorm, $keywordsNorm);
return count(array_intersect($allTags, $preferred)) > 0;
}));
//////////////
private function normTags(array $tags): array {
$out = [];
foreach ($tags as $t) {
$n = $this->norm((string)$t);
if ($n !== '') { $out[$n] = true; }
}
return array_keys($out);
}
//////////////
private function getPreferredTagsForBucket(string $bucket): array {
// Search terms for translation
$translations = [
'breakfast' => [
$this->l10n->t('breakfast'),
$this->l10n->t('brunch'),
$this->l10n->t('egg'),
$this->l10n->t('eggs'),
$this->l10n->t('morning'),
$this->l10n->t('oatmeal'),
$this->l10n->t('pancake'),
$this->l10n->t('toast'),
$this->l10n->t('cereal'),
// English fallbacks
'breakfast', 'brunch', 'egg', 'eggs', 'morning', 'oatmeal', 'pancake', 'toast', 'cereal',
],
Main challenge right now: What is the best way to query the database. It currently fetches recipes sequentially and I worry what the time to load would be with say 100+ recipes. I do know for SQL you can use ORDER BY RANDOM() so that is probably the way since it will offload randomness to the database rather than pull then sort via the dashboard.