Add IDs to entries on edit page, set fragment when modifying entry

This commit is contained in:
asonix 2023-11-13 12:29:50 -06:00
parent 425569fc5e
commit 6c08946354
4 changed files with 52 additions and 18 deletions

View file

@ -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<Uuid>,
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<Uuid>,
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<CollectionPath>, state: &web::Data<State>) -> String {

View file

@ -18,7 +18,7 @@
<div class="content-group">
<div class="button-group">
@: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)
</div>
</div>
</article>

View file

@ -21,7 +21,7 @@
<p class="delete-confirmation">Are you sure you want to delete this image?</p>
<div class="button-group button-space">
@: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)
</div>
</div>
</div>

View file

@ -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};
<h3>Edit Collection</h3>
</article>
<article class="content-group">
<p class="subtitle"><a href="@state.edit_collection_path(collection_id, token)">Do not lose this link</a></p>
<p class="subtitle"><a href="@state.edit_collection_path(collection_id, None, token)">Do not lose this link</a></p>
</article>
<article class="content-group">
<form method="POST" action="@state.update_collection_path(collection_id, token)">
@ -44,7 +44,7 @@ statics::file_upload_js};
</article>
<ul>
@for (i, (id, entry)) in entries.iter().enumerate() {
<li class="content-group">
<li class="content-group" id="@id">
<article>
<div class="edit-row">
<div class="edit-item">
@ -61,7 +61,8 @@ statics::file_upload_js};
<div class="button-group button-space">
@if let Some(upload_id) = entry.upload_id() {
<input type="hidden" name="upload_id" value="@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() {
<input type="hidden" name="filename" value="@filename" />