SmartBlocks
SmartBlocks copied to clipboard
Display a Random Joke
✂️ Copy of your #42SmartBlock from Roam
- Random Joke #42SmartBlock
-
<%JA: ```javascript let currentBlockUID = roam42.common.currentActiveBlockUID(); let joke = await fetch('https://official-joke-api.appspot.com/random_joke').then(res=>res.json());
roam42.common.createBlock(currentBlockUID, -1, joke.punchline + " 😆"); roam42.common.updateBlock(currentBlockUID, document.activeElement.value, false); return joke.setup + " 🤔";``` %>
-
📋 Describe the SmartBlock
This smartblock will display a random joke .
✅ Describe any prerequisites or dependencies that are required for this SmartBlock
No other requirements.
📷 Screenshot of your #42SmartBlock workflow/template from Roam
💡 Additional Info
Gets the jokes from https://github.com/15Dkatz/official_joke_api
https://www.loom.com/share/de7927d5d27f4069bed885e8bd5dff9e
Hi, it lacks the single quote ' ' around the url, in the code to copy/past. Anyway, good call to this api ! For a bit more excitement, I propose to close the child block, here is my suggestion:
<%JA: ```javascript
let currentBlockUID = roam42.common.currentActiveBlockUID();
let joke = await fetch('https://official-joke-api.appspot.com/random_joke').then(res=>res.json());
roam42.common.createBlock(currentBlockUID, -1, joke.punchline + " 😆");
roam42.common.updateBlock(currentBlockUID, document.activeElement.value, false);
return joke.setup + " 🤔";``` %>
Thanks @fbgallet . Updated.