diff --git a/blogdb/src/posts.rs b/blogdb/src/posts.rs index 2e134f3..8bf9013 100644 --- a/blogdb/src/posts.rs +++ b/blogdb/src/posts.rs @@ -75,6 +75,19 @@ impl BlogDb { .await?; Ok(()) } + /// Delete post by id + pub async fn set_post_date(&self, id: S, date: T) -> anyhow::Result<()> + where + S: AsRef, + T: AsRef, + { + sqlx::query("UPDATE posts SET date=? WHERE id=?") + .bind(date.as_ref()) + .bind(id.as_ref()) + .execute(&self.db) + .await?; + Ok(()) + } } #[cfg(test)] diff --git a/server/src/client/assets/css/admin.css b/server/src/client/assets/css/admin.css index f52d14b..980b4aa 100644 --- a/server/src/client/assets/css/admin.css +++ b/server/src/client/assets/css/admin.css @@ -23,7 +23,7 @@ main { } .admin-widget:not(.admin-widget-user) { - max-inline-size: 50%; + max-inline-size: calc(50% - (0.5 * var(--default-padding))); } .admin-widget-user { @@ -122,8 +122,8 @@ main { .blog-admin { box-sizing: border-box; display: flex; - gap: var(--default-padding); flex-wrap: wrap; + gap: var(--default-padding); box-sizing: border-box; min-block-size: 0; flex: 1; @@ -246,7 +246,7 @@ main { a.entry-content { color: inherit; text-decoration: inherit; - inline-size: 90%; + max-inline-size: 90%; transition: all 0.3s ease; diff --git a/server/src/client/assets/js/admin.js b/server/src/client/assets/js/admin.js new file mode 100644 index 0000000..759015a --- /dev/null +++ b/server/src/client/assets/js/admin.js @@ -0,0 +1,11 @@ +const editDateButton = document.getElementById("date-update"); +const postActions = document.getElementById("post-actions"); +const children = postActions.innerHTML; + +dateInput = ` `; + +editDateButton.addEventListener("click", (ev) => { + ev.preventDefault(); + console.log(ev, postActions, dateInput); + postActions.innerHTML = dateInput; +}); diff --git a/server/src/html.rs b/server/src/html.rs index 01199d0..1c060fa 100644 --- a/server/src/html.rs +++ b/server/src/html.rs @@ -295,8 +295,7 @@ async fn admin_entries(entry_type: EntryType, session_id: i64, db: &BlogDb) -> S let is_empty: bool; let entries_html = match entry_type { EntryType::Post => { - let mut entries = db.get_posts().await.unwrap_or(vec![]); - entries.reverse(); + let entries = db.get_posts().await.unwrap_or(vec![]); let mut entry_list_html = String::new(); is_empty = entries.is_empty(); if !is_empty { diff --git a/server/src/server/routes/api/mod.rs b/server/src/server/routes/api/mod.rs index f6042b8..de50c32 100644 --- a/server/src/server/routes/api/mod.rs +++ b/server/src/server/routes/api/mod.rs @@ -38,6 +38,7 @@ pub(super) fn api(state: BlogState) -> Router { struct Entries { #[serde(default)] item: Vec, + date: Option, } #[derive(Debug, Deserialize)] @@ -45,6 +46,7 @@ struct Entries { enum PostsEndpoints { delete, unpublish, + date, } async fn posts( @@ -71,6 +73,12 @@ async fn posts( state.index_delete(term); } } + PostsEndpoints::date => { + let date = &data.date.clone().unwrap_or("1970-01-01".to_string()); + for post_id in data.item.iter() { + let _ = db.set_post_date(post_id, &date).await; + } + } } state.index_commit(); let mut headers = HeaderMap::new(); diff --git a/server/src/templates/admin-widgets/posts.html b/server/src/templates/admin-widgets/posts.html index 52a8fb6..4d0fd74 100644 --- a/server/src/templates/admin-widgets/posts.html +++ b/server/src/templates/admin-widgets/posts.html @@ -3,11 +3,14 @@

Published Posts

-
+
+
diff --git a/server/src/templates/admin.html b/server/src/templates/admin.html index d1ba99c..5a866e4 100644 --- a/server/src/templates/admin.html +++ b/server/src/templates/admin.html @@ -3,3 +3,4 @@
+