Add prompt marketplace interactions and profile prompt tabs
This commit is contained in:
1 parent
691bc72681
commit
c95319b1fe
20 files changed
+734
-146
No files matched your search
@@ -28,8 +28,8 @@
|
||||
<main class="create-main">
|
||||
<div class="create-container">
|
||||
<div class="create-header">
|
||||
<h1>Create AI Prompt</h1>
|
||||
<p>Design and save custom prompts for your AI workflows.</p>
|
||||
<h1 id="create-title">Create AI Prompt</h1>
|
||||
<p id="create-subtitle">Design and save custom prompts for your AI workflows.</p>
|
||||
</div>
|
||||
|
||||
<form id="createPromptForm" class="create-form" enctype="multipart/form-data">
|
||||
@@ -96,7 +96,7 @@
|
||||
|
||||
<!-- Submit Button -->
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="submit-btn">Publish Prompt</button>
|
||||
<button type="submit" class="submit-btn" id="submitPromptBtn">Publish Prompt</button>
|
||||
<button type="button" class="cancel-btn">Cancel</button>
|
||||
</div>
|
||||
<p id="create-status" style="text-align:center;color:#64748b;margin:0;"></p>
|
||||
@@ -112,6 +112,8 @@
|
||||
const paidBtn = document.getElementById('paidBtn');
|
||||
const priceField = document.getElementById('priceField');
|
||||
const priceInput = document.getElementById('price');
|
||||
const editPromptId = new URLSearchParams(location.search).get('id');
|
||||
const submitPromptBtn = document.getElementById('submitPromptBtn');
|
||||
|
||||
freeBtn.addEventListener('click', () => {
|
||||
freeBtn.classList.add('active');
|
||||
@@ -169,12 +171,56 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPromptForEdit() {
|
||||
if (!editPromptId) return;
|
||||
|
||||
document.getElementById('create-title').textContent = 'Edit AI Prompt';
|
||||
document.getElementById('create-subtitle').textContent = 'Update your published prompt.';
|
||||
submitPromptBtn.textContent = 'Save Changes';
|
||||
|
||||
const status = document.getElementById('create-status');
|
||||
status.textContent = 'Loading prompt...';
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/v1/prompts/${editPromptId}`);
|
||||
if (response.status === 401) {
|
||||
location.href = '/login';
|
||||
return;
|
||||
}
|
||||
if (!response.ok) throw new Error('Prompt could not be loaded.');
|
||||
|
||||
const prompt = await response.json();
|
||||
document.getElementById('title').value = prompt.title || '';
|
||||
document.getElementById('description').value = prompt.description || '';
|
||||
document.getElementById('category').value = prompt.categorySlug || document.getElementById('category').value;
|
||||
document.getElementById('promptContent').value = prompt.content || '';
|
||||
document.getElementById('exampleOutput').value = prompt.exampleOutput || '';
|
||||
exampleImageUrl = prompt.exampleImageUrl || '';
|
||||
|
||||
if (exampleImageUrl) {
|
||||
previewImg.src = exampleImageUrl;
|
||||
imagePreview.style.display = 'block';
|
||||
}
|
||||
|
||||
if (prompt.price != null && Number(prompt.price) > 0) {
|
||||
paidBtn.click();
|
||||
priceInput.value = Number(prompt.price);
|
||||
} else {
|
||||
freeBtn.click();
|
||||
}
|
||||
|
||||
status.textContent = '';
|
||||
} catch (error) {
|
||||
status.textContent = error.message;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle form submission
|
||||
document.getElementById('createPromptForm').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const status = document.getElementById('create-status');
|
||||
const submitBtn = document.querySelector('.submit-btn');
|
||||
status.textContent = 'Publishing...';
|
||||
status.textContent = editPromptId ? 'Saving...' : 'Publishing...';
|
||||
submitBtn.disabled = true;
|
||||
|
||||
try {
|
||||
@@ -192,8 +238,8 @@
|
||||
slug: null
|
||||
};
|
||||
|
||||
const response = await fetch('/api/v1/prompts', {
|
||||
method: 'POST',
|
||||
const response = await fetch(editPromptId ? `/api/v1/prompts/${editPromptId}` : '/api/v1/prompts', {
|
||||
method: editPromptId ? 'PUT' : 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify(payload)
|
||||
@@ -254,7 +300,7 @@
|
||||
.then(r => r.text())
|
||||
.then(data => document.getElementById('topbar-container').innerHTML = data);
|
||||
|
||||
loadCategories();
|
||||
loadCategories().then(loadPromptForEdit);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user