97 lines
5.8 KiB
Plaintext
97 lines
5.8 KiB
Plaintext
package blog
|
|
|
|
import (
|
|
"gobeyhan/database/models"
|
|
"fmt"
|
|
)
|
|
|
|
templ CommentList(items []models.Comment) {
|
|
@Layout("Blog Comments") {
|
|
<div class="flex justify-between items-center mb-6">
|
|
<h1 class="text-2xl font-semibold text-gray-900">Comments</h1>
|
|
</div>
|
|
|
|
<div class="bg-white shadow overflow-hidden sm:rounded-lg">
|
|
<table class="min-w-full divide-y divide-gray-200">
|
|
<thead class="bg-gray-50">
|
|
<tr>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Post</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Author</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Comment</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
|
|
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="bg-white divide-y divide-gray-200">
|
|
for _, comment := range items {
|
|
<tr>
|
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{ fmt.Sprintf("%d", comment.ID) }</td>
|
|
<td class="px-6 py-4 text-sm text-gray-900">
|
|
<div class="max-w-xs truncate">{ comment.Product.Title }</div>
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
|
User ID: { fmt.Sprintf("%d", comment.UserID) }
|
|
</td>
|
|
<td class="px-6 py-4 text-sm text-gray-500">
|
|
<div class="max-w-md line-clamp-2">{ comment.Body }</div>
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
|
if comment.IsActive {
|
|
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">Approved</span>
|
|
} else {
|
|
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800">Pending</span>
|
|
}
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
|
<a href={ templ.SafeURL(fmt.Sprintf("/admin/blog/comments/%d/edit", comment.ID)) } class="text-indigo-600 hover:text-indigo-900 mr-4">Edit</a>
|
|
<form id={ fmt.Sprintf("delete-comment-%d", comment.ID) } action={ templ.SafeURL(fmt.Sprintf("/admin/blog/comments/%d/delete", comment.ID)) } method="POST" class="inline">
|
|
<button type="button" class="text-red-600 hover:text-red-900" onclick={ templ.ComponentScript{ Call: fmt.Sprintf("confirmDelete('Delete Comment', 'Are you sure you want to delete this comment?', 'delete-comment-%d')", comment.ID) } }>Delete</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
}
|
|
}
|
|
|
|
templ CommentForm(comment *models.Comment, errors map[string]string) {
|
|
@Layout("Edit Comment") {
|
|
<div class="max-w-2xl mx-auto py-6">
|
|
<h1 class="text-2xl font-semibold text-gray-900 mb-6">Edit Comment</h1>
|
|
<form action={ templ.SafeURL(fmt.Sprintf("/admin/blog/comments/%d", comment.ID)) } method="POST" class="space-y-6 bg-white p-6 rounded-lg shadow">
|
|
<div class="grid grid-cols-2 gap-4">
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700">User ID</label>
|
|
<p class="mt-1 p-2 bg-gray-50 border rounded text-sm text-gray-900">{ fmt.Sprintf("%d", comment.UserID) }</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label for="body" class="block text-sm font-medium text-gray-700">Comment Body</label>
|
|
<textarea name="body" id="body" rows="5" required
|
|
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm p-2 border">{ comment.Body }</textarea>
|
|
</div>
|
|
|
|
<div class="flex items-center">
|
|
<label class="flex items-center">
|
|
<input type="checkbox" name="is_active"
|
|
if comment.IsActive {
|
|
checked
|
|
}
|
|
class="rounded border-gray-300 text-indigo-600 shadow-sm focus:border-indigo-500 focus:ring-indigo-500" />
|
|
<span class="ml-2 text-sm text-gray-700">Approved / Active</span>
|
|
</label>
|
|
</div>
|
|
|
|
<div class="flex justify-end gap-3">
|
|
<a href="/admin/blog/comments" class="bg-white py-2 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 hover:bg-gray-50">Cancel</a>
|
|
<button type="submit" class="bg-indigo-600 text-white px-4 py-2 rounded-md hover:bg-indigo-700">Save Changes</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
}
|
|
}
|