Run a giveaway from a bsky post. Choose from those who interacted with it

wip

Changed files
+83 -50
+83 -50
Index.html
··· 37 37 </script> 38 38 39 39 <script> 40 + // links/links/distinct-dids?target=at://did:plc:vc7f4oafdgxsihk4cry2xpze/app.bsky.feed.post/3lgwdn7vd722r&collection=app.bsky.feed.like&path=.subject.uri 41 + const constellationEndpoint = 'https://constellation.microcosm.blue/links/distinct-dids'; 40 42 41 43 function isValidHttpUrl(string) { 42 44 let url; ··· 52 54 Alpine.data('giveaway', () => ({ 53 55 //Form input 54 56 post_url: '', 57 + winner_count: 1, 55 58 likes_only: false, 56 59 reposts_only: false, 57 60 likes_and_reposts: false, ··· 64 67 this.reposts_only = targetId === 'reposts_only'; 65 68 this.likes_and_reposts = targetId === 'likes_and_reposts'; 66 69 }, 67 - 68 - test() { 69 - console.log('test'); 70 - }, 71 70 async runGiveaway() { 72 - //TODO validation of input 73 - 71 + this.error = ''; 72 + //Form validation 74 73 if (!isValidHttpUrl(this.post_url)) { 75 74 this.error = 'Invalid Bluesky post URL'; 76 75 return; 77 76 } 78 77 79 - let postSplit = this.post_url.split('/'); 78 + if (this.winner_count < 1) { 79 + this.error = 'SOMEBODY has to win'; 80 + } 81 + 82 + if (!this.likes_only && !this.reposts_only && !this.likes_and_reposts) { 83 + this.error = 'Well, you have to pick some way for them to win'; 84 + return; 85 + } 86 + 87 + let atUri = ''; 88 + if (this.post_url.startsWith('at://')) { 89 + atUri = this.post_url; 90 + } else { 91 + //More checks to make sure it's a bsky url 92 + if (!this.post_url.startsWith('https://bsky.app/')) { 93 + this.error = 'Link to the Bluesky post or at uri please'; 94 + return; 95 + } 96 + const postSplit = this.post_url.split('/'); 97 + if (postSplit.length < 7) { 98 + this.error = 'Invalid Bluesky post URL. Should look like https://bsky.app/profile/baileytownsend.dev/post/3lbq7o74fcc2d'; 99 + return; 100 + } 101 + try { 102 + const handle = postSplit[4]; 103 + const recordKey = postSplit[6]; 104 + 105 + let did = await window.resolveHandle(handle); 106 + atUri = `at://${did}/app.bsky.feed.post/${recordKey}`; 107 + 108 + } catch (e) { 109 + console.log(e); 110 + this.error = e.message; 111 + return; 112 + } 113 + } 114 + 115 + 116 + console.log(atUri); 80 117 81 - let handle = postSplit[4]; 82 - console.log(handle); 83 - let recordKey = postSplit[6]; 84 - console.log(recordKey); 85 - let result = await window.resolveHandle(handle); 86 - console.log(result); 87 118 } 88 119 89 120 })) ··· 98 129 <div class="text-center"> 99 130 <h1 class="text-5xl font-bold">at://giveaways 🎉</h1> 100 131 <p class="py-6"> 101 - Enter a bluesky post, how many winners and what to check by 132 + Pick which Bluesky post you want to use for a giveaway. 102 133 </p> 103 134 <div>uses <a class="link" href="https://constellation.microcosm.blue/">constellation 104 135 🌌</a> ··· 114 145 </div> 115 146 <div class="card bg-base-100 w-full max-w-sm shrink-0 shadow-2xl"> 116 147 <div class="card-body" x-data="giveaway"> 117 - <fieldset class="fieldset"> 118 - <label for="post_url" class="label">Post Url</label> 119 - <input x-model="post_url" id="post_url" type="text" class="input" 120 - placeholder="https://bsky.app/profile/baileytownsend.dev/post/3lbq7o74fcc2d"/> 121 - <label for="winner_count" class="label">How many winners?</label> 122 - <input id="winner_count" type="number" class="input" value="1"/> 123 - <fieldset class="fieldset bg-base-100 border-base-300 rounded-box w-64 border p-4"> 124 - <legend class="fieldset-legend">Winning options</legend> 125 - <label class="label"> 126 - <input x-model="likes_only" x-on:change="validateCheckBoxes($event)" 127 - id="likes" 128 - type="checkbox" 129 - checked="checked" 130 - class="checkbox"/> 131 - Likes only 132 - </label> 133 - <label class="label"> 134 - <input x-model="reposts_only" x-on:change="validateCheckBoxes($event)" id="reposts_only" 135 - type="checkbox" 136 - class="checkbox"/> 137 - Reposts only 138 - </label> 139 - <label class="label"> 140 - <input x-model="likes_and_reposts" x-on:change="validateCheckBoxes($event)" 141 - id="likes_and_reposts" 142 - type="checkbox" 143 - class="checkbox"/> 144 - Likes & Reposts 145 - </label> 148 + <form x-on:submit.prevent="await runGiveaway()"> 149 + <fieldset class="fieldset"> 150 + <label for="post_url" class="label">Post Url</label> 151 + <input x-model="post_url" id="post_url" type="text" class="input" 152 + placeholder="https://bsky.app/profile/baileytownsend.dev/post/3lbq7o74fcc2d"/> 153 + <label for="winner_count" class="label">How many winners?</label> 154 + <input x-model="winner_count" id="winner_count" type="number" class="input" value="1"/> 155 + <fieldset class="fieldset bg-base-100 border-base-300 rounded-box w-64 border p-4"> 156 + <legend class="fieldset-legend">Winning options</legend> 157 + <label class="label"> 158 + <input x-model="likes_only" x-on:change="validateCheckBoxes($event)" 159 + id="likes" 160 + type="checkbox" 161 + checked="checked" 162 + class="checkbox"/> 163 + Likes only 164 + </label> 165 + <label class="label"> 166 + <input x-model="reposts_only" x-on:change="validateCheckBoxes($event)" id="reposts_only" 167 + type="checkbox" 168 + class="checkbox"/> 169 + Reposts only 170 + </label> 171 + <label class="label"> 172 + <input x-model="likes_and_reposts" x-on:change="validateCheckBoxes($event)" 173 + id="likes_and_reposts" 174 + type="checkbox" 175 + class="checkbox"/> 176 + Likes & Reposts 177 + </label> 146 178 179 + </fieldset> 180 + <span x-show="error" x-text="error" class="text-red-500 text-lg font-bold"></span> 181 + <button type="submit" class="btn btn-neutral mt-4">I choose 182 + you! 183 + </button> 147 184 </fieldset> 148 - <span x-show="error" x-text="error" class="text-red-500"></span> 149 - <button x-on:click="await runGiveaway()" class="btn btn-neutral mt-4">I choose 150 - you! 151 - </button> 152 - </fieldset> 153 - <a href="https://tangled.sh/@baileytownsend.dev/at-giveaways" class="link">View on <span hx-boost="true" 154 - class="font-semibold italic">tangled.sh</span></a> 185 + </form> 186 + <a href="https://tangled.sh/@baileytownsend.dev/at-giveaways" class="link">View on <span 187 + class="font-semibold italic">tangled.sh</span></a> 155 188 </div> 156 189 </div> 157 190 </div>