Refactor: Update submit.html

This commit is contained in:
2025-10-03 12:59:56 -07:00
parent 8166507513
commit bc4fa990ff

View File

@@ -23,23 +23,18 @@
<main class="max-w-2xl mx-auto py-8 px-4" x-data="f()"> <main class="max-w-2xl mx-auto py-8 px-4" x-data="f()">
<h1 class="text-xl font-bold mb-4">Submit a Post</h1> <h1 class="text-xl font-bold mb-4">Submit a Post</h1>
<form @submit.prevent="s" class="bg-white p-6 rounded border border-gray-300"> <form @submit.prevent="s" class="bg-white p-6 rounded border border-gray-300 space-y-4">
<div class="flex border-b border-gray-300 mb-4">
<button type="button" @click="type='text'" :class="type==='text' ? 'border-b-2 border-gray-900 text-gray-900' : 'text-gray-500'" class="px-4 py-2 text-sm font-medium">Text</button>
<button type="button" @click="type='link'" :class="type==='link' ? 'border-b-2 border-gray-900 text-gray-900' : 'text-gray-500'" class="px-4 py-2 text-sm font-medium">Link</button>
</div>
<div class="space-y-4">
<div> <div>
<label class="block text-sm font-medium mb-1">Title</label> <label class="block text-sm font-medium mb-1">Title</label>
<input x-model="t" type="text" required class="w-full border border-gray-300 rounded px-3 py-2 text-sm"> <input x-model="t" type="text" required class="w-full border border-gray-300 rounded px-3 py-2 text-sm">
</div> </div>
<div x-show="type==='link'"> <div>
<label class="block text-sm font-medium mb-1">Link</label> <label class="block text-sm font-medium mb-1">Link (optional)</label>
<input x-model="l" type="url" class="w-full border border-gray-300 rounded px-3 py-2 text-sm" placeholder="https://..."> <input x-model="l" type="url" class="w-full border border-gray-300 rounded px-3 py-2 text-sm" placeholder="https://...">
</div> </div>
<div x-show="type==='text'"> <div>
<div class="flex items-baseline justify-between"> <div class="flex items-baseline justify-between">
<label class="block text-sm font-medium mb-1">Text (optional)</label> <label class="block text-sm font-medium mb-1">Text (for self posts)</label>
<span class="text-xs text-gray-500">Markdown supported</span> <span class="text-xs text-gray-500">Markdown supported</span>
</div> </div>
<textarea x-model="c" rows="8" class="w-full border border-gray-300 rounded px-3 py-2 text-sm"></textarea> <textarea x-model="c" rows="8" class="w-full border border-gray-300 rounded px-3 py-2 text-sm"></textarea>
@@ -47,7 +42,6 @@
<div class="cf-turnstile" data-sitekey="0x4AAAAAAB4klN__r6wwJXs4"></div> <div class="cf-turnstile" data-sitekey="0x4AAAAAAB4klN__r6wwJXs4"></div>
<button type="submit" :disabled="loading" class="bg-gray-900 text-white px-4 py-2 rounded text-sm hover:bg-gray-800" x-text="loading?'Moderating...':'Submit'"></button> <button type="submit" :disabled="loading" class="bg-gray-900 text-white px-4 py-2 rounded text-sm hover:bg-gray-800" x-text="loading?'Moderating...':'Submit'"></button>
<p x-show="e" x-text="e" class="text-red-600 text-sm"></p> <p x-show="e" x-text="e" class="text-red-600 text-sm"></p>
</div>
</form> </form>
<div class="mt-6 flex items-center justify-center gap-2 text-xs text-green-700"> <div class="mt-6 flex items-center justify-center gap-2 text-xs text-green-700">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg> <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
@@ -58,7 +52,8 @@
<script> <script>
const host=window.location.hostname,parts=host.split('.'); const host=window.location.hostname,parts=host.split('.');
if(parts.length>2)document.getElementById('subdomain').textContent=parts[0]+'.'; if(parts.length>2)document.getElementById('subdomain').textContent=parts[0]+'.';
f=()=>({t:'',l:'',c:'',e:null,loading:false,type:'text',async s(){this.loading=!0;this.e=null;try{const sub=parts.length>2?parts[0]:'free';if(this.type==='link'&&!this.l){throw new Error('Link URL is required.')}const token=this.$el.querySelector('[name="cf-turnstile-response"]')?.value;if(!token)throw new Error('Please complete the CAPTCHA.');const r=await fetch('https://speech.capital/api/posts',{method:'POST',credentials:'include',headers:{'Content-Type':'application/json'},body:JSON.stringify({sub,title:this.t,link:this.l,content:this.c,post_type:this.type,'cf-turnstile-response':token})});if(!r.ok){const d=await r.json();throw new Error(d.error?.message||'Submission failed')}const{id}=await r.json();window.location.href=`/${id}`}catch(e){this.e=e.message}finally{this.loading=!1}}}) f=()=>({t:'',l:'',c:'',e:null,loading:false,async s(){this.loading=!0;this.e=null;try{const sub=parts.length>2?parts[0]:'free';const token=this.$el.querySelector('[name="cf-turnstile-response"]')?.value;if(!token)throw new Error('Please complete the CAPTCHA.');const r=await fetch('https://speech.capital/api/posts',{method:'POST',credentials:'include',headers:{'Content-Type':'application/json'},body:JSON.stringify({sub,title:this.t,link:this.l||null,content:this.c||null,'cf-turnstile-response':token})});if(!r.ok){const d=await r.json();throw new Error(d.error?.message||'Submission failed')}const{id}=await r.json();window.location.href=`/${id}`}catch(e){this.e=e.message}finally{this.loading=!1}}})
</script> </script>
</body> </body>
</html> </html>