Add a button to get the public link of a recipe

This commit is contained in:
traxys 2024-03-02 22:28:08 +01:00
parent 05120ab201
commit dec027f258

View file

@ -107,6 +107,7 @@ async fn list_public_recipe(
async fn recipe_view(
r: &recipe::Model,
household_id: Uuid,
private: bool,
db: &DatabaseConnection,
) -> Result<Markup, RouteError> {
@ -145,6 +146,22 @@ async fn recipe_view(
});
"#;
if private {
script += &format!(
r#"
current_page = window.location.origin;
console.log(current_page);
public_link = document.querySelector('#publicLink');
public_link.addEventListener("click", () => navigator.clipboard.writeText(
window.location.origin + "/recipe/public/{}/{}"
));
"#,
household_id, r.id
);
}
let steps = {
let parser = Parser::new(&r.steps);
@ -158,7 +175,10 @@ async fn recipe_view(
.d-flex.align-items-center.justify-content-center."w-100" {
.container.text-center.rounded.border."pt-2"."m-2" {
h1 { (r.name) @if private { (recipe_rating(r.ranking)) } }
@if private { ."mt-2" { "TODO: edit" } }
@if private {
button .btn.btn-secondary."mt-2" #publicLink { "Copy public link" }
."mt-2" { "TODO: edit" }
}
."mt-2".container.text-start {
.row {
."col-8"[private] {
@ -215,7 +235,7 @@ async fn view_recipe(
SidebarLocation::RecipeList,
&household,
&user,
recipe_view(&recipe, true, &state.db).await?,
recipe_view(&recipe, household.0.id, true, &state.db).await?,
))
}
@ -241,12 +261,14 @@ async fn view_public_recipe(
.await?
.ok_or(RouteError::RessourceNotFound)?;
Ok(base_page(recipe_view(&recipe, false, &state.db).await?))
Ok(base_page(
recipe_view(&recipe, household.id, false, &state.db).await?,
))
}
async fn create_recipe(
user: &AuthenticatedUser,
household: &CurrentHousehold,
user: AuthenticatedUser,
household: CurrentHousehold,
) -> Result<Markup, RouteError> {
Ok(sidebar(
SidebarLocation::RecipeCreator,