this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

disable button when not logged in

authored by

phil and committed by
Bailey Townsend
44d333fb a167ddc3

+14 -4
+14 -4
shared/challenges_markdown/three/part_one.md
··· 2 2 We can create a new web handler like. /day/3/{did} and it downloads the car file. 3 3 Inside the car export is just one record with the verficiation code 4 4 5 - TODO: detect not-logged-in and if not, don't render this button: 6 - 7 - <a id="download-car" href="#" class="btn btn-primary">Download your CAR file</a> 5 + <a id="download-car" href="" class="btn btn-primary btn-disabled">Loading (JS required) &hellip;</a> 8 6 9 7 <script> 8 + (function() { 9 + const button = document.getElementById('download-car'); 10 10 const carData = atob("{{car_base64}}"); 11 + 12 + if (carData.length === 0) { 13 + button.textContent = 'Log in to download'; 14 + return; 15 + } 16 + 17 + button.classList.remove('btn-disabled'); 18 + button.textContent = 'Download your CAR file'; 19 + 11 20 const bytes = new Uint8Array(carData.length); 12 21 for (let i = 0; i < carData.length; i++) bytes[i] = carData.charCodeAt(i); 13 - document.getElementById('download-car').addEventListener('click', (e) => { 22 + button.addEventListener('click', (e) => { 14 23 e.preventDefault(); 15 24 const blob = new Blob([bytes], {type: 'application/vnd.ipld.car'}); 16 25 const url = URL.createObjectURL(blob); ··· 18 27 a.href = url; a.download = 'day3.car'; a.click(); 19 28 URL.revokeObjectURL(url); 20 29 }); 30 + })(); 21 31 </script>