From 7003da9fc898584c25d7326dee09fe86c63251d6 Mon Sep 17 00:00:00 2001 From: Mario Sergio Date: Tue, 3 Sep 2024 14:20:28 -0300 Subject: [PATCH] feat(vote): converted dashboard share buttons to templatetags --- .../static/js/copy-to-clipboard.js | 13 +++----- .../templates/candidature/dashboard.html | 28 ++++++++-------- .../candidature/templatetags/social_share.py | 32 +++++++++++++++++++ 3 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 app/org_eleicoes/votepeloclima/candidature/templatetags/social_share.py diff --git a/app/org_eleicoes/votepeloclima/candidature/static/js/copy-to-clipboard.js b/app/org_eleicoes/votepeloclima/candidature/static/js/copy-to-clipboard.js index 61507c72..e2f57435 100644 --- a/app/org_eleicoes/votepeloclima/candidature/static/js/copy-to-clipboard.js +++ b/app/org_eleicoes/votepeloclima/candidature/static/js/copy-to-clipboard.js @@ -1,19 +1,16 @@ const copyButton = document.querySelector("#copyButton"); -function copyURL(isDashboard=false) { - let url = window.location.href; +function copyURL(url=null) { + if (!url) { + // Se a URL não for passada, use a URL atual da página + url = window.location.href; + } let modalString = "?modal=true"; if (url.includes(modalString)) { url = url.replace(modalString, ""); } - if (isDashboard) { - const slug = document.getElementById("dashboard").getAttribute("data-slug"); - const baseUrl = window.location.origin; - url = baseUrl + "/c/" + slug; - } - navigator.clipboard.writeText(url).then(function() { const copyButton = document.querySelector("#copyButton"); let tooltip = bootstrap.Tooltip.getInstance(copyButton) || new bootstrap.Tooltip(copyButton); diff --git a/app/org_eleicoes/votepeloclima/candidature/templates/candidature/dashboard.html b/app/org_eleicoes/votepeloclima/candidature/templates/candidature/dashboard.html index 3225f242..e1a7df5a 100644 --- a/app/org_eleicoes/votepeloclima/candidature/templates/candidature/dashboard.html +++ b/app/org_eleicoes/votepeloclima/candidature/templates/candidature/dashboard.html @@ -1,5 +1,5 @@ {% extends "votepeloclima/base.html" %} -{% load static crispy_forms_filters %} +{% load static crispy_forms_filters social_share %} {% block content %}
@@ -92,23 +92,23 @@

Outras informações

Compartilhe seu perfil:

{% with request.scheme|add:"://"|add:request.get_host as base_url %} - - - WhatsApp + + + WhatsApp - - - Twitter + + + Twitter - - - LinkedIn + + + LinkedIn - - - Facebook + + + Facebook - diff --git a/app/org_eleicoes/votepeloclima/candidature/templatetags/social_share.py b/app/org_eleicoes/votepeloclima/candidature/templatetags/social_share.py new file mode 100644 index 00000000..23f9d349 --- /dev/null +++ b/app/org_eleicoes/votepeloclima/candidature/templatetags/social_share.py @@ -0,0 +1,32 @@ +from django import template +from urllib.parse import urlencode + +register = template.Library() + +@register.simple_tag +def share_url(base_url, slug, platform): + url = f"{base_url}/c/{slug}" + + if platform == 'whatsapp': + text = ("Oi! As eleições estão chegando e o futuro da nossa cidade depende do nosso voto. " + "Compartilho com você uma das candidaturas comprometidas na luta pelo meio ambiente e contra as ameaças climáticas. " + "Conheça as propostas na plataforma *Vote pelo Clima!*") + return f"https://wa.me/?text={urlencode({'text': text})}{url}" + + elif platform == 'twitter': + text = ("O clima mudou. A política precisa mudar. #VotePeloClima é a plataforma que reúne candidaturas de todo o Brasil " + "comprometidas com a pauta climática, eu sou uma delas! Acesse o perfil e conheça as propostas.") + return f"https://twitter.com/intent/tweet?url={url}&{urlencode({'text': text})}" + + elif platform == 'linkedin': + title = "O clima mudou. A política precisa mudar." + summary = ("#VotePeloClima é a plataforma que reúne candidaturas de todo o Brasil comprometidas com a pauta climática, " + "eu sou uma delas! Acesse o perfil e conheça as propostas.") + return f"https://www.linkedin.com/shareArticle?mini=true&url={url}&{urlencode({'title': title, 'summary': summary})}" + + elif platform == 'facebook': + quote = ("O clima mudou. A política precisa mudar. #VotePeloClima é a plataforma que reúne candidaturas de todo o Brasil " + "comprometidas com a pauta climática, eu sou uma delas! Acesse o perfil e conheça as propostas.") + return f"https://www.facebook.com/sharer/sharer.php?u={url}&{urlencode({'quote': quote})}" + + return url \ No newline at end of file