-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show popovers for each cooking term #12
Comments
Heads up, this is a long one. As I was working on this, I realized how complicated step 4 is. In How to Stock, I was able to add popovers to predefined spots on each page. But for this app, I need to inject popovers dynamically based on the recipe information we get. In other words, we need to:
To inject the popovers, I need to add a style to make the terms look hoverable and add There were 2 ways I thought of implementing this. One was to search the entire addTooltips(recipeContent: HTMLDivElement) {
// Look for each term throughout the recipe page and convert them into tooltips
const terms = this.termsService.getCachedTerms();
if (this.recipe === null || terms === null) return;
let newInnerHTML = recipeContent.innerHTML;
console.log('Original HTML:', newInnerHTML);
for (const term of terms) {
console.log(`Searching for ${term.word}...`);
// Capture all occurrences of each term, case-insensitive
const regex = new RegExp(`\\b(${term.word})\\b`, 'gi');
newInnerHTML = newInnerHTML.replace(
regex,
`<span class="term" matTooltip="${term.definition}">$1</span>`
);
}
console.log('New HTML:', newInnerHTML);
this.renderer.setProperty(recipeContent, 'innerHTML', newInnerHTML);
} However, there were several issues with this approach. First, this had the potential to inject popovers outside the visible text content. For example, if one of the ingredients had an image called The other option I came up with was to look at one word at a time and use ![]() I'm glad this works, but I'm worried about how this will translate to the mobile apps. I know at least for SwiftUI that there is a limit to the number of children a view can have, so I can't just add a bunch of To compensate, I can make a separate page to show all the terms like a dictionary. That should be very simple to implement and I have space to add a tab to the app. Plus, I can continue to cache the terms as described above and implement the terms API on mobile so there's no waste in effort. I also feel like fetching the terms API on startup will help with improving the cold start times during tests so the server can be active before fetching the recipes. |
Similar to How to Stock, terms will be saved to
localStorage/UserDefaults/DataStore
(can move toIndexedDB/Core Data/Room
with recent recipes if needed) and expire after 1 week to prevent data from being stale.Steps to be done:
a. If they are, check if they're expired.
b. If they are, remove the terms.
The text was updated successfully, but these errors were encountered: