feat(template): add user_id to HtmlPageContext and delete button to diary
This commit is contained in:
@@ -21,6 +21,13 @@
|
|||||||
<div class="comment">{{ comment.value() }}</div>
|
<div class="comment">{{ comment.value() }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="watched-at">{{ entry.review().watched_at().format("%Y-%m-%d") }}</div>
|
<div class="watched-at">{{ entry.review().watched_at().format("%Y-%m-%d") }}</div>
|
||||||
|
{% if let Some(uid) = ctx.user_id %}
|
||||||
|
{% if *uid == entry.review().user_id().value() %}
|
||||||
|
<form method="post" action="/reviews/{{ entry.review().id().value() }}/delete">
|
||||||
|
<button type="submit">Delete</button>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use domain::models::{DiaryEntry, collections::Paginated};
|
use domain::models::{DiaryEntry, collections::Paginated};
|
||||||
|
|
||||||
pub struct HtmlPageContext {
|
pub struct HtmlPageContext {
|
||||||
pub user_email: Option<String>,
|
pub user_email: Option<String>,
|
||||||
|
pub user_id: Option<Uuid>,
|
||||||
pub register_enabled: bool,
|
pub register_enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,11 +24,12 @@ pub mod html {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async fn build_page_context(state: &AppState, user_id: Option<UserId>) -> HtmlPageContext {
|
async fn build_page_context(state: &AppState, user_id: Option<UserId>) -> HtmlPageContext {
|
||||||
let user_email = if let Some(id) = user_id {
|
let uuid = user_id.as_ref().map(|u| u.value());
|
||||||
|
let user_email = if let Some(ref id) = user_id {
|
||||||
state
|
state
|
||||||
.app_ctx
|
.app_ctx
|
||||||
.user_repository
|
.user_repository
|
||||||
.find_by_id(&id)
|
.find_by_id(id)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.flatten()
|
.flatten()
|
||||||
@@ -38,6 +39,7 @@ pub mod html {
|
|||||||
};
|
};
|
||||||
HtmlPageContext {
|
HtmlPageContext {
|
||||||
user_email,
|
user_email,
|
||||||
|
user_id: uuid,
|
||||||
register_enabled: state.app_ctx.config.allow_registration,
|
register_enabled: state.app_ctx.config.allow_registration,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,6 +91,7 @@ pub mod html {
|
|||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let ctx = HtmlPageContext {
|
let ctx = HtmlPageContext {
|
||||||
user_email: None,
|
user_email: None,
|
||||||
|
user_id: None,
|
||||||
register_enabled: state.app_ctx.config.allow_registration,
|
register_enabled: state.app_ctx.config.allow_registration,
|
||||||
};
|
};
|
||||||
let html = state
|
let html = state
|
||||||
@@ -140,6 +143,7 @@ pub mod html {
|
|||||||
}
|
}
|
||||||
let ctx = HtmlPageContext {
|
let ctx = HtmlPageContext {
|
||||||
user_email: None,
|
user_email: None,
|
||||||
|
user_id: None,
|
||||||
register_enabled: true,
|
register_enabled: true,
|
||||||
};
|
};
|
||||||
let html = state
|
let html = state
|
||||||
|
|||||||
Reference in New Issue
Block a user