diff --git a/src/routes/admin/dashboard.rs b/src/routes/admin/dashboard.rs index 5a1df94..413c24e 100644 --- a/src/routes/admin/dashboard.rs +++ b/src/routes/admin/dashboard.rs @@ -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()) } diff --git a/src/routes/admin/posts.rs b/src/routes/admin/posts.rs index ac87f6a..0bdb52a 100644 --- a/src/routes/admin/posts.rs +++ b/src/routes/admin/posts.rs @@ -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()) } } diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 256374b..b0b497a 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -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 diff --git a/src/templates.rs b/src/templates.rs index bf5636c..d1604aa 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -64,10 +64,12 @@ pub struct DashboardTemplate { pub subscribers: Vec, pub current_page: i64, pub max_page: i64, + pub count: i64, pub users: Vec, pub posts: Vec, pub posts_current_page: i64, pub posts_max_page: i64, + pub posts_count: i64, } #[derive(Template)] diff --git a/templates/dashboard/posts/list.html b/templates/dashboard/posts/list.html index ae3e06a..d7dd9c1 100644 --- a/templates/dashboard/posts/list.html +++ b/templates/dashboard/posts/list.html @@ -10,16 +10,16 @@ - Posts management + Posts management ({{ posts_count }})

View and manage all published posts.

-
+
{% block posts %} {% if posts.is_empty() %} -
+
-

No posts yet

-

Published posts will appear here.

+

No data to display

+

The request did not return any data.

{% else %}
@@ -39,7 +39,7 @@ {% endfor %}
{% endif %} -
+
-
+
{% block subs %} {% if subscribers.is_empty() %} -
+
{% endif %} -
+
-
+
{% if users.is_empty() %} -
+
-

Activity

+
+

Activity

{% if posts.is_empty() %} -
- - - -

No posts yet

-
+
+ + + +

No posts yet

+
{% else %} - {% endif %}