Skip to content

Commit 89b1ea6

Browse files
Antreesybackportbot[bot]
authored andcommitted
refactor(LocationCard): migrate to script setup
refactor(LocationCard): migrate to script setup Assisted-by: ClaudeCode:claude-sonnet-5 Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com> [skip ci]
1 parent 1432652 commit 89b1ea6

3 files changed

Lines changed: 68 additions & 8 deletions

File tree

src/components/MessagesList/MessagesGroup/Message/MessageItem.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ describe('MessageItem.vue', () => {
400400
'geo-location': {
401401
id: '123',
402402
name: 'Location name',
403-
latitude: 12.345678,
404-
longitude: 98.765432,
403+
latitude: '12.345678',
404+
longitude: '98.765432',
405405
metadata: '{id:123}',
406406
type: 'geo-location',
407407
},

src/components/MessagesList/MessagesGroup/Message/MessagePart/LocationCard.vue

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,69 @@
33
- SPDX-License-Identifier: AGPL-3.0-or-later
44
-->
55

6+
<script setup lang="ts">
7+
import { t } from '@nextcloud/l10n'
8+
import { imagePath } from '@nextcloud/router'
9+
import {
10+
LControlAttribution,
11+
LIcon,
12+
LMap,
13+
LMarker,
14+
LTileLayer,
15+
} from '@vue-leaflet/vue-leaflet'
16+
import { computed } from 'vue'
17+
18+
// Leaflet icon patch | re-uses images from ~leaflet package
19+
import 'leaflet/dist/leaflet.css'
20+
import 'leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.webpack.css'
21+
import 'leaflet-defaulticon-compatibility'
22+
23+
const props = withDefaults(defineProps<{
24+
/** The latitude of the location */
25+
latitude: string
26+
/** The longitude of the location */
27+
longitude: string
28+
/** The name of the location */
29+
name?: string
30+
/** The component appearance (take full width) */
31+
wide?: boolean
32+
}>(), {
33+
name: '',
34+
})
35+
36+
// {s} subdomains are used by ~leaflet package instead of the policy-preferred 'tile.openstreetmap.org' host
37+
const url = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
38+
// The zoom level of the map in the Talk app (chat, shared items tab)
39+
const previewZoom = 13
40+
// The zoom level of the map in the new OpenStreetMap tab upon opening the link
41+
const linkZoom = 18
42+
43+
// Map preview is non-interactive
44+
// Attribution control from ~leaflet package is replaced with LControlAttribution
45+
const mapOptions = {
46+
scrollWheelZoom: false,
47+
zoomControl: false,
48+
dragging: false,
49+
attributionControl: false,
50+
}
51+
// Visible attribution is required by the OpenStreetMap tile usage policy (https://operations.osmfoundation.org/policies/tiles/)
52+
const attribution = '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
53+
54+
// HTTP Referer header is required by the OpenStreetMap tile usage policy (https://operations.osmfoundation.org/policies/tiles/)
55+
const tileLayerOptions = {
56+
referrerPolicy: 'strict-origin-when-cross-origin',
57+
}
58+
59+
const linkAriaLabel = t('spreed', 'Open this location in OpenStreetMap')
60+
const iconUrl = imagePath('spreed', 'icon-marker-openstreetmap.svg')
61+
62+
const center = computed(() => [Number(props.latitude), Number(props.longitude)])
63+
const mapLink = computed(() => 'https://www.openstreetmap.org/'
64+
+ `?mlat=${props.latitude}`
65+
+ `&mlon=${props.longitude}`
66+
+ `#map=${linkZoom}/${props.latitude}/${props.longitude}`)
67+
</script>
68+
669
<template>
770
<a
871
:href="mapLink"
@@ -14,12 +77,7 @@
1477
<LMap
1578
:zoom="previewZoom"
1679
:center="center"
17-
:options="{
18-
scrollWheelZoom: false,
19-
zoomControl: false,
20-
dragging: false,
21-
attributionControl: false,
22-
}"
80+
:options="mapOptions"
2381
@scroll.prevent="">
2482
<LTileLayer
2583
:url="url"

src/env.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ declare global {
3636
export default content
3737
}
3838

39+
declare module '*.css'
40+
3941
// @nextcloud/webpack-vue-config build globals
4042
const appName: string
4143
const appVersion: string

0 commit comments

Comments
 (0)