Add a button to get the public link of a recipe
This commit is contained in:
parent
05120ab201
commit
dec027f258
1 changed files with 27 additions and 5 deletions
|
|
@ -107,6 +107,7 @@ async fn list_public_recipe(
|
||||||
|
|
||||||
async fn recipe_view(
|
async fn recipe_view(
|
||||||
r: &recipe::Model,
|
r: &recipe::Model,
|
||||||
|
household_id: Uuid,
|
||||||
private: bool,
|
private: bool,
|
||||||
db: &DatabaseConnection,
|
db: &DatabaseConnection,
|
||||||
) -> Result<Markup, RouteError> {
|
) -> 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 steps = {
|
||||||
let parser = Parser::new(&r.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" {
|
.d-flex.align-items-center.justify-content-center."w-100" {
|
||||||
.container.text-center.rounded.border."pt-2"."m-2" {
|
.container.text-center.rounded.border."pt-2"."m-2" {
|
||||||
h1 { (r.name) @if private { (recipe_rating(r.ranking)) } }
|
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 {
|
."mt-2".container.text-start {
|
||||||
.row {
|
.row {
|
||||||
."col-8"[private] {
|
."col-8"[private] {
|
||||||
|
|
@ -215,7 +235,7 @@ async fn view_recipe(
|
||||||
SidebarLocation::RecipeList,
|
SidebarLocation::RecipeList,
|
||||||
&household,
|
&household,
|
||||||
&user,
|
&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?
|
.await?
|
||||||
.ok_or(RouteError::RessourceNotFound)?;
|
.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(
|
async fn create_recipe(
|
||||||
user: &AuthenticatedUser,
|
user: AuthenticatedUser,
|
||||||
household: &CurrentHousehold,
|
household: CurrentHousehold,
|
||||||
) -> Result<Markup, RouteError> {
|
) -> Result<Markup, RouteError> {
|
||||||
Ok(sidebar(
|
Ok(sidebar(
|
||||||
SidebarLocation::RecipeCreator,
|
SidebarLocation::RecipeCreator,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue