| 
									
										
										
										
											2023-09-28 23:50:27 +02:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-12-04 15:02:42 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Shows an 'upload'-button which will start the upload for this feature | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-09-25 02:13:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-04 15:02:42 +01:00
										 |  |  |     import type { SpecialVisualizationState } from "../SpecialVisualization" | 
					
						
							|  |  |  |     import { ImmutableStore, Store } from "../../Logic/UIEventSource" | 
					
						
							|  |  |  |     import type { OsmTags } from "../../Models/OsmFeature" | 
					
						
							|  |  |  |     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 Camera_plus from "../../assets/svg/Camera_plus.svelte" | 
					
						
							|  |  |  |     import LoginButton from "../Base/LoginButton.svelte" | 
					
						
							| 
									
										
										
										
											2023-09-25 02:13:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-04 15:02:42 +01:00
										 |  |  |     export let state: SpecialVisualizationState | 
					
						
							| 
									
										
										
										
											2023-09-25 02:13:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-04 15:02:42 +01:00
										 |  |  |     export let tags: Store<OsmTags> | 
					
						
							|  |  |  |     export let targetKey: string = undefined | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-04 15:02:42 +01:00
										 |  |  |     let licenseStore = state?.userRelatedState?.imageLicense ?? new ImmutableStore("CC0") | 
					
						
							| 
									
										
										
										
											2023-09-25 02:13:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-04 15:02:42 +01:00
										 |  |  |     function handleFiles(files: FileList) { | 
					
						
							|  |  |  |         for (let i = 0; i < files.length; i++) { | 
					
						
							|  |  |  |             const file = files.item(i) | 
					
						
							|  |  |  |             console.log("Got file", file.name) | 
					
						
							|  |  |  |             try { | 
					
						
							|  |  |  |                 state?.imageUploadManager.uploadImageAndApply(file, tags, targetKey) | 
					
						
							|  |  |  |             } catch (e) { | 
					
						
							|  |  |  |                 alert(e) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-09-25 02:13:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <LoginToggle {state}> | 
					
						
							| 
									
										
										
										
											2023-12-04 15:02:42 +01:00
										 |  |  |   <LoginButton slot="not-logged-in" clss="small w-full"> | 
					
						
							|  |  |  |     <Tr t={Translations.t.image.pleaseLogin} /> | 
					
						
							|  |  |  |   </LoginButton> | 
					
						
							| 
									
										
										
										
											2023-09-25 02:13:24 +02:00
										 |  |  |   <div class="flex flex-col"> | 
					
						
							|  |  |  |     <UploadingImageCounter {state} {tags} /> | 
					
						
							| 
									
										
										
										
											2023-09-28 23:50:27 +02:00
										 |  |  |     <FileSelector | 
					
						
							|  |  |  |       accept="image/*" | 
					
						
							|  |  |  |       cls="button border-2 text-2xl" | 
					
						
							|  |  |  |       multiple={true} | 
					
						
							|  |  |  |       on:submit={(e) => handleFiles(e.detail)} | 
					
						
							|  |  |  |     > | 
					
						
							| 
									
										
										
										
											2023-12-06 17:27:30 +01:00
										 |  |  |       <div class="flex items-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} | 
					
						
							| 
									
										
										
										
											2023-12-01 15:23:28 +01:00
										 |  |  |           <Camera_plus class="block h-12 w-12 p-1 text-4xl" /> | 
					
						
							| 
									
										
										
										
											2023-09-25 02:13:24 +02:00
										 |  |  |         {/if} | 
					
						
							|  |  |  |         {#if labelText} | 
					
						
							|  |  |  |           {labelText} | 
					
						
							|  |  |  |         {:else} | 
					
						
							|  |  |  |           <Tr t={t.addPicture} /> | 
					
						
							|  |  |  |         {/if} | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     </FileSelector> | 
					
						
							|  |  |  |     <div class="text-sm"> | 
					
						
							| 
									
										
										
										
											2023-12-06 17:27:30 +01:00
										 |  |  |       <button | 
					
						
							|  |  |  |         class="link small " | 
					
						
							| 
									
										
										
										
											2023-09-28 23:50:27 +02:00
										 |  |  |         on:click={() => { | 
					
						
							|  |  |  |           state.guistate.openUsersettings("picture-license") | 
					
						
							|  |  |  |         }} | 
					
						
							|  |  |  |       > | 
					
						
							|  |  |  |         <Tr t={t.currentLicense.Subs({ license: $licenseStore })} /> | 
					
						
							| 
									
										
										
										
											2023-12-06 17:27:30 +01:00
										 |  |  |       </button> | 
					
						
							|  |  |  |         <Tr t={t.respectPrivacy} /> | 
					
						
							| 
									
										
										
										
											2023-09-25 02:13:24 +02:00
										 |  |  |     </div> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </LoginToggle> |