Manage posts on dashboard and templates fixes
This commit is contained in:
@@ -42,10 +42,10 @@ pub async fn admin_dashboard(
|
||||
.await
|
||||
.context("Could not fetch subscribers from database.")
|
||||
.map_err(AppError::unexpected_message)?;
|
||||
let count = get_total_subs(&connection_pool)
|
||||
let subs_count = get_total_subs(&connection_pool)
|
||||
.await
|
||||
.context("Could not fetch total subscribers count from the database.")?;
|
||||
let max_page = get_max_page(count, SUBS_PER_PAGE);
|
||||
let max_page = get_max_page(subs_count, SUBS_PER_PAGE);
|
||||
let users = get_users(&connection_pool)
|
||||
.await
|
||||
.context("Could not fetch users")?;
|
||||
@@ -53,10 +53,10 @@ pub async fn admin_dashboard(
|
||||
.await
|
||||
.context("Could not fetch posts.")?;
|
||||
let posts_current_page = 1;
|
||||
let count = get_posts_count(&connection_pool)
|
||||
let posts_count = get_posts_count(&connection_pool)
|
||||
.await
|
||||
.context("Could not fetch posts count.")?;
|
||||
let posts_max_page = get_max_page(count, POSTS_PER_PAGE);
|
||||
let posts_max_page = get_max_page(posts_count, POSTS_PER_PAGE);
|
||||
let template = DashboardTemplate {
|
||||
user,
|
||||
idempotency_key_1,
|
||||
@@ -65,10 +65,12 @@ pub async fn admin_dashboard(
|
||||
subscribers,
|
||||
current_page,
|
||||
max_page,
|
||||
count: subs_count,
|
||||
users,
|
||||
posts,
|
||||
posts_current_page,
|
||||
posts_max_page,
|
||||
posts_count,
|
||||
};
|
||||
Ok(Html(template.render().unwrap()).into_response())
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ pub async fn delete_post(
|
||||
"We could not find the post in the database."
|
||||
)))
|
||||
} else {
|
||||
let template = MessageTemplate::success("The subscriber has been deleted.".into());
|
||||
let template = MessageTemplate::success("The post has been deleted.".into());
|
||||
Ok(template.render().unwrap().into_response())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,11 +210,14 @@ pub async fn load_more(
|
||||
let posts = get_posts_page(&connection_pool, page)
|
||||
.await
|
||||
.context("Could not fetch posts from database.")?;
|
||||
let count = posts.len();
|
||||
let count = get_posts_count(&connection_pool)
|
||||
.await
|
||||
.context("Could not fetch posts count.")?;
|
||||
let max_page = get_max_page(count, POSTS_PER_PAGE);
|
||||
Ok(Html(
|
||||
PostListTemplate {
|
||||
posts,
|
||||
next_page: if count as i64 == POSTS_PER_PAGE {
|
||||
next_page: if page < max_page {
|
||||
Some(page + 1)
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -64,10 +64,12 @@ pub struct DashboardTemplate {
|
||||
pub subscribers: Vec<SubscriberEntry>,
|
||||
pub current_page: i64,
|
||||
pub max_page: i64,
|
||||
pub count: i64,
|
||||
pub users: Vec<UserEntry>,
|
||||
pub posts: Vec<PostEntry>,
|
||||
pub posts_current_page: i64,
|
||||
pub posts_max_page: i64,
|
||||
pub posts_count: i64,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
|
||||
@@ -10,16 +10,16 @@
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
|
||||
</svg>
|
||||
Posts management
|
||||
<span>Posts management ({{ posts_count }})</span>
|
||||
</h2>
|
||||
<p class="text-sm text-gray-600 mt-1">View and manage all published posts.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="posts-list" class="py-6 space-y-6">
|
||||
<div id="posts-list" class="space-y-6">
|
||||
{% block posts %}
|
||||
{% if posts.is_empty() %}
|
||||
<div class="bg-gray-50 rounded-lg p-8 border-2 border-dashed border-gray-300 text-center">
|
||||
<div class="p-8 text-center">
|
||||
<div class="w-16 h-16 bg-gray-200 rounded-full flex items-center justify-center mx-auto mb-4">
|
||||
<svg class="w-8 h-8 text-gray-500"
|
||||
fill="none"
|
||||
@@ -29,8 +29,8 @@
|
||||
d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<h3 class="text-lg font-medium text-gray-900 mb-2">No posts yet</h3>
|
||||
<p class="text-gray-600">Published posts will appear here.</p>
|
||||
<h3 class="text-lg font-medium text-gray-900 mb-2">No data to display</h3>
|
||||
<p class="text-gray-600">The request did not return any data.</p>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="divide-y divide-gray-200">
|
||||
@@ -39,7 +39,7 @@
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="flex items-center justify-center space-x-2">
|
||||
<div class="flex items-center justify-center space-x-2 mb-6">
|
||||
<button hx-get="/admin/posts?page={{ posts_current_page - 1 }}"
|
||||
hx-target="#posts-list"
|
||||
hx-swap="innerHTML"
|
||||
|
||||
@@ -13,16 +13,16 @@
|
||||
<path d="M23 21v-2a4 4 0 0 0-3-3.87"/>
|
||||
<path d="M16 3.13a4 4 0 0 1 0 7.75"/>
|
||||
</svg>
|
||||
Subscribers management
|
||||
Subscribers management ({{ count }})
|
||||
</h2>
|
||||
<p class="text-sm text-gray-600 mt-1">View and manage your subscribers.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="subscribers-list" class="py-6 space-y-6">
|
||||
<div id="subscribers-list" class="space-y-6">
|
||||
{% block subs %}
|
||||
{% if subscribers.is_empty() %}
|
||||
<div class="bg-gray-50 rounded-lg p-8 border-2 border-dashed border-gray-300 text-center">
|
||||
<div class="g p-8 text-center">
|
||||
<div class="w-16 h-16 bg-gray-200 rounded-full flex items-center justify-center mx-auto mb-4">
|
||||
<svg class="w-8 h-8 text-gray-500"
|
||||
fill="none"
|
||||
@@ -42,7 +42,7 @@
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="flex items-center justify-center space-x-2">
|
||||
<div class="flex items-center justify-center space-x-2 mb-6">
|
||||
<button hx-get="/admin/subscribers?page={{ current_page - 1 }}"
|
||||
hx-target="#subscribers-list"
|
||||
hx-swap="innerHTML"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="flex items-center space-x-2 mb-1">
|
||||
<a href="/users/{{ user.username }}"
|
||||
class="font-medium text-gray-900 group-hover:text-blue-600 transition-colors truncate">
|
||||
class="font-medium text-gray-900 group-hover:text-blue-600 hover:underline transition-colors truncate">
|
||||
{{ user.username }}
|
||||
</a>
|
||||
{% if user.role.to_string() == "admin" %}
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="users-list" class="py-6">
|
||||
<div id="users-list">
|
||||
{% if users.is_empty() %}
|
||||
<div class="bg-gray-50 rounded-lg p-8 border-2 border-dashed border-gray-300 text-center">
|
||||
<div class="py-6 p-8 text-center">
|
||||
<div class="w-16 h-16 bg-gray-200 rounded-full flex items-center justify-center mx-auto mb-4">
|
||||
<svg class="w-8 h-8 text-gray-500"
|
||||
fill="none"
|
||||
|
||||
@@ -1,29 +1,32 @@
|
||||
<div class="bg-white rounded-lg shadow-md border border-gray-200 p-8">
|
||||
<h2 class="text-xl font-semibold text-gray-900 mb-4">Activity</h2>
|
||||
<div class="bg-white rounded-lg shadow-md border border-gray-200">
|
||||
<h2 class="text-xl font-semibold text-gray-900 pb-4 pt-8 px-8">Activity</h2>
|
||||
{% if posts.is_empty() %}
|
||||
<div class="text-center py-8 text-gray-500">
|
||||
<div class="text-center text-gray-500 p-8">
|
||||
<svg class="w-12 h-12 mx-auto mb-3 text-gray-400"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
|
||||
</svg>
|
||||
<p>No posts yet</p>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="divide-y divide-gray-200">
|
||||
<div class="divide-y divide-gray-200 pb-8">
|
||||
{% for post in posts %}
|
||||
<a href="/posts/{{ post.post_id }}"
|
||||
class="block py-4 hover:bg-gray-50 -mx-8 px-8 transition-colors group">
|
||||
class="block py-4 hover:bg-gray-50 px-8 transition-colors group">
|
||||
<div class="flex items-start justify-between">
|
||||
<div class="flex-1 min-w-0">
|
||||
<h3 class="text-base font-medium text-gray-900 group-hover:text-blue-600 transition-colors mb-1">{{ post.title }}</h3>
|
||||
<h3 class="text-base font-medium text-gray-900 group-hover:text-blue-600 transition-colors mb-1">{{
|
||||
post.title }}</h3>
|
||||
<div class="flex items-center text-sm text-gray-500">
|
||||
<svg class="w-4 h-4 mr-1.5"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/>
|
||||
</svg>
|
||||
<time datetime="{{ post.published_at }}">
|
||||
{{ post.formatted_date() }}
|
||||
@@ -34,7 +37,7 @@
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
|
||||
</svg>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user