diff --git a/src/lib.rs b/src/lib.rs index b205cea..bcb487e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -173,12 +173,21 @@ impl State { self.scoped("") } - fn edit_collection_path(&self, id: Uuid, token: &ValidToken) -> String { - self.scoped(&format!("{id}?token={}", token.token)) + fn edit_collection_path( + &self, + collection_id: Uuid, + entry_id: Option, + token: &ValidToken, + ) -> String { + if let Some(entry_id) = entry_id { + self.scoped(&format!("{collection_id}?token={}#{entry_id}", token.token)) + } else { + self.scoped(&format!("{collection_id}?token={}", token.token)) + } } - fn update_collection_path(&self, id: Uuid, token: &ValidToken) -> String { - self.scoped(&format!("{id}?token={}", token.token)) + fn update_collection_path(&self, collection_id: Uuid, token: &ValidToken) -> String { + self.scoped(&format!("{collection_id}?token={}", token.token)) } fn delete_collection_path(&self, id: Uuid, token: &ValidToken, confirmed: bool) -> String { @@ -314,9 +323,17 @@ pub fn configure(cfg: &mut web::ServiceConfig, state: State, client: Client) { ); } -fn to_edit_page(id: Uuid, token: &ValidToken, state: &State) -> HttpResponse { +fn to_edit_page( + collection_id: Uuid, + entry_id: Option, + token: &ValidToken, + state: &State, +) -> HttpResponse { HttpResponse::SeeOther() - .insert_header((LOCATION, state.edit_collection_path(id, token))) + .insert_header(( + LOCATION, + state.edit_collection_path(collection_id, entry_id, token), + )) .finish() } @@ -696,7 +713,12 @@ async fn upload( .await .stateful(&state)?; - Ok(to_edit_page(path.collection, &token, &state)) + Ok(to_edit_page( + path.collection, + Some(entry_path.entry), + &token, + &state, + )) } #[derive(Debug, serde::Deserialize)] @@ -845,6 +867,7 @@ async fn create_collection( Ok(to_edit_page( collection_path.collection, + None, &ValidToken { token: token.token }, &state, )) @@ -865,7 +888,7 @@ async fn update_collection( .await .stateful(&state)?; - Ok(to_edit_page(path.collection, &token, &state)) + Ok(to_edit_page(path.collection, None, &token, &state)) } async fn move_entry( @@ -880,7 +903,12 @@ async fn move_entry( .await .stateful(&state)?; - Ok(to_edit_page(path.collection, &token, &state)) + Ok(to_edit_page( + path.collection, + Some(path.entry), + &token, + &state, + )) } #[tracing::instrument(name = "Update Entry")] @@ -898,7 +926,12 @@ async fn update_entry( .await .stateful(&state)?; - Ok(to_edit_page(entry_path.collection, &token, &state)) + Ok(to_edit_page( + entry_path.collection, + Some(entry_path.entry), + &token, + &state, + )) } #[derive(Debug, serde::Deserialize)] @@ -953,7 +986,7 @@ async fn delete_entry( .await .stateful(&state)?; - Ok(to_edit_page(entry_path.collection, &token, &state)) + Ok(to_edit_page(entry_path.collection, None, &token, &state)) } fn qr(req: &HttpRequest, path: &web::Path, state: &web::Data) -> String { diff --git a/templates/confirm_delete.rs.html b/templates/confirm_delete.rs.html index 86ae80a..14e9499 100644 --- a/templates/confirm_delete.rs.html +++ b/templates/confirm_delete.rs.html @@ -18,7 +18,7 @@
@:button_link_html("Delete Collection", &state.delete_collection_path(id, token, true), ButtonKind::Submit) - @:button_link_html("Cancel", &state.edit_collection_path(id, token), ButtonKind::Outline) + @:button_link_html("Cancel", &state.edit_collection_path(id, None, token), ButtonKind::Outline)
diff --git a/templates/confirm_entry_delete.rs.html b/templates/confirm_entry_delete.rs.html index a378218..f93f546 100644 --- a/templates/confirm_entry_delete.rs.html +++ b/templates/confirm_entry_delete.rs.html @@ -21,7 +21,7 @@

Are you sure you want to delete this image?

@:button_link_html("Delete Image", &state.delete_entry_path(collection_id, id, token, true), ButtonKind::Submit) - @:button_link_html("Cancel", &state.edit_collection_path(collection_id, token), ButtonKind::Outline) + @:button_link_html("Cancel", &state.edit_collection_path(collection_id, Some(id), token), ButtonKind::Outline)
diff --git a/templates/edit_collection.rs.html b/templates/edit_collection.rs.html index e8b0ef9..6f2c632 100644 --- a/templates/edit_collection.rs.html +++ b/templates/edit_collection.rs.html @@ -1,6 +1,6 @@ @use crate::{ui::ButtonKind, Collection, Direction, Entry, State, ValidToken}; -@use super::{button_html, button_link_html, image_html, file_input_html, layout_html, return_home_html, text_area_html, text_input_html, -statics::file_upload_js}; +@use super::{button_html, button_link_html, image_html, file_input_html, layout_html, return_home_html, text_area_html, +text_input_html, statics::file_upload_js}; @use uuid::Uuid; @(collection: &Collection, collection_id: Uuid, entries: &[(Uuid, Entry)], token: &ValidToken, state: &State, qr: &str) @@ -29,7 +29,7 @@ statics::file_upload_js};

Edit Collection

@@ -44,7 +44,7 @@ statics::file_upload_js};
    @for (i, (id, entry)) in entries.iter().enumerate() { -
  • +
  • @@ -61,7 +61,8 @@ statics::file_upload_js};
    @if let Some(upload_id) = entry.upload_id() { - @:button_link_html("Refresh", &state.edit_collection_path(collection_id, token), ButtonKind::Submit) + @:button_link_html("Refresh", &state.edit_collection_path(collection_id, Some(*id), token), + ButtonKind::Submit) } @if let Some((filename, delete_token)) = entry.file_parts() {