Improve share functionality
This commit is contained in:
parent
df6e47faa8
commit
6cd3c15544
6 changed files with 68 additions and 18 deletions
|
@ -1583,6 +1583,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "last_edit",
|
"id": "last_edit",
|
||||||
|
"labels": ["added_by_default"],
|
||||||
"description": "Gives some metainfo about the last edit and who did edit it - rendering only",
|
"description": "Gives some metainfo about the last edit and who did edit it - rendering only",
|
||||||
"condition": {
|
"condition": {
|
||||||
"and": [
|
"and": [
|
||||||
|
@ -1622,6 +1623,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "just_created",
|
"id": "just_created",
|
||||||
|
"labels": ["added_by_default"],
|
||||||
"description": "This element shows a 'thank you' that the contributor has recently created this element",
|
"description": "This element shows a 'thank you' that the contributor has recently created this element",
|
||||||
"classes": "rounded-xl thanks",
|
"classes": "rounded-xl thanks",
|
||||||
"mappings": [
|
"mappings": [
|
||||||
|
@ -2609,6 +2611,34 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "qr_code",
|
||||||
|
"labels": ["added_by_default"],
|
||||||
|
"classes": "flex items-center gap-x-2",
|
||||||
|
"render": {
|
||||||
|
"special": {
|
||||||
|
"type": "qr_code"
|
||||||
|
},
|
||||||
|
"after": {
|
||||||
|
"en": "Scan this code to open this location on another device",
|
||||||
|
"nl": "Scan deze code om deze locatie op een ander apparaat te zien"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "share",
|
||||||
|
"labels": ["added_by_default"],
|
||||||
|
"metacondition": "_supports_sharing=yes",
|
||||||
|
"render": {
|
||||||
|
"special": {
|
||||||
|
"type": "share_link",
|
||||||
|
"text": {
|
||||||
|
"en": "Share this location",
|
||||||
|
"nl": "Deel deze locatie"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1248,10 +1248,6 @@ video {
|
||||||
width: 16rem;
|
width: 16rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.w-14 {
|
|
||||||
width: 3.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.w-auto {
|
.w-auto {
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
|
|
|
@ -601,6 +601,7 @@ export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
|
||||||
}
|
}
|
||||||
json = { ...json }
|
json = { ...json }
|
||||||
json.tagRenderings = [...(json.tagRenderings ?? [])]
|
json.tagRenderings = [...(json.tagRenderings ?? [])]
|
||||||
|
const allIds = new Set<string>(json.tagRenderings.map((tr) => tr["id"]))
|
||||||
const specialVisualisations = ValidationUtils.getAllSpecialVisualisations(
|
const specialVisualisations = ValidationUtils.getAllSpecialVisualisations(
|
||||||
<any>json.tagRenderings
|
<any>json.tagRenderings
|
||||||
)
|
)
|
||||||
|
@ -658,11 +659,12 @@ export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!usedSpecialFunctions.has("qr_code")) {
|
if (!allIds.has("qr_code")) {
|
||||||
json.tagRenderings.push({
|
json.tagRenderings.push(this._desugaring.tagRenderings.get("qr_code"))
|
||||||
id: "qr_code",
|
}
|
||||||
render: { "*": "{qr_code()}" },
|
|
||||||
})
|
if (!allIds.has("share")) {
|
||||||
|
json.tagRenderings.push(this._desugaring.tagRenderings.get("share"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!usedSpecialFunctions.has("all_tags")) {
|
if (!usedSpecialFunctions.has("all_tags")) {
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import ToSvelte from "./ToSvelte.svelte"
|
|
||||||
import Svg from "../../Svg"
|
|
||||||
import Share from "../../assets/svg/Share.svelte"
|
import Share from "../../assets/svg/Share.svelte"
|
||||||
import { ariaLabel } from "../../Utils/ariaLabel"
|
import { ariaLabel } from "../../Utils/ariaLabel"
|
||||||
import Translations from "../i18n/Translations"
|
import Translations from "../i18n/Translations"
|
||||||
|
@ -10,6 +8,9 @@
|
||||||
title: string
|
title: string
|
||||||
url: string
|
url: string
|
||||||
}
|
}
|
||||||
|
export let text: string
|
||||||
|
let isIcon = text === undefined || text === ""
|
||||||
|
|
||||||
function share() {
|
function share() {
|
||||||
if (!navigator.share) {
|
if (!navigator.share) {
|
||||||
console.log("web share not supported")
|
console.log("web share not supported")
|
||||||
|
@ -26,8 +27,16 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button on:click={share} class="soft no-image-background m-0 h-8 w-8 p-0" use:ariaLabel={Translations.t.general.share}>
|
{#if isIcon}
|
||||||
<slot name="content">
|
<button on:click={share} class="soft no-image-background m-0 h-8 w-8 p-0"
|
||||||
<Share class="h-7 w-7 p-1" />
|
use:ariaLabel={Translations.t.general.share}>
|
||||||
</slot>
|
<slot name="content">
|
||||||
</button>
|
<Share class="h-7 w-7 p-1" />
|
||||||
|
</slot>
|
||||||
|
</button>
|
||||||
|
{:else}
|
||||||
|
<button on:click={share}>
|
||||||
|
<Share class="h-8 w-8 pr-2" />
|
||||||
|
{text}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
|
|
@ -14,6 +14,10 @@ export class ShareLinkViz implements SpecialVisualization {
|
||||||
name: "url",
|
name: "url",
|
||||||
doc: "The url to share (default: current URL)",
|
doc: "The url to share (default: current URL)",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "text",
|
||||||
|
doc: "The text to show on the button. If none is given, will act as a titleIcon",
|
||||||
|
},
|
||||||
]
|
]
|
||||||
needsUrls = []
|
needsUrls = []
|
||||||
|
|
||||||
|
@ -22,6 +26,8 @@ export class ShareLinkViz implements SpecialVisualization {
|
||||||
tagSource: UIEventSource<Record<string, string>>,
|
tagSource: UIEventSource<Record<string, string>>,
|
||||||
args: string[]
|
args: string[]
|
||||||
) {
|
) {
|
||||||
|
const text = args[1]
|
||||||
|
|
||||||
const generateShareData = () => {
|
const generateShareData = () => {
|
||||||
const title = state?.layout?.title?.txt ?? "MapComplete"
|
const title = state?.layout?.title?.txt ?? "MapComplete"
|
||||||
|
|
||||||
|
@ -46,6 +52,6 @@ export class ShareLinkViz implements SpecialVisualization {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SvelteUIElement(ShareButton, { generateShareData })
|
return new SvelteUIElement(ShareButton, { generateShareData, text })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1578,8 +1578,15 @@ export default class SpecialVisualizations {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
const [lon, lat] = GeoOperations.centerpointCoordinates(feature)
|
const [lon, lat] = GeoOperations.centerpointCoordinates(feature)
|
||||||
|
const includeLayout = window.location.pathname
|
||||||
|
.split("/")
|
||||||
|
.at(-1)
|
||||||
|
.startsWith("theme")
|
||||||
|
const layout = includeLayout
|
||||||
|
? "layout=" + state.layout.id + "&"
|
||||||
|
: ""
|
||||||
const url =
|
const url =
|
||||||
`${window.location.protocol}//${window.location.host}${window.location.pathname}?lat=${lat}&lon=${lon}&z=15` +
|
`${window.location.protocol}//${window.location.host}${window.location.pathname}?${layout}lat=${lat}&lon=${lon}&z=15` +
|
||||||
`#${id}`
|
`#${id}`
|
||||||
return new Img(new Qr(url).toImageElement(75)).SetStyle(
|
return new Img(new Qr(url).toImageElement(75)).SetStyle(
|
||||||
"width: 75px"
|
"width: 75px"
|
||||||
|
|
Loading…
Reference in a new issue