From a1d84052a07edf84b102bb73fb0e71d804cb6e6b Mon Sep 17 00:00:00 2001 From: reaper47 Date: Sat, 20 Jul 2024 14:42:08 +0200 Subject: [PATCH] Finish web share --- .idea/dataSources.xml | 2 +- docs/website/content/about/changelog/v1.3.0.md | 1 + docs/website/themes/hextra | 2 +- internal/server/handlers_cookbooks.go | 14 +++++++++++--- internal/server/handlers_cookbooks_test.go | 4 ++-- internal/server/handlers_recipes.go | 13 ++++++++++--- internal/server/handlers_recipes_test.go | 10 +++++----- web/components/cookbooks.templ | 10 +++++++++- web/components/recipes.templ | 10 ++++++---- 9 files changed, 46 insertions(+), 20 deletions(-) diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index 07bef0f04..d7af92055 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -1,7 +1,7 @@ - + sqlite.xerial true org.sqlite.JDBC diff --git a/docs/website/content/about/changelog/v1.3.0.md b/docs/website/content/about/changelog/v1.3.0.md index 1e73b91e8..9f06691f6 100644 --- a/docs/website/content/about/changelog/v1.3.0.md +++ b/docs/website/content/about/changelog/v1.3.0.md @@ -6,6 +6,7 @@ weight: 1 ## Added - [EMOJI] **Bypass Guide option**: You may now bypass the guide and go straight to the login page when anonymous by setting the `server.bypassGuide` configuration variable or the `RECIPYA_SERVER_BYPASS_GUIDE` environment variable to `true`. You may also do so from the settings. +- [EMOJI] **Share**: It's now possible to share to multiple installed apps, e.g. WhatsApp, Gmail and Telegram. ## Fixed diff --git a/docs/website/themes/hextra b/docs/website/themes/hextra index e3b582676..6ee6ddeac 160000 --- a/docs/website/themes/hextra +++ b/docs/website/themes/hextra @@ -1 +1 @@ -Subproject commit e3b582676e5db64078053db99e3636e5b6311874 +Subproject commit 6ee6ddeacb9cdf80a390a762f202e0b4c8d0cd94 diff --git a/internal/server/handlers_cookbooks.go b/internal/server/handlers_cookbooks.go index 974109140..f17b46ff9 100644 --- a/internal/server/handlers_cookbooks.go +++ b/internal/server/handlers_cookbooks.go @@ -10,6 +10,7 @@ import ( "log/slog" "net/http" "strconv" + "strings" ) func (s *Server) cookbooksHandler() http.HandlerFunc { @@ -651,10 +652,17 @@ func (s *Server) cookbookSharePostHandler() http.HandlerFunc { return } + link = r.Host + link + if !strings.HasPrefix(link, "http") { + if r.TLS != nil { + link = "https://" + link + } else { + link = "http://" + link + } + } + slog.Info("Cookbook shared", userIDAttr, "share", share, "link", link) - _ = components.ShareLink(templates.Data{ - Content: r.Host + link, - }).Render(r.Context(), w) + _ = components.ShareLink(templates.Data{Content: link}).Render(r.Context(), w) } } diff --git a/internal/server/handlers_cookbooks_test.go b/internal/server/handlers_cookbooks_test.go index 02b189031..f07087937 100644 --- a/internal/server/handlers_cookbooks_test.go +++ b/internal/server/handlers_cookbooks_test.go @@ -109,7 +109,7 @@ func TestHandlers_Cookbooks(t *testing.T) { `
`, ``, ``, - ``, + ``, ``, ``, ``, @@ -811,7 +811,7 @@ func TestHandlers_Cookbooks_Share(t *testing.T) { assertStatus(t, rr.Code, http.StatusOK) assertStringsInHTML(t, getBodyHTML(rr), []string{ - `
`, ``, - `Chicken Jersey`, - ` } - { data.Recipe.Name } + { data.Recipe.Name } if data.Share.IsShared { if !data.Share.IsFromHost { @@ -1966,10 +1966,12 @@ templ viewRecipe(data *templates.ViewRecipeData, isAuthenticated bool) { hx-target="#share-dialog-result" _="on htmx:afterRequest from me if event.detail.successful - if no navigator.canShare - call share_dialog.showModal() + if navigator.canShare + set name to document.querySelector('[itemprop=name]').textContent then + set data to {title: name, text: name, url: document.querySelector('#share-dialog-result input').value} then + call navigator.share(data) else - alert('fuck') + call share_dialog.showModal() end" > @iconShare()