-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
200 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<script setup lang="ts"> | ||
/* eslint-disable vue/prop-name-casing */ | ||
import { pickBy } from 'lodash' | ||
import type { ContribFields, Link } from '~/middleware/contrib-mode.global' | ||
import ExternalLink from '~/components/UI/ExternalLink.vue' | ||
const props = defineProps<{ | ||
editor_id: ContribFields['editor_id'] | ||
mapillary_link: ContribFields['mapillary_link'] | ||
osm_note: ContribFields['osm_note'] | ||
}>() | ||
const onlyDefinedProps = computed(() => { | ||
return pickBy(props, p => !!p) | ||
}) as ComputedRef<Record<string, Link>> | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<ExternalLink | ||
v-for="(field, key, index) in onlyDefinedProps" | ||
:key="key" | ||
:class="{ 'mt-2': index > 0 }" | ||
:icon="field.icon" | ||
:href="field.url" | ||
> | ||
{{ $t(`fields.contrib.${key}`) }} | ||
</ExternalLink> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
div { | ||
margin: 1rem 0; | ||
} | ||
@media print { | ||
div { | ||
display: none; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { ApiPoi, ApiPoiProperties } from '~/lib/apiPois' | ||
import { STORE_NAME, useContribStore } from '~/stores/contrib' | ||
|
||
export interface Link { | ||
icon: string | ||
url: string | ||
} | ||
|
||
export interface ContribFields { | ||
editor_id: Link | ||
mapillary_link?: Link | ||
osm_note: Link | ||
} | ||
|
||
export default defineNuxtRouteMiddleware((to) => { | ||
if (process.server) | ||
return | ||
|
||
if (process.client) { | ||
const { setEnabled } = useContribStore() | ||
const contribLocalStorage = localStorage.getItem(STORE_NAME) | ||
|
||
if (to.query.contrib !== undefined) { | ||
setEnabled(to.query.contrib === 'true') | ||
return | ||
} | ||
|
||
if (contribLocalStorage) | ||
setEnabled(contribLocalStorage === 'true') | ||
} | ||
}) | ||
|
||
export function getContributorFields(feature: ApiPoi): ContribFields { | ||
const { mapillary } = feature.properties | ||
const { osm_id, osm_type } = feature.properties.metadata | ||
const { coordinates } = feature.geometry as GeoJSON.Point | ||
|
||
return { | ||
editor_id: { | ||
icon: 'pen-to-square', | ||
url: `https://www.openstreetmap.org/edit?${osm_type}=${osm_id}`, | ||
}, | ||
mapillary_link: mapillary | ||
? { | ||
icon: 'external-link-alt', | ||
url: `https://www.mapillary.com/app/?pKey=${mapillary}&focus=photo`, | ||
} | ||
: undefined, | ||
osm_note: { | ||
icon: 'note-sticky', | ||
url: `https://www.openstreetmap.org/note/new#map=19/${coordinates[1]}/${coordinates[0]}&layers=N`, | ||
}, | ||
} | ||
} | ||
|
||
export function isContribEligible(properties: ApiPoiProperties): boolean { | ||
return !!(properties.metadata.osm_id && properties.metadata.osm_type && properties.editorial) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { mapState } from 'pinia' | ||
import type { ApiPoi, ApiPoiProperties } from '~/lib/apiPois' | ||
import { useContribStore } from '~/stores/contrib' | ||
import type { ContribFields } from '~/middleware/contrib-mode.global' | ||
import { getContributorFields, isContribEligible } from '~/middleware/contrib-mode.global' | ||
import ContribFieldGroup from '~/components/Fields/ContribFieldGroup.vue' | ||
|
||
export default { | ||
components: { | ||
ContribFieldGroup, | ||
}, | ||
computed: { | ||
...mapState(useContribStore, { | ||
contribMode: 'enabled', | ||
}), | ||
}, | ||
methods: { | ||
isContribEligible(properties: ApiPoiProperties): boolean { | ||
return isContribEligible(properties) | ||
}, | ||
getContributorFields(feature: ApiPoi): ContribFields { | ||
return getContributorFields(feature) | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { defineStore } from 'pinia' | ||
|
||
export const STORE_NAME = 'contrib' | ||
|
||
interface State { | ||
enabled: boolean | ||
} | ||
|
||
export const useContribStore = defineStore(STORE_NAME, { | ||
state: (): State => ({ | ||
enabled: false, | ||
}), | ||
actions: { | ||
setEnabled(state: boolean) { | ||
this.enabled = state | ||
localStorage.setItem(STORE_NAME, JSON.stringify(state)) | ||
}, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters