@open-commune/web 0.2.6 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,6 +36,20 @@
36
36
  </div>
37
37
  </transition>
38
38
  </div>
39
+ <p
40
+ v-if="isMissingCoordinates"
41
+ class="mt-2 flex flex-wrap items-center gap-x-2 rounded-md bg-amber-50 px-3 py-2 text-sm text-amber-800"
42
+ role="status"
43
+ >
44
+ <span>Cette adresse n'est pas géolocalisée : la carte du site ne peut pas la situer. Choisissez-la dans les suggestions.</span>
45
+ <button
46
+ type="button"
47
+ class="font-medium underline"
48
+ @click="_suggestFromAddress"
49
+ >
50
+ Voir les suggestions
51
+ </button>
52
+ </p>
39
53
  <div class="w-full mt-2 border border-gray-200 rounded-md" style="min-height: 18rem;">
40
54
  <div id="map" class="w-full h-full" style="min-height: 18rem;" />
41
55
  </div>
@@ -47,6 +61,7 @@ import { onClickOutside, useDebounceFn } from '@vueuse/core'
47
61
  import axios from 'axios'
48
62
  import mapbox, { Map, Marker } from 'mapbox-gl'
49
63
  import inputText from '~/components/forms/inputs/input-text'
64
+ import { FALLBACK_CENTER, FALLBACK_ZOOM, LOCATION_ZOOM, toLngLat } from '~/utils/location'
50
65
 
51
66
  // Prepare composable
52
67
  const $config = useRuntimeConfig()
@@ -89,6 +104,8 @@ const isLoading = ref(false)
89
104
 
90
105
  // Prepare computed
91
106
  const places = computed(() => list.value.map(({ id, place_name_fr: place, center }) => ({ id, place, center })))
107
+ const lngLat = computed(() => toLngLat(selection.value?.coordinates))
108
+ const isMissingCoordinates = computed(() => !!selection.value?.address && !lngLat.value)
92
109
 
93
110
  // Prepare methods
94
111
  const _createMap = () => {
@@ -96,27 +113,33 @@ const _createMap = () => {
96
113
  map.value = new Map({
97
114
  container: 'map',
98
115
  style: 'mapbox://styles/mapbox/light-v11?optimized=true',
99
- zoom: 13,
100
- center: selection.value?.coordinates,
116
+ // Without a position, Mapbox would centre on [0, 0], the open ocean.
117
+ zoom: lngLat.value ? LOCATION_ZOOM : FALLBACK_ZOOM,
118
+ center: lngLat.value || FALLBACK_CENTER,
101
119
  attributionControl: false,
102
120
  interactive: true
103
121
  })
104
122
  map.value.on('load', _updateMarker)
105
123
  }
106
124
  const _updateMarker = () => {
107
- if (selection.value?.coordinates?.length) {
125
+ if (!map.value) {
126
+ return
127
+ }
128
+ marker.value?.remove()
129
+ marker.value = undefined
130
+ if (lngLat.value) {
108
131
  marker.value = new Marker({ color: '#000' })
109
- .setLngLat(selection.value?.coordinates)
132
+ .setLngLat(lngLat.value)
110
133
  .addTo(map.value)
111
- map.value.flyTo({ center: selection.value.coordinates })
134
+ map.value.flyTo({ center: lngLat.value, zoom: LOCATION_ZOOM })
112
135
  }
113
136
  }
114
- const _findLocation = useDebounceFn(async () => {
115
- if (!isLoading.value && search.value) {
137
+ const _findLocation = useDebounceFn(async (query = search.value) => {
138
+ if (!isLoading.value && query) {
116
139
  isLoading.value = true
117
140
  try {
118
141
  const { data: { features } } = await MAPBOX_CLIENT.get(
119
- `/${search.value}.json?access_token=${$config.public.mapBoxToken}&types=postcode,district,place,locality,neighborhood,address,poi&autocomplete=true&country=fr&language=fr`
142
+ `/${encodeURIComponent(query)}.json?access_token=${$config.public.mapBoxToken}&types=postcode,district,place,locality,neighborhood,address,poi&autocomplete=true&country=fr&language=fr`
120
143
  )
121
144
  list.value = [...features]
122
145
  } catch (err) {
@@ -127,7 +150,8 @@ const _findLocation = useDebounceFn(async () => {
127
150
  }
128
151
  }, 300)
129
152
  const _select = (id) => {
130
- const { place_name_fr: address, center: coordinates } = list.value.find(({ id: check }) => check === id) || {}
153
+ const { place_name_fr: address, center } = list.value.find(({ id: check }) => check === id) || {}
154
+ const coordinates = toLngLat(center)
131
155
  if (address && coordinates) {
132
156
  selection.value = {
133
157
  address,
@@ -141,6 +165,11 @@ const _select = (id) => {
141
165
  const _toggle = () => {
142
166
  display.value = !display.value
143
167
  }
168
+ // Geocodes the stored address so a legacy, never-geocoded value can be fixed in one click.
169
+ const _suggestFromAddress = () => {
170
+ display.value = true
171
+ _findLocation(selection.value.address)
172
+ }
144
173
  const _close = () => {
145
174
  search.value = ''
146
175
  display.value = false
@@ -163,10 +192,14 @@ watch(
163
192
  watch(
164
193
  () => $props.value,
165
194
  (newValue) => {
166
- if (newValue.address && newValue.coordinates) {
195
+ // Keep an address without coordinates too: the field shows it and says it is not on the map.
196
+ if (newValue?.address) {
167
197
  selection.value = {
168
198
  address: newValue.address,
169
- coordinates: newValue.coordinates,
199
+ coordinates: newValue.coordinates || [],
200
+ }
201
+ if (map.value?.loaded()) {
202
+ _updateMarker()
170
203
  }
171
204
  }
172
205
  },
package/package.json CHANGED
@@ -16,14 +16,14 @@
16
16
  "@casl/ability": "^7.0.2",
17
17
  "@iconify/vue": "^5.0.3",
18
18
  "@nuxt/kit": "^4.6.1",
19
- "@nuxt/ui": "^4.3.0",
20
- "@open-commune/core": "^0.2.0",
21
- "@open-commune/editor": "^0.1.5",
19
+ "@nuxt/ui": "^4.12.0",
20
+ "@open-commune/core": "^0.2.12",
21
+ "@open-commune/editor": "^0.2.12",
22
22
  "@pinia-orm/nuxt": "^2.0.0",
23
23
  "@pinia/nuxt": "^1.0.3",
24
24
  "@tanstack/vue-query": "^5.104.3",
25
- "@tiptap/pm": "^3.27.3",
26
- "@tiptap/vue-3": "^3.27.3",
25
+ "@tiptap/pm": "^3.32.0",
26
+ "@tiptap/vue-3": "^3.32.0",
27
27
  "@trpc/client": "^11.19.0",
28
28
  "@trpc/server": "^11.19.0",
29
29
  "@vueuse/core": "^15.0.0",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "description": "The Open Commune application: the admin interface and the server, on a single origin.",
42
42
  "license": "AGPL-3.0-or-later",
43
- "version": "0.2.6",
43
+ "version": "0.2.12",
44
44
  "type": "module",
45
45
  "main": "./nuxt.config.ts",
46
46
  "files": [