SmartBlocks icon indicating copy to clipboard operation
SmartBlocks copied to clipboard

Display a Random Joke

Open jozzua opened this issue 3 years ago • 2 comments

✂️ 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

image

💡 Additional Info

Gets the jokes from https://github.com/15Dkatz/official_joke_api

https://www.loom.com/share/de7927d5d27f4069bed885e8bd5dff9e

jozzua avatar Apr 10 '21 04:04 jozzua

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 + " 🤔";``` %>

fbgallet avatar Apr 10 '21 15:04 fbgallet

Thanks @fbgallet . Updated.

jozzua avatar Apr 18 '21 02:04 jozzua