2023-09-28 23:50:27 +02:00
|
|
|
<script lang="ts">
|
2023-12-19 22:08:00 +01:00
|
|
|
/**
|
|
|
|
* Shows an 'upload'-button which will start the upload for this feature
|
|
|
|
*/
|
2023-09-25 02:13:24 +02:00
|
|
|
|
2023-12-19 22:08:00 +01:00
|
|
|
import type { SpecialVisualizationState } from "../SpecialVisualization"
|
2023-12-19 23:02:02 +01:00
|
|
|
import { ImmutableStore, UIEventSource } from "../../Logic/UIEventSource"
|
2024-09-28 12:01:10 +02:00
|
|
|
import type { OsmId, OsmTags } from "../../Models/OsmFeature"
|
2023-12-19 22:08:00 +01:00
|
|
|
import LoginToggle from "../Base/LoginToggle.svelte"
|
|
|
|
import Translations from "../i18n/Translations"
|
|
|
|
import Tr from "../Base/Tr.svelte"
|
|
|
|
import UploadingImageCounter from "./UploadingImageCounter.svelte"
|
|
|
|
import FileSelector from "../Base/FileSelector.svelte"
|
|
|
|
import LoginButton from "../Base/LoginButton.svelte"
|
2024-05-28 01:25:43 +02:00
|
|
|
import { Translation } from "../i18n/Translation"
|
2024-06-18 03:33:11 +02:00
|
|
|
import Camera from "@babeard/svelte-heroicons/solid/Camera"
|
2024-09-28 02:44:03 +02:00
|
|
|
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
|
|
|
import NoteCommentElement from "../Popup/Notes/NoteCommentElement"
|
2023-09-25 02:13:24 +02:00
|
|
|
|
2023-12-19 22:08:00 +01:00
|
|
|
export let state: SpecialVisualizationState
|
2023-09-25 02:13:24 +02:00
|
|
|
|
2023-12-19 23:02:02 +01:00
|
|
|
export let tags: UIEventSource<OsmTags>
|
2023-12-19 22:08:00 +01:00
|
|
|
export let targetKey: string = undefined
|
2024-09-28 02:44:03 +02:00
|
|
|
export let layer: LayerConfig
|
2023-12-19 22:08:00 +01:00
|
|
|
/**
|
|
|
|
* Image to show in the button
|
|
|
|
* NOT the image to upload!
|
|
|
|
*/
|
|
|
|
export let image: string = undefined
|
|
|
|
if (image === "") {
|
|
|
|
image = undefined
|
|
|
|
}
|
|
|
|
export let labelText: string = undefined
|
|
|
|
const t = Translations.t.image
|
2023-09-25 02:13:24 +02:00
|
|
|
|
2024-05-28 01:25:43 +02:00
|
|
|
let errors = new UIEventSource<Translation[]>([])
|
|
|
|
|
2024-09-28 02:44:03 +02:00
|
|
|
async function handleFiles(files: FileList) {
|
2024-05-28 01:25:43 +02:00
|
|
|
const errs = []
|
2023-12-19 22:08:00 +01:00
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
|
|
const file = files.item(i)
|
|
|
|
console.log("Got file", file.name)
|
|
|
|
try {
|
2024-05-28 01:25:43 +02:00
|
|
|
const canBeUploaded = state?.imageUploadManager?.canBeUploaded(file)
|
|
|
|
if (canBeUploaded !== true) {
|
|
|
|
errs.push(canBeUploaded.error)
|
|
|
|
continue
|
|
|
|
}
|
2024-09-28 02:44:03 +02:00
|
|
|
|
2024-09-28 12:01:10 +02:00
|
|
|
if(layer?.id === "note"){
|
|
|
|
const uploadResult = await state?.imageUploadManager.uploadImageWithLicense(tags.data.id,
|
|
|
|
state.osmConnection.userDetails.data?.name ?? "Anonymous",
|
|
|
|
file, "image")
|
2024-09-28 02:44:03 +02:00
|
|
|
if(!uploadResult){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const url = uploadResult.absoluteUrl
|
2024-09-28 12:01:10 +02:00
|
|
|
await state.osmConnection.addCommentToNote(tags.data.id, url)
|
2024-09-28 02:44:03 +02:00
|
|
|
NoteCommentElement.addCommentTo(url, <UIEventSource<any>>tags, {
|
2024-09-28 12:01:10 +02:00
|
|
|
osmConnection: state.osmConnection,
|
2024-09-28 02:44:03 +02:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
await state?.imageUploadManager.uploadImageAndApply(file, tags, targetKey)
|
2023-12-19 22:08:00 +01:00
|
|
|
} catch (e) {
|
2024-09-28 12:01:10 +02:00
|
|
|
console.error(e)
|
|
|
|
state.reportError(e, "Could not upload image")
|
2023-12-19 22:08:00 +01:00
|
|
|
}
|
2023-09-25 02:13:24 +02:00
|
|
|
}
|
2024-05-28 01:25:43 +02:00
|
|
|
errors.setData(errs)
|
2023-12-19 22:08:00 +01:00
|
|
|
}
|
2023-09-25 02:13:24 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<LoginToggle {state}>
|
2023-12-19 23:02:02 +01:00
|
|
|
<LoginButton clss="small w-full" osmConnection={state.osmConnection} slot="not-logged-in">
|
2023-12-04 15:02:42 +01:00
|
|
|
<Tr t={Translations.t.image.pleaseLogin} />
|
|
|
|
</LoginButton>
|
2024-06-24 13:11:35 +02:00
|
|
|
<div class="my-4 flex flex-col">
|
2023-09-25 02:13:24 +02:00
|
|
|
<UploadingImageCounter {state} {tags} />
|
2024-05-28 01:25:43 +02:00
|
|
|
{#each $errors as error}
|
|
|
|
<Tr t={error} cls="alert" />
|
|
|
|
{/each}
|
2023-09-28 23:50:27 +02:00
|
|
|
<FileSelector
|
|
|
|
accept="image/*"
|
2024-10-02 00:18:32 +02:00
|
|
|
cls="button border-2 flex flex-col"
|
2023-09-28 23:50:27 +02:00
|
|
|
multiple={true}
|
|
|
|
on:submit={(e) => handleFiles(e.detail)}
|
|
|
|
>
|
2024-10-02 00:18:32 +02:00
|
|
|
<div class="flex items-center text-2xl w-full justify-center">
|
2023-09-25 02:13:24 +02:00
|
|
|
{#if image !== undefined}
|
2023-12-06 17:27:30 +01:00
|
|
|
<img src={image} aria-hidden="true" />
|
2023-09-25 02:13:24 +02:00
|
|
|
{:else}
|
2024-06-18 03:33:11 +02:00
|
|
|
<Camera class="h-12 w-12 p-1" aria-hidden="true" />
|
2023-09-25 02:13:24 +02:00
|
|
|
{/if}
|
|
|
|
{#if labelText}
|
|
|
|
{labelText}
|
|
|
|
{:else}
|
|
|
|
<Tr t={t.addPicture} />
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
</FileSelector>
|
2024-10-02 00:18:32 +02:00
|
|
|
<div class="text-xs subtle italic">
|
|
|
|
<Tr t={Translations.t.general.attribution.panoramaxLicenseCCBYSA}/>
|
|
|
|
<span class="mx-1">—</span>
|
|
|
|
<Tr t={t.respectPrivacy} />
|
2023-09-25 02:13:24 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</LoginToggle>
|