Compare commits
	
		
			28 Commits
		
	
	
		
			1.13.1
			...
			feature/cu
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 77413c7e53 | |||
| 72e5425c08 | |||
| 53f5fa3988 | |||
| 6ef6dc0078 | |||
| b89d4f248c | |||
| 444b1f5370 | |||
| 3709881176 | |||
| a00af08b3f | |||
| 9ef34359d8 | |||
| 4d79589903 | |||
| 1386b80d0c | |||
| 286bd61497 | |||
| 50b5e4e455 | |||
| 2c91f46375 | |||
| 0cb1193269 | |||
| 564a971c63 | |||
| 3842d8b104 | |||
| a827279163 | |||
| b0063cdead | |||
| 9298a0dc92 | |||
| b9e2e65331 | |||
| 27e7bbb9d1 | |||
| 2139b197ba | |||
| 4e1a944a2d | |||
| e3c6d5a5c0 | |||
| 8c3f0092d2 | |||
| 6fad04c862 | |||
| 838dcbfd7e | 
							
								
								
									
										16
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								CHANGELOG.md
									
									
									
									
									
								
							| @@ -2,8 +2,24 @@ | |||||||
|  |  | ||||||
| All notable changes to this project will be documented in this file. Dates are displayed in UTC. | All notable changes to this project will be documented in this file. Dates are displayed in UTC. | ||||||
|  |  | ||||||
|  | #### [1.13.3](https://git.odit.services/lfk/frontend/compare/1.13.2...1.13.3) | ||||||
|  |  | ||||||
|  | - Refactor code structure for improved readability and maintainability [`e3c6d5a`](https://git.odit.services/lfk/frontend/commit/e3c6d5a5c0eaac2c91432b0be37d6fa11e57f644) | ||||||
|  | - refactor(donation): Refactor donor selection and add new donor creation functionality [`8c3f009`](https://git.odit.services/lfk/frontend/commit/8c3f0092d2735b1c85976f4e6955780b1035f68a) | ||||||
|  | - fix(donation): Ensure all selections are cleared on reset [`4e1a944`](https://git.odit.services/lfk/frontend/commit/4e1a944a2d7d0d0666fb8d2181a9941d0f11957f) | ||||||
|  |  | ||||||
|  | #### [1.13.2](https://git.odit.services/lfk/frontend/compare/1.13.1...1.13.2) | ||||||
|  |  | ||||||
|  | > 16 May 2025 | ||||||
|  |  | ||||||
|  | - chore(release): 1.13.2 [`6fad04c`](https://git.odit.services/lfk/frontend/commit/6fad04c86249613dacfe2bc75362cb32d109573d) | ||||||
|  | - feat(dashboard): Add permission checks for scan and donation creation links [`838dcbf`](https://git.odit.services/lfk/frontend/commit/838dcbfd7e0c09e8cf61a04952475934ad1e3b86) | ||||||
|  |  | ||||||
| #### [1.13.1](https://git.odit.services/lfk/frontend/compare/1.13.0...1.13.1) | #### [1.13.1](https://git.odit.services/lfk/frontend/compare/1.13.0...1.13.1) | ||||||
|  |  | ||||||
|  | > 16 May 2025 | ||||||
|  |  | ||||||
|  | - chore(release): 1.13.1 [`f5df252`](https://git.odit.services/lfk/frontend/commit/f5df252857f20f8426b8ca566b9bb3ec50331880) | ||||||
| - feat(tools): Remove unnecessary validation display in donation creation [`285fc91`](https://git.odit.services/lfk/frontend/commit/285fc91c66d03aaa861da549cb739c3698beb892) | - feat(tools): Remove unnecessary validation display in donation creation [`285fc91`](https://git.odit.services/lfk/frontend/commit/285fc91c66d03aaa861da549cb739c3698beb892) | ||||||
|  |  | ||||||
| #### [1.13.0](https://git.odit.services/lfk/frontend/compare/1.12.8...1.13.0) | #### [1.13.0](https://git.odit.services/lfk/frontend/compare/1.12.8...1.13.0) | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ | |||||||
|  |  | ||||||
|   <body> |   <body> | ||||||
|     <span style="display: none; visibility: hidden" id="buildinfo" |     <span style="display: none; visibility: hidden" id="buildinfo" | ||||||
|       >RELEASE_INFO-1.13.1-RELEASE_INFO</span |       >RELEASE_INFO-1.13.3-RELEASE_INFO</span | ||||||
|     > |     > | ||||||
|     <noscript>You need to enable JavaScript to run this app.</noscript> |     <noscript>You need to enable JavaScript to run this app.</noscript> | ||||||
|     <script src="/env.js"></script> |     <script src="/env.js"></script> | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "@odit/lfk-frontend", |   "name": "@odit/lfk-frontend", | ||||||
|   "version": "1.13.1", |   "version": "1.13.3", | ||||||
|   "type": "module", |   "type": "module", | ||||||
|   "scripts": { |   "scripts": { | ||||||
|     "i18n-order": "node order.js", |     "i18n-order": "node order.js", | ||||||
| @@ -52,7 +52,6 @@ | |||||||
|     "html5-qrcode": "^2.3.8", |     "html5-qrcode": "^2.3.8", | ||||||
|     "localforage": "1.10.0", |     "localforage": "1.10.0", | ||||||
|     "papaparse": "^5.5.2", |     "papaparse": "^5.5.2", | ||||||
|     "svelecte": "3", |  | ||||||
|     "svelte": "3.58.0", |     "svelte": "3.58.0", | ||||||
|     "svelte-french-toast": "1.2.0", |     "svelte-french-toast": "1.2.0", | ||||||
|     "svelte-i18n": "4.0.1", |     "svelte-i18n": "4.0.1", | ||||||
|   | |||||||
							
								
								
									
										15
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										15
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							| @@ -38,9 +38,6 @@ importers: | |||||||
|       papaparse: |       papaparse: | ||||||
|         specifier: ^5.5.2 |         specifier: ^5.5.2 | ||||||
|         version: 5.5.2 |         version: 5.5.2 | ||||||
|       svelecte: |  | ||||||
|         specifier: '3' |  | ||||||
|         version: 3.17.3 |  | ||||||
|       svelte: |       svelte: | ||||||
|         specifier: 3.58.0 |         specifier: 3.58.0 | ||||||
|         version: 3.58.0 |         version: 3.58.0 | ||||||
| @@ -1986,9 +1983,6 @@ packages: | |||||||
|     resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} |     resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} | ||||||
|     engines: {node: '>= 0.4'} |     engines: {node: '>= 0.4'} | ||||||
|  |  | ||||||
|   svelecte@3.17.3: |  | ||||||
|     resolution: {integrity: sha512-wnvoRxJIFFkm+CmXgjL4R3i/TcuYUIBkE+jDJSBD7AdSOzk1K6u3+nW4zwxaGT29zyZpiZkWeiy7lO62r5F+tg==} |  | ||||||
|  |  | ||||||
|   svelte-french-toast@1.2.0: |   svelte-french-toast@1.2.0: | ||||||
|     resolution: {integrity: sha512-5PW+6RFX3xQPbR44CngYAP1Sd9oCq9P2FOox4FZffzJuZI2mHOB7q5gJBVnOiLF5y3moVGZ7u2bYt7+yPAgcEQ==} |     resolution: {integrity: sha512-5PW+6RFX3xQPbR44CngYAP1Sd9oCq9P2FOox4FZffzJuZI2mHOB7q5gJBVnOiLF5y3moVGZ7u2bYt7+yPAgcEQ==} | ||||||
|     peerDependencies: |     peerDependencies: | ||||||
| @@ -2010,9 +2004,6 @@ packages: | |||||||
|   svelte-select@3.17.0: |   svelte-select@3.17.0: | ||||||
|     resolution: {integrity: sha512-ITmX/XUiSdkaILmsTviKRkZPaXckM5/FA7Y8BhiUPoamaZG/ZDyOo6ydjFu9fDVFTbwoAUGUi6HBjs+ZdK2AwA==} |     resolution: {integrity: sha512-ITmX/XUiSdkaILmsTviKRkZPaXckM5/FA7Y8BhiUPoamaZG/ZDyOo6ydjFu9fDVFTbwoAUGUi6HBjs+ZdK2AwA==} | ||||||
|  |  | ||||||
|   svelte-tiny-virtual-list@2.1.2: |  | ||||||
|     resolution: {integrity: sha512-jeP/WMvgFUR4mYXHGPiCexjX5DuzSO+3xzHNhxfcsFyy+uYPtnqI5UGb383swpzQAyXB0OBqYfzpYihD/5gxnA==} |  | ||||||
|  |  | ||||||
|   svelte-writable-derived@3.1.1: |   svelte-writable-derived@3.1.1: | ||||||
|     resolution: {integrity: sha512-w4LR6/bYZEuCs7SGr+M54oipk/UQKtiMadyOhW0PTwAtJ/Ai12QS77sLngEcfBx2q4H8ZBQucc9ktSA5sUGZWw==} |     resolution: {integrity: sha512-w4LR6/bYZEuCs7SGr+M54oipk/UQKtiMadyOhW0PTwAtJ/Ai12QS77sLngEcfBx2q4H8ZBQucc9ktSA5sUGZWw==} | ||||||
|     peerDependencies: |     peerDependencies: | ||||||
| @@ -3955,10 +3946,6 @@ snapshots: | |||||||
|  |  | ||||||
|   supports-preserve-symlinks-flag@1.0.0: {} |   supports-preserve-symlinks-flag@1.0.0: {} | ||||||
|  |  | ||||||
|   svelecte@3.17.3: |  | ||||||
|     dependencies: |  | ||||||
|       svelte-tiny-virtual-list: 2.1.2 |  | ||||||
|  |  | ||||||
|   svelte-french-toast@1.2.0(svelte@3.58.0): |   svelte-french-toast@1.2.0(svelte@3.58.0): | ||||||
|     dependencies: |     dependencies: | ||||||
|       svelte: 3.58.0 |       svelte: 3.58.0 | ||||||
| @@ -3981,8 +3968,6 @@ snapshots: | |||||||
|  |  | ||||||
|   svelte-select@3.17.0: {} |   svelte-select@3.17.0: {} | ||||||
|  |  | ||||||
|   svelte-tiny-virtual-list@2.1.2: {} |  | ||||||
|  |  | ||||||
|   svelte-writable-derived@3.1.1(svelte@3.58.0): |   svelte-writable-derived@3.1.1(svelte@3.58.0): | ||||||
|     dependencies: |     dependencies: | ||||||
|       svelte: 3.58.0 |       svelte: 3.58.0 | ||||||
|   | |||||||
| @@ -85,6 +85,8 @@ | |||||||
|  |  | ||||||
|           <span>{$_("card-replacement-menu")}</span> |           <span>{$_("card-replacement-menu")}</span> | ||||||
|         </a> |         </a> | ||||||
|  |         {/if} | ||||||
|  |       {#if store.state.jwtinfo.userdetails.permissions.includes("SCAN:CREATE")} | ||||||
|         <a |         <a | ||||||
|           class:activenav={$router.path.includes("/tools/scanclient/")} |           class:activenav={$router.path.includes("/tools/scanclient/")} | ||||||
|           class="flex items-center px-4 py-3 transition cursor-pointer group hover:bg-gray-200 hover:text-gray-900 w-full font-semibold" |           class="flex items-center px-4 py-3 transition cursor-pointer group hover:bg-gray-200 hover:text-gray-900 w-full font-semibold" | ||||||
| @@ -105,6 +107,8 @@ | |||||||
|  |  | ||||||
|           <span>{$_("scanclient")}</span> |           <span>{$_("scanclient")}</span> | ||||||
|         </a> |         </a> | ||||||
|  |         {/if} | ||||||
|  |         {#if store.state.jwtinfo.userdetails.permissions.includes("DONATION:CREATE")} | ||||||
|         <a |         <a | ||||||
|           class:activenav={$router.path.includes("/tools/donationcreate/")} |           class:activenav={$router.path.includes("/tools/donationcreate/")} | ||||||
|           class="flex items-center px-4 py-3 transition cursor-pointer group hover:bg-gray-200 hover:text-gray-900 w-full font-semibold" |           class="flex items-center px-4 py-3 transition cursor-pointer group hover:bg-gray-200 hover:text-gray-900 w-full font-semibold" | ||||||
| @@ -125,9 +129,11 @@ | |||||||
|  |  | ||||||
|           <span>{$_("donation-quick-add")}</span> |           <span>{$_("donation-quick-add")}</span> | ||||||
|         </a> |         </a> | ||||||
|  |         {/if} | ||||||
|         <h2 class="px-4 py-2 text-xs font-semibold text-gray-600 uppercase"> |         <h2 class="px-4 py-2 text-xs font-semibold text-gray-600 uppercase"> | ||||||
|           {$_("management")} |           {$_("management")} | ||||||
|         </h2> |         </h2> | ||||||
|  |         {#if store.state.jwtinfo.userdetails.permissions.includes("RUNNER:GET")} | ||||||
|         <a |         <a | ||||||
|           class:activenav={$router.path.includes("/runners/")} |           class:activenav={$router.path.includes("/runners/")} | ||||||
|           class="flex items-center px-4 py-3 transition cursor-pointer group hover:bg-gray-200 hover:text-gray-900 w-full font-semibold" |           class="flex items-center px-4 py-3 transition cursor-pointer group hover:bg-gray-200 hover:text-gray-900 w-full font-semibold" | ||||||
|   | |||||||
| @@ -1,296 +1,422 @@ | |||||||
| <script> | <script> | ||||||
|   import { _ } from "svelte-i18n"; | 	import { _ } from "svelte-i18n"; | ||||||
|   import { | 	import { | ||||||
|     DonationService, | 		DonationService, | ||||||
|     DonorService, | 		DonorService, | ||||||
|     RunnerService, | 		RunnerService, | ||||||
|   } from "@odit/lfk-client-js"; | 	} from "@odit/lfk-client-js"; | ||||||
|   import Svelecte from "svelecte"; | 	import toast from "svelte-french-toast"; | ||||||
|   import Select from "svelte-select"; | 	import VirtualSelect from "./VirtualSelect.svelte"; | ||||||
|   import toast from "svelte-french-toast"; | 	import { onMount } from "svelte"; | ||||||
|  |  | ||||||
|   let runners = []; | 	let runners = []; | ||||||
|   let donors = []; | 	let donors = []; | ||||||
|   let runnerinfo = { id: 0, firstname: "", lastname: "" }; | 	let runnerinfo = { id: 0, firstname: "", lastname: "" }; | ||||||
|   let donorinfo = { id: 0, firstname: "", lastname: "" }; | 	let donorinfo = { id: 0, firstname: "", lastname: "" }; | ||||||
|   let address = { | 	let address = { | ||||||
|     address1: "", | 		address1: "", | ||||||
|     address2: "", | 		address2: "", | ||||||
|     city: "", | 		city: "", | ||||||
|     postalcode: "", | 		postalcode: "", | ||||||
|     country: "Germany", | 		country: "Germany", | ||||||
|   }; | 	}; | ||||||
|   let amount = 0; | 	let amount = null; | ||||||
|   let lastname = ""; | 	let address_checked = false; | ||||||
|   let address_checked = false; | 	let donor_create_new = false; | ||||||
|  | 	let last_created = null; | ||||||
|  |  | ||||||
|   RunnerService.runnerControllerGetAll() | 	RunnerService.runnerControllerGetAll() | ||||||
|     .then((val) => { | 		.then((val) => { | ||||||
|       runners = val.map((r) => { | 			runners = val.map((r) => { | ||||||
|         return { label: getRunnerLabel(r), value: r }; | 				return { label: getRunnerLabel(r), value: r }; | ||||||
|       }); | 			}); | ||||||
|     }) | 		}) | ||||||
|     .catch((err) => { | 		.catch((err) => { | ||||||
|       console.log("error fetching runners:", err); | 			console.log("error fetching runners:", err); | ||||||
|     }); | 		}); | ||||||
|  |  | ||||||
|   function loadDonors() { | 	function loadDonors() { | ||||||
|     DonorService.donorControllerGetAll() | 		DonorService.donorControllerGetAll() | ||||||
|       .then((val) => { | 			.then((val) => { | ||||||
|         donors = val.map((r) => { | 				donors = val.map((r) => { | ||||||
|           return { label: getDonorlabel(r), value: r }; | 					return { label: getRunnerLabel(r), value: r }; | ||||||
|         }); | 				}); | ||||||
|         console.log("refreshed donors"); | 				console.log("refreshed donors"); | ||||||
|         setTimeout(() => { | 				setTimeout(() => { | ||||||
|           loadDonors; | 					loadDonors; | ||||||
|         }, 30000); | 				}, 30000); | ||||||
|       }) | 			}) | ||||||
|       .catch((err) => { | 			.catch((err) => { | ||||||
|         console.log("error fetching donors:", err); | 				console.log("error fetching donors:", err); | ||||||
|       }); | 			}); | ||||||
|   } | 	} | ||||||
|   loadDonors(); | 	loadDonors(); | ||||||
|  |  | ||||||
|   const getRunnerLabel = (option) => | 	const getRunnerLabel = (option) => { | ||||||
|     option.firstname + " " + (option.middlename || "") + " " + option.lastname; | 		return ( | ||||||
|  | 			[option.firstname, option.middlename, option.lastname] | ||||||
|  | 				.join(" ") | ||||||
|  | 				.replace("  ", " ") + | ||||||
|  | 			" [#" + | ||||||
|  | 			option.id + | ||||||
|  | 			"]" | ||||||
|  | 		); | ||||||
|  | 	}; | ||||||
|  |  | ||||||
|   const getDonorlabel = (option) => `${option.firstname} (${option.lastname})`; | 	let selectRefRunner; | ||||||
|  | 	let selectRefDonor; | ||||||
|  |  | ||||||
|   const filterRunners = (label, filterText, option) => { | 	function resetAll() { | ||||||
|     if (filterText.startsWith("#")) { | 		runnerinfo = { id: 0, firstname: "", lastname: "" }; | ||||||
|       return option.value.id == parseInt(filterText.replace("#", "")); | 		donorinfo = { id: 0, firstname: "", lastname: "" }; | ||||||
|     } | 		amount = null; | ||||||
|     return ( | 		address_checked = false; | ||||||
|       label.toLowerCase().includes(filterText.toLowerCase()) || | 		donor_create_new = false; | ||||||
|       option.value.toString().startsWith(filterText.toLowerCase()) | 		selectRefRunner?.reset(); | ||||||
|     ); | 		selectRefDonor?.reset(); | ||||||
|   }; | 		document.querySelector("#jjqzqicxujrnnh1x3447x18x").focus(); | ||||||
|  | 	} | ||||||
|   function resetAll() { | 	onMount(() => { | ||||||
|     runnerinfo = { id: 0, firstname: "", lastname: "" }; | 		document.querySelector("#jjqzqicxujrnnh1x3447x18x").focus(); | ||||||
|     donorinfo = { id: 0, firstname: "", lastname: "" }; | 	}); | ||||||
|     amount = 0; |  | ||||||
|   } |  | ||||||
| </script> | </script> | ||||||
|  |  | ||||||
| <div class="p-4"> | <div class="p-4"> | ||||||
|   <h3 class="text-3xl font-bold">{$_("fast_donation_create")}</h3> | 	<h3 class="text-3xl font-bold">{$_("fast_donation_create")}</h3> | ||||||
|   <!--  --> | 	<!--  --> | ||||||
|   <div class="grid grid-cols-6 gap-4"> | 	<div> | ||||||
|     <div class="col-span-2"> | 		<div class="w-full space-y-4 mb-6"> | ||||||
|       <h4 class="text-xl font-semibold"> | 			{#if last_created} | ||||||
|         {$_("runner")} | 				<div class="mt-4 p-3 bg-green-50 border border-green-200 rounded-md"> | ||||||
|       </h4> | 					<p class="text-black"> | ||||||
|       <Select | 						{$_("last-created-donation")}: #{last_created.id}: {last_created.amountPerDistance / | ||||||
|         containerClasses="rounded-l-md mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 border bg-gray-50 text-neutral-800 rounded-md p-2" | 							100}€ für {getRunnerLabel(last_created.runner)} von {getRunnerLabel( | ||||||
|         itemFilter={(label, filterText, option) => | 							last_created.donor | ||||||
|           filterRunners(label, filterText, option)} | 						)} | ||||||
|         items={runners} | 					</p> | ||||||
|         showChevron={true} | 				</div> | ||||||
|         placeholder={$_("search-for-runner-by-name-or-id")} | 			{/if} | ||||||
|         noOptionsMessage={$_("no-runners-found")} |  | ||||||
|         on:select={(selectedValue) => { | 			<!--  --> | ||||||
|           runnerinfo = selectedValue.detail.value; | 			<h4 class="text-xl font-semibold">{$_("runner")}</h4> | ||||||
|         }} | 			<VirtualSelect | ||||||
|         on:clear={() => (runnerinfo.runner = null)} | 				inputElementID="jjqzqicxujrnnh1x3447x18x" | ||||||
|       /> | 				bind:this={selectRefRunner} | ||||||
|     </div> | 				on:onClear={() => { | ||||||
|     <div class="col-span-2"> | 					console.log("Cleared selection"); | ||||||
|       <h4 class="text-xl font-semibold"> | 				}} | ||||||
|         {$_("donor")} | 				options={runners} | ||||||
|       </h4> | 				filterFn={(item, searchTerm) => { | ||||||
|       <div class="mb-2"> | 					if (searchTerm.startsWith("#")) { | ||||||
|         <Svelecte | 						const id = parseInt(searchTerm.replace("#", "")); | ||||||
|           name="donor_fistname" | 						return item.value.id === id; | ||||||
|           placeholder={$_("first-name")} | 					} | ||||||
|           clearable={true} | 					return item.label.toLowerCase().includes(searchTerm.toLowerCase()); | ||||||
|           options={donors} | 				}} | ||||||
|           keepCreated={false} | 				bind:selected={runnerinfo} | ||||||
|           creatable={true} | 				inputAriaLabel={$_("search-for-runner-by-name-or-id")} | ||||||
|           labelField="label" | 				inputPlaceholder={$_("search-for-runner-by-name-or-id")} | ||||||
|           on:change={(e) => { | 				noOptionsText={$_("no-runners-found")} | ||||||
|             if (!e.detail?.value) { | 				on:onSelected={(data) => { | ||||||
|               donorinfo = { id: 0, firstname: "", lastname: "" }; | 					if (data.detail !== null) { | ||||||
|               return; | 						document.querySelector("#donation_amount_eur").focus(); | ||||||
|             } | 					} | ||||||
|             if (!e.detail?.$created) { | 				}} | ||||||
|               donorinfo = e.detail.value; | 			/> | ||||||
|               lastname = e.detail.value.lastname; |  | ||||||
|             } else { | 			<!-- Amount Input --> | ||||||
|               console.log("created option", e); | 			<div> | ||||||
|               donorinfo.firstname = e.detail.value; | 				<h4 class="text-xl font-semibold">{$_("amount-per-kilometer")}</h4> | ||||||
|             } | 				<div class="mt-1 flex rounded-md shadow-sm"> | ||||||
|           }} | 					<input | ||||||
|           class="rounded-l-md mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 border bg-gray-50 text-neutral-800 rounded-md p-0.5" | 						autocomplete="off" | ||||||
|         /> | 						class:border-red-500={!amount > 0} | ||||||
|         <input | 						class:focus:border-red-500={!amount > 0} | ||||||
|           autocomplete="off" | 						class:focus:ring-red-500={!amount > 0} | ||||||
|           placeholder={$_("last-name")} | 						bind:value={amount} | ||||||
|           class:border-red-500={donorinfo.lastname?.length == 0} | 						on:keydown={(e) => { | ||||||
|           class:focus:border-red-500={donorinfo.lastname?.length == 0} | 							if (e.key === "Enter") { | ||||||
|           class:focus:ring-red-500={donorinfo.lastname?.length == 0} | 								e.preventDefault(); | ||||||
|           bind:value={lastname} | 								document.querySelector("#button_existing_donor").focus(); | ||||||
|           on:input={e => { | 							} | ||||||
|             donorinfo.lastname = e.target.value; | 						}} | ||||||
|           }} | 						type="number" | ||||||
|           type="text" | 						step="0.01" | ||||||
|           name="lastname" | 						id="donation_amount_eur" | ||||||
|           class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-neutral-800 rounded-md p-2" | 						name="donation_amount_eur" | ||||||
|         /> | 						class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | ||||||
|       </div> | 						placeholder="z.B. 1,50" | ||||||
|       <div class="flex items-start"> | 					/> | ||||||
|         <div class="flex items-center h-5"> | 					<span | ||||||
|           {#if donorinfo.id == 0} | 						class="inline-flex items-center px-3 rounded-r-md border border-neutral-300 bg-neutral-50 text-neutral-500 text-sm" | ||||||
|             <input | 						>€</span | ||||||
|               bind:checked={address_checked} | 					> | ||||||
|               id="comments" | 				</div> | ||||||
|               name="comments" | 			</div> | ||||||
|               type="checkbox" |  | ||||||
|               class="focus:ring-indigo-500 size-4 text-indigo-600 border-gray-300 rounded" | 			<!-- Donor Selection --> | ||||||
|             /> | 			<div> | ||||||
|           {:else} | 				<h4 class="text-xl font-semibold">{$_("donor")}</h4> | ||||||
|             <input |  | ||||||
|               checked={true} | 				<!-- Donor Type Toggle --> | ||||||
|               disabled | 				<div class="mb-2"> | ||||||
|               id="comments" | 					<div class="flex border rounded-md overflow-hidden shadow-sm"> | ||||||
|               name="comments" | 						<button | ||||||
|               type="checkbox" | 							on:keydown={(e) => { | ||||||
|               class="focus:ring-indigo-500 size-4 text-indigo-600 border-gray-300 rounded" | 								if (e.key === "ArrowRight") { | ||||||
|             /> | 									e.preventDefault(); | ||||||
|           {/if} | 									document.querySelector("#button_new_donor").focus(); | ||||||
|         </div> | 									document.querySelector("#button_new_donor").click(); | ||||||
|         <div class="ml-3 text-sm"> | 								} | ||||||
|           <label for="comments" class="font-semibold text-gray-700" | 								if (e.key === "Enter") { | ||||||
|             >{$_("receipt-needed")}</label | 									e.preventDefault(); | ||||||
|           > | 									document.querySelector("#zt12c3udy3bme5bqobmqcif1").focus(); | ||||||
|         </div> | 								} | ||||||
|       </div> | 							}} | ||||||
|       {#if address_checked} | 							id="button_existing_donor" | ||||||
|         <div class="col-span-6"> | 							class:bg-indigo-600={!donor_create_new} | ||||||
|           <label for="address1" class="block text-sm font-medium text-gray-700" | 							class:text-white={!donor_create_new} | ||||||
|             >{$_("address")}</label | 							class="py-2 px-4 w-1/2 transition-colors" | ||||||
|           > | 							on:click={() => { | ||||||
|           <input | 								donor_create_new = false; | ||||||
|             autocomplete="off" | 								donorinfo = { id: 0, firstname: "", lastname: "" }; | ||||||
|             placeholder="Address" | 							}} | ||||||
|             class:border-red-500={address.address1.length == 0} | 						> | ||||||
|             class:focus:border-red-500={address.address1.length == 0} | 							{$_("existing-donor")} | ||||||
|             class:focus:ring-red-500={address.address1.length == 0} | 						</button> | ||||||
|             bind:value={address.address1} | 						<button | ||||||
|             type="text" | 							on:keydown={(e) => { | ||||||
|             name="address1" | 								if (e.key === "ArrowLeft") { | ||||||
|             class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-neutral-800 rounded-md p-2" | 									e.preventDefault(); | ||||||
|           /> | 									document.querySelector("#button_existing_donor").focus(); | ||||||
|         </div> | 									document.querySelector("#button_existing_donor").click(); | ||||||
|         <div class="col-span-6"> | 								} | ||||||
|           <label for="address2" class="block text-sm font-medium text-gray-700" | 								if (e.key === "Enter") { | ||||||
|             >{$_("apartment-suite-etc")}</label | 									e.preventDefault(); | ||||||
|           > | 									document.querySelector("#button_new_donor").click(); | ||||||
|           <input | 								} | ||||||
|             autocomplete="off" | 							}} | ||||||
|             placeholder={$_("apartment-suite-etc")} | 							id="button_new_donor" | ||||||
|             bind:value={address.address2} | 							class={`py-2 px-4 w-1/2 transition-colors ${donor_create_new ? "bg-indigo-600 text-white" : "bg-gray-100 text-gray-700"}`} | ||||||
|             type="text" | 							on:click={() => { | ||||||
|             name="address2" | 								donor_create_new = true; | ||||||
|             class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-neutral-800 rounded-md p-2" | 								donorinfo = { id: 0, firstname: "", lastname: "" }; | ||||||
|           /> | 								setTimeout(() => { | ||||||
|         </div> | 									document.querySelector("#firstname").focus(); | ||||||
|         <div class="col-span-6"> | 								}, 50); | ||||||
|           <label for="zipcode" class="block text-sm font-medium text-gray-700" | 							}} | ||||||
|             >{$_("zip-postal-code")}</label | 						> | ||||||
|           > | 							{$_("new-donor")} | ||||||
|           <input | 						</button> | ||||||
|             autocomplete="off" | 					</div> | ||||||
|             placeholder={$_("zip-postal-code")} | 				</div> | ||||||
|             class:border-red-500={address.postalcode.length == 0} |  | ||||||
|             class:focus:border-red-500={address.postalcode.length == 0} | 				{#if !donor_create_new} | ||||||
|             class:focus:ring-red-500={address.postalcode.length == 0} | 					<VirtualSelect | ||||||
|             bind:value={address.postalcode} | 						inputElementID="zt12c3udy3bme5bqobmqcif1" | ||||||
|             type="text" | 						bind:this={selectRefDonor} | ||||||
|             name="zipcode" | 						on:onClear={() => { | ||||||
|             class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-neutral-800 rounded-md p-2" | 							console.log("Cleared selection"); | ||||||
|           /> | 						}} | ||||||
|         </div> | 						options={donors} | ||||||
|         <div class="col-span-6"> | 						filterFn={(item, searchTerm) => { | ||||||
|           <label for="city" class="block text-sm font-medium text-gray-700" | 							return item.label | ||||||
|             >City</label | 								.toLowerCase() | ||||||
|           > | 								.includes(searchTerm.toLowerCase()); | ||||||
|           <input | 						}} | ||||||
|             autocomplete="off" | 						bind:selected={donorinfo} | ||||||
|             placeholder="City" | 						inputAriaLabel={$_("search-for-donor")} | ||||||
|             class:border-red-500={address.city.length == 0} | 						inputPlaceholder={$_("search-for-donor")} | ||||||
|             class:focus:border-red-500={address.city.length == 0} | 						noOptionsText={$_("no-donors-found")} | ||||||
|             class:focus:ring-red-500={address.city.length == 0} | 						on:onSelected={(data) => { | ||||||
|             bind:value={address.city} | 							console.log(data.detail); | ||||||
|             type="text" | 							if (data.detail !== null) { | ||||||
|             name="city" | 								document.querySelector("#submit_button").focus(); | ||||||
|             class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-neutral-800 rounded-md p-2" | 								setTimeout(() => { | ||||||
|           /> | 									document.querySelector("#submit_button").focus(); | ||||||
|         </div> | 								}, 100); | ||||||
|       {/if} | 							} | ||||||
|     </div> | 						}} | ||||||
|     <div> | 					/> | ||||||
|       <h4 class="text-xl font-semibold"> | 				{:else} | ||||||
|         {$_("amount-per-kilometer")} | 					<div class="space-y-3"> | ||||||
|       </h4> | 						<!-- First Name --> | ||||||
|       <div class="mt-1 flex rounded-md shadow-sm"> | 						<div> | ||||||
|         <input | 							<label | ||||||
|           autocomplete="off" | 								for="firstname" | ||||||
|           class:border-red-500={!amount > 0} | 								class="block text-sm font-medium text-gray-700" | ||||||
|           class:focus:border-red-500={!amount > 0} | 							> | ||||||
|           class:focus:ring-red-500={!amount > 0} | 								{$_("first-name")} | ||||||
|           bind:value={amount} | 							</label> | ||||||
|           type="number" | 							<input | ||||||
|           step="0.01" | 								type="text" | ||||||
|           name="donation_amount_eur" | 								id="firstname" | ||||||
|           class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | 								on:keydown={(e) => { | ||||||
|           placeholder="2.00" | 									if (e.key === "Enter") { | ||||||
|         /> | 										document.querySelector("#lastname").focus(); | ||||||
|         <span | 									} | ||||||
|           class="inline-flex items-center px-3 rounded-r-md border border-neutral-300 bg-neutral-50 text-neutral-500 text-sm" | 								}} | ||||||
|           >€</span | 								bind:value={donorinfo.firstname} | ||||||
|         > | 								class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | ||||||
|       </div> | 								placeholder={$_("first-name")} | ||||||
|     </div> | 							/> | ||||||
|     <div> | 						</div> | ||||||
|       <h4 class="text-xl font-semibold"> |  | ||||||
|         {$_("confirm")} | 						<!-- Last Name --> | ||||||
|       </h4> | 						<div> | ||||||
|       <button | 							<label | ||||||
|         disabled={amount <= 0 || | 								for="lastname" | ||||||
|           runnerinfo.id == 0 || | 								class="block text-sm font-medium text-gray-700" | ||||||
|           (donorinfo.firstname.length == 0 || donorinfo.lastname.length == 0)} | 							> | ||||||
|         class="py-2 px-4 text-center inline-flex items-center text-md font-medium rounded-lg border border-transparent bg-blue-100 text-blue-800 hover:bg-blue-200 focus:outline-hidden focus:bg-blue-200 disabled:opacity-50 disabled:pointer-events-none dark:text-blue-500 dark:bg-blue-800/30 dark:hover:bg-blue-800/20 dark:focus:bg-blue-800/20" | 								{$_("last-name")} | ||||||
|         on:click={async () => { | 							</label> | ||||||
|           toast.loading($_("creating-donation")); | 							<input | ||||||
|           if (donorinfo.id == 0) { | 								type="text" | ||||||
|             if (!address_checked) { | 								id="lastname" | ||||||
|               address = null | 								bind:value={donorinfo.lastname} | ||||||
|             } | 								class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | ||||||
|             donorinfo = await DonorService.donorControllerPost({ | 								placeholder={$_("last-name")} | ||||||
|               firstname: donorinfo.firstname, | 							/> | ||||||
|               lastname: lastname, | 						</div> | ||||||
|               receiptNeeded: address_checked, |  | ||||||
|               address: address, | 						<!-- Address Checkbox --> | ||||||
|             }); | 						<div class="flex items-start mt-4"> | ||||||
|             loadDonors(); | 							<div class="flex items-center h-5"> | ||||||
|           } | 								<input | ||||||
|           await DonationService.donationControllerPostDistance({ | 									id="address_check" | ||||||
|             amountPerDistance: amount*100, | 									type="checkbox" | ||||||
|             runner: runnerinfo.id, | 									bind:checked={address_checked} | ||||||
|             donor: donorinfo.id, | 									class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded" | ||||||
|           }); | 								/> | ||||||
|           toast.dismiss(); | 							</div> | ||||||
|           toast.success($_("donation-created")); | 							<div class="ml-3 text-sm"> | ||||||
|           resetAll(); | 								<label for="address_check" class="font-medium text-gray-700"> | ||||||
|         }}>{$_("create")}</button | 									{$_("receipt-needed")} | ||||||
|       > | 								</label> | ||||||
|     </div> | 							</div> | ||||||
|   </div> | 						</div> | ||||||
|  |  | ||||||
|  | 						{#if address_checked} | ||||||
|  | 							<!-- Address Fields --> | ||||||
|  | 							<div | ||||||
|  | 								class="space-y-3 mt-3 p-3 border border-gray-200 rounded-md bg-gray-50" | ||||||
|  | 							> | ||||||
|  | 								<div> | ||||||
|  | 									<label | ||||||
|  | 										for="address1" | ||||||
|  | 										class="block text-sm font-medium text-gray-700" | ||||||
|  | 									> | ||||||
|  | 										{$_("address")} | ||||||
|  | 									</label> | ||||||
|  | 									<input | ||||||
|  | 										type="text" | ||||||
|  | 										id="address1" | ||||||
|  | 										bind:value={address.address1} | ||||||
|  | 										class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | ||||||
|  | 									/> | ||||||
|  | 								</div> | ||||||
|  |  | ||||||
|  | 								<div> | ||||||
|  | 									<label | ||||||
|  | 										for="address2" | ||||||
|  | 										class="block text-sm font-medium text-gray-700" | ||||||
|  | 									> | ||||||
|  | 										{$_("apartment-suite-etc")} | ||||||
|  | 									</label> | ||||||
|  | 									<input | ||||||
|  | 										type="text" | ||||||
|  | 										id="address2" | ||||||
|  | 										bind:value={address.address2} | ||||||
|  | 										class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | ||||||
|  | 									/> | ||||||
|  | 								</div> | ||||||
|  |  | ||||||
|  | 								<div class="grid grid-cols-2 gap-3"> | ||||||
|  | 									<div> | ||||||
|  | 										<label | ||||||
|  | 											for="postalcode" | ||||||
|  | 											class="block text-sm font-medium text-gray-700" | ||||||
|  | 										> | ||||||
|  | 											{$_("zip-postal-code")} | ||||||
|  | 										</label> | ||||||
|  | 										<input | ||||||
|  | 											type="text" | ||||||
|  | 											id="postalcode" | ||||||
|  | 											bind:value={address.postalcode} | ||||||
|  | 											class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | ||||||
|  | 										/> | ||||||
|  | 									</div> | ||||||
|  |  | ||||||
|  | 									<div> | ||||||
|  | 										<label | ||||||
|  | 											for="city" | ||||||
|  | 											class="block text-sm font-medium text-gray-700" | ||||||
|  | 										> | ||||||
|  | 											{$_("city")} | ||||||
|  | 										</label> | ||||||
|  | 										<input | ||||||
|  | 											type="text" | ||||||
|  | 											id="city" | ||||||
|  | 											bind:value={address.city} | ||||||
|  | 											class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | ||||||
|  | 										/> | ||||||
|  | 									</div> | ||||||
|  | 								</div> | ||||||
|  | 							</div> | ||||||
|  | 						{/if} | ||||||
|  | 					</div> | ||||||
|  | 				{/if} | ||||||
|  | 			</div> | ||||||
|  | 			<!-- Submit Button --> | ||||||
|  | 			<div class="mt-6"> | ||||||
|  | 				<button | ||||||
|  | 					id="submit_button" | ||||||
|  | 					type="button" | ||||||
|  | 					class="w-full inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:bg-gray-400 disabled:cursor-not-allowed" | ||||||
|  | 					disabled={!amount > 0 || | ||||||
|  | 						!runnerinfo.id || | ||||||
|  | 						(!donorinfo.id && !donor_create_new) || | ||||||
|  | 						(donor_create_new && | ||||||
|  | 							(!donorinfo.firstname || !donorinfo.lastname)) || | ||||||
|  | 						(donor_create_new && | ||||||
|  | 							address_checked && | ||||||
|  | 							(!address.address1 || !address.city || !address.postalcode))} | ||||||
|  | 					on:click={async () => { | ||||||
|  | 						if (donor_create_new) { | ||||||
|  | 							donorinfo = await DonorService.donorControllerPost({ | ||||||
|  | 								firstname: donorinfo.firstname, | ||||||
|  | 								lastname: donorinfo.lastname, | ||||||
|  | 								receiptNeeded: address_checked, | ||||||
|  | 								...(address_checked ? { address: address } : {}), | ||||||
|  | 							}); | ||||||
|  | 						} | ||||||
|  |  | ||||||
|  | 						DonationService.donationControllerPostDistance({ | ||||||
|  | 							donor: donorinfo.id, | ||||||
|  | 							runner: runnerinfo.id, | ||||||
|  | 							amountPerDistance: amount * 100, | ||||||
|  | 						}) | ||||||
|  | 							.then((data) => { | ||||||
|  | 								last_created = data; | ||||||
|  | 								toast.success($_("donation-created-successfully")); | ||||||
|  | 								resetAll(); | ||||||
|  | 								loadDonors(); | ||||||
|  | 							}) | ||||||
|  | 							.catch((err) => { | ||||||
|  | 								console.error("Error creating donation:", err); | ||||||
|  | 								toast.error($_("error-creating-donation")); | ||||||
|  | 							}); | ||||||
|  | 					}} | ||||||
|  | 				> | ||||||
|  | 					{$_("create")} | ||||||
|  | 				</button> | ||||||
|  | 			</div> | ||||||
|  | 		</div> | ||||||
|  | 	</div> | ||||||
| </div> | </div> | ||||||
|  |  | ||||||
| <style> | <style> | ||||||
|   :global(:root) { | 	:global(:root) { | ||||||
|     --sv-bg: #ffffff; | 		--sv-bg: #ffffff; | ||||||
|   } | 	} | ||||||
| </style> | </style> | ||||||
|   | |||||||
							
								
								
									
										357
									
								
								src/components/tools/VirtualSelect.svelte
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										357
									
								
								src/components/tools/VirtualSelect.svelte
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,357 @@ | |||||||
|  | <script> | ||||||
|  | 	import { createEventDispatcher, onMount, tick } from "svelte"; | ||||||
|  |  | ||||||
|  | 	// Generate a default unique ID | ||||||
|  | 	function generateDefaultID() { | ||||||
|  | 		return "virtual-select-" + Math.random().toString(36).slice(2); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Props | ||||||
|  | 	export let options = []; | ||||||
|  | 	export let selected = null; | ||||||
|  | 	export let inputPlaceholder = "Search options..."; | ||||||
|  | 	export let noOptionsText = "No options found"; | ||||||
|  | 	export let inputAriaLabel = "Search and select an option"; | ||||||
|  | 	export let toggleAriaLabel = "Toggle dropdown"; | ||||||
|  | 	export let clearAriaLabel = "Clear selection"; | ||||||
|  | 	export let filterFn = null; // Custom filter function | ||||||
|  | 	export let autofocus = false; // Autofocus input | ||||||
|  | 	export let inputElementID = generateDefaultID(); // Input element ID | ||||||
|  |  | ||||||
|  | 	// Internal state | ||||||
|  | 	let searchTerm = ""; | ||||||
|  | 	let filteredOptions = options; | ||||||
|  | 	let isOpen = false; | ||||||
|  | 	let container; | ||||||
|  | 	let visibleItems = []; | ||||||
|  | 	let startIndex = 0; | ||||||
|  | 	let itemHeight = 40; // Fixed height for each option (in pixels) | ||||||
|  | 	let visibleCount = 10; // Default number of items to render | ||||||
|  | 	let focusedIndex = -1; // Track the focused option index (-1 means no focus) | ||||||
|  | 	let inputElement; // Reference to input element | ||||||
|  |  | ||||||
|  | 	const dispatch = createEventDispatcher(); | ||||||
|  |  | ||||||
|  | 	// Filter options based on search term | ||||||
|  | 	$: { | ||||||
|  | 		filteredOptions = searchTerm | ||||||
|  | 			? filterFn | ||||||
|  | 				? options.filter((option) => filterFn(option, searchTerm)) | ||||||
|  | 				: options.filter((option) => | ||||||
|  | 						option.label.toLowerCase().includes(searchTerm.toLowerCase()) | ||||||
|  | 					) | ||||||
|  | 			: options; | ||||||
|  | 		// Reset scroll and focus when filtered options change | ||||||
|  | 		startIndex = 0; | ||||||
|  | 		focusedIndex = -1; | ||||||
|  | 		updateVisibleItems(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Update visible items based on scroll position | ||||||
|  | 	function updateVisibleItems() { | ||||||
|  | 		if (!container) return; | ||||||
|  | 		const scrollTop = container.scrollTop; | ||||||
|  | 		startIndex = Math.floor(scrollTop / itemHeight); | ||||||
|  | 		const endIndex = Math.min( | ||||||
|  | 			startIndex + visibleCount, | ||||||
|  | 			filteredOptions.length | ||||||
|  | 		); | ||||||
|  | 		visibleItems = filteredOptions.slice(startIndex, endIndex); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Handle scroll event | ||||||
|  | 	function handleScroll() { | ||||||
|  | 		updateVisibleItems(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Calculate visible item count based on container height | ||||||
|  | 	async function updateVisibleCount() { | ||||||
|  | 		if (container) { | ||||||
|  | 			await tick(); // Wait for DOM to render | ||||||
|  | 			visibleCount = Math.ceil(container.clientHeight / itemHeight) + 2; // Buffer of 2 items | ||||||
|  | 			updateVisibleItems(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Handle option selection | ||||||
|  | 	function selectOption(option) { | ||||||
|  | 		selected = option.value; | ||||||
|  | 		isOpen = false; | ||||||
|  | 		searchTerm = option.label; // Set searchTerm to the selected option's label | ||||||
|  | 		focusedIndex = -1; | ||||||
|  | 		dispatch("onSelected", option.value); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Handle clear selection | ||||||
|  | 	function clearSelection() { | ||||||
|  | 		selected = null; | ||||||
|  | 		searchTerm = ""; | ||||||
|  | 		focusedIndex = -1; | ||||||
|  | 		dispatch("onSelected", null); | ||||||
|  | 		dispatch("onClear"); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Reset component state | ||||||
|  | 	export function reset() { | ||||||
|  | 		selected = null; | ||||||
|  | 		searchTerm = ""; | ||||||
|  | 		isOpen = false; | ||||||
|  | 		focusedIndex = -1; | ||||||
|  | 		startIndex = 0; | ||||||
|  | 		updateVisibleItems(); | ||||||
|  | 		dispatch("onSelected", null); | ||||||
|  | 		dispatch("onClear"); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Toggle dropdown | ||||||
|  | 	async function toggleDropdown() { | ||||||
|  | 		isOpen = !isOpen; | ||||||
|  | 		if (isOpen) { | ||||||
|  | 			forceVisibleItems(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Handle click outside to close dropdown | ||||||
|  | 	function handleClickOutside(event) { | ||||||
|  | 		if (!event.target.closest(".select-container")) { | ||||||
|  | 			isOpen = false; | ||||||
|  | 			focusedIndex = -1; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Handle input focus to open dropdown | ||||||
|  | 	async function handleInputFocus() { | ||||||
|  | 		// forceVisibleItems(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Handle input typing to open dropdown | ||||||
|  | 	async function handleInput() { | ||||||
|  | 		forceVisibleItems(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	async function forceVisibleItems() { | ||||||
|  | 		isOpen = true; | ||||||
|  | 		await updateVisibleCount(); // Ensure items render on focus | ||||||
|  | 		// these 2 timeouts are a more or less tmp fix for rendering items when dropdown opens | ||||||
|  | 		setTimeout(async () => { | ||||||
|  | 			await updateVisibleCount(); // Ensure items render on focus | ||||||
|  | 		}, 25); | ||||||
|  | 		setTimeout(async () => { | ||||||
|  | 			await updateVisibleCount(); // Ensure items render on focus | ||||||
|  | 		}, 50); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Handle keyboard navigation | ||||||
|  | 	function handleKeydown(event, index) { | ||||||
|  | 		if (!isOpen) return; | ||||||
|  |  | ||||||
|  | 		if (event.key === "ArrowDown") { | ||||||
|  | 			event.preventDefault(); | ||||||
|  | 			if (focusedIndex < filteredOptions.length - 1) { | ||||||
|  | 				focusedIndex += 1; | ||||||
|  | 				scrollToFocusedItem(); | ||||||
|  | 			} | ||||||
|  | 		} else if (event.key === "ArrowUp") { | ||||||
|  | 			event.preventDefault(); | ||||||
|  | 			if (focusedIndex > 0) { | ||||||
|  | 				focusedIndex -= 1; | ||||||
|  | 				scrollToFocusedItem(); | ||||||
|  | 			} else if (focusedIndex === -1 && filteredOptions.length > 0) { | ||||||
|  | 				focusedIndex = 0; | ||||||
|  | 				scrollToFocusedItem(); | ||||||
|  | 			} | ||||||
|  | 		} else if (event.key === "Enter" && index >= 0) { | ||||||
|  | 			event.preventDefault(); | ||||||
|  | 			selectOption(filteredOptions[index]); | ||||||
|  | 		} else if (event.key === "Escape") { | ||||||
|  | 			event.preventDefault(); | ||||||
|  | 			isOpen = false; | ||||||
|  | 			focusedIndex = -1; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Scroll to the focused item | ||||||
|  | 	function scrollToFocusedItem() { | ||||||
|  | 		if (!container || focusedIndex < 0) return; | ||||||
|  |  | ||||||
|  | 		const itemTop = focusedIndex * itemHeight; | ||||||
|  | 		const itemBottom = itemTop + itemHeight; | ||||||
|  | 		const containerTop = container.scrollTop; | ||||||
|  | 		const containerBottom = containerTop + container.clientHeight; | ||||||
|  |  | ||||||
|  | 		if (itemTop < containerTop) { | ||||||
|  | 			container.scrollTop = itemTop; | ||||||
|  | 		} else if (itemBottom > containerBottom) { | ||||||
|  | 			container.scrollTop = itemBottom - container.clientHeight; | ||||||
|  | 		} | ||||||
|  | 		updateVisibleItems(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Initialize container size observer and autofocus fallback | ||||||
|  | 	onMount(async () => { | ||||||
|  | 		if (container) { | ||||||
|  | 			const resizeObserver = new ResizeObserver(updateVisibleCount); | ||||||
|  | 			resizeObserver.observe(container); | ||||||
|  | 			return () => resizeObserver.disconnect(); | ||||||
|  | 		} | ||||||
|  | 		// Fallback autofocus with tick to ensure inputElement is bound | ||||||
|  | 		if (autofocus && inputElement) { | ||||||
|  | 			await tick(); | ||||||
|  | 			inputElement.focus(); | ||||||
|  | 		} | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	// Get display text for the input | ||||||
|  | 	function getDisplayText() { | ||||||
|  | 		if (!selected) return inputPlaceholder; | ||||||
|  | 		const selectedOption = options.find((option) => option.value === selected); | ||||||
|  | 		return selectedOption ? selectedOption.label : inputPlaceholder; | ||||||
|  | 	} | ||||||
|  | </script> | ||||||
|  |  | ||||||
|  | <svelte:window on:click={handleClickOutside} /> | ||||||
|  |  | ||||||
|  | <div class="select-container relative w-full"> | ||||||
|  | 	<!-- Select element with inline search --> | ||||||
|  | 	<div | ||||||
|  | 		class="border rounded-md px-3 py-2 bg-white shadow-sm flex items-center gap-2" | ||||||
|  | 		role="combobox" | ||||||
|  | 		aria-expanded={isOpen} | ||||||
|  | 	> | ||||||
|  | 		<input | ||||||
|  | 			autocomplete="off" | ||||||
|  | 			type="text" | ||||||
|  | 			id={inputElementID} | ||||||
|  | 			bind:value={searchTerm} | ||||||
|  | 			bind:this={inputElement} | ||||||
|  | 			placeholder={getDisplayText()} | ||||||
|  | 			class="w-full bg-transparent focus:outline-none {selected | ||||||
|  | 				? 'text-black' | ||||||
|  | 				: 'text-gray-700'}" | ||||||
|  | 			{autofocus} | ||||||
|  | 			on:focus={handleInputFocus} | ||||||
|  | 			on:input={handleInput} | ||||||
|  | 			on:keydown={(e) => { | ||||||
|  | 				if (e.key === "Enter" && !isOpen) { | ||||||
|  | 					toggleDropdown(); | ||||||
|  | 				} else { | ||||||
|  | 					handleKeydown(e, focusedIndex); | ||||||
|  | 				} | ||||||
|  | 			}} | ||||||
|  | 			aria-label={inputAriaLabel} | ||||||
|  | 		/> | ||||||
|  | 		{#if selected} | ||||||
|  | 			<button | ||||||
|  | 				type="button" | ||||||
|  | 				class="w-5 h-5 flex items-center justify-center text-gray-500 hover:text-gray-700" | ||||||
|  | 				on:click={clearSelection} | ||||||
|  | 				on:keydown={(e) => { | ||||||
|  | 					if (e.key === "Enter" || e.key === " ") { | ||||||
|  | 						e.preventDefault(); | ||||||
|  | 						clearSelection(); | ||||||
|  | 					} else if (e.key === "Escape") { | ||||||
|  | 						e.preventDefault(); | ||||||
|  | 						isOpen = false; | ||||||
|  | 						focusedIndex = -1; | ||||||
|  | 					} | ||||||
|  | 				}} | ||||||
|  | 				role="button" | ||||||
|  | 				tabindex="0" | ||||||
|  | 				aria-label={clearAriaLabel} | ||||||
|  | 			> | ||||||
|  | 				<svg | ||||||
|  | 					class="w-4 h-4" | ||||||
|  | 					fill="none" | ||||||
|  | 					stroke="currentColor" | ||||||
|  | 					viewBox="0 0 24 24" | ||||||
|  | 				> | ||||||
|  | 					<path | ||||||
|  | 						stroke-linecap="round" | ||||||
|  | 						stroke-linejoin="round" | ||||||
|  | 						stroke-width="2" | ||||||
|  | 						d="M6 18L18 6M6 6l12 12" | ||||||
|  | 					/> | ||||||
|  | 				</svg> | ||||||
|  | 			</button> | ||||||
|  | 		{/if} | ||||||
|  | 		<svg | ||||||
|  | 			class="w-4 h-4 text-gray-500 transform {isOpen ? 'rotate-180' : ''}" | ||||||
|  | 			fill="none" | ||||||
|  | 			stroke="currentColor" | ||||||
|  | 			viewBox="0 0 24 24" | ||||||
|  | 			on:click={toggleDropdown} | ||||||
|  | 			role="button" | ||||||
|  | 			tabindex="0" | ||||||
|  | 			on:keydown={(e) => { | ||||||
|  | 				if (e.key === "Enter") toggleDropdown(); | ||||||
|  | 				else if (e.key === "Escape") { | ||||||
|  | 					e.preventDefault(); | ||||||
|  | 					isOpen = false; | ||||||
|  | 					focusedIndex = -1; | ||||||
|  | 				} | ||||||
|  | 			}} | ||||||
|  | 			aria-label={toggleAriaLabel} | ||||||
|  | 		> | ||||||
|  | 			<path | ||||||
|  | 				stroke-linecap="round" | ||||||
|  | 				stroke-linejoin="round" | ||||||
|  | 				stroke | ||||||
|  | 				Politeness="round" | ||||||
|  | 				stroke-width="2" | ||||||
|  | 				d="M19 9l-7 7-7-7" | ||||||
|  | 			/> | ||||||
|  | 		</svg> | ||||||
|  | 	</div> | ||||||
|  |  | ||||||
|  | 	<!-- Dropdown --> | ||||||
|  | 	{#if isOpen} | ||||||
|  | 		<div | ||||||
|  | 			class="absolute z-10 w-full mt-1 bg-white border rounded-md shadow-lg max-h-80 overflow-auto" | ||||||
|  | 			bind:this={container} | ||||||
|  | 			on:scroll={handleScroll} | ||||||
|  | 			role="listbox" | ||||||
|  | 		> | ||||||
|  | 			{#if filteredOptions.length > 0} | ||||||
|  | 				<!-- Virtualized list container --> | ||||||
|  | 				<div style="height: {filteredOptions.length * itemHeight}px;"> | ||||||
|  | 					<div style="transform: translateY({startIndex * itemHeight}px);"> | ||||||
|  | 						{#each visibleItems as item, i (item.label + "-" + (startIndex + i))} | ||||||
|  | 							<div | ||||||
|  | 								class="px-3 py-2 hover:bg-blue-100 cursor-pointer {selected === | ||||||
|  | 								item.value | ||||||
|  | 									? 'bg-blue-50' | ||||||
|  | 									: ''} {focusedIndex === startIndex + i | ||||||
|  | 									? 'bg-blue-200 outline outline-2 outline-blue-500' | ||||||
|  | 									: ''}" | ||||||
|  | 								on:click={() => selectOption(item)} | ||||||
|  | 								on:keydown={(e) => handleKeydown(e, startIndex + i)} | ||||||
|  | 								role="option" | ||||||
|  | 								tabindex="0" | ||||||
|  | 								aria-selected={selected === item.value} | ||||||
|  | 							> | ||||||
|  | 								{item.label} | ||||||
|  | 							</div> | ||||||
|  | 						{/each} | ||||||
|  | 					</div> | ||||||
|  | 				</div> | ||||||
|  | 			{:else} | ||||||
|  | 				<div class="px-3 py-2 text-gray-500">{noOptionsText}</div> | ||||||
|  | 			{/if} | ||||||
|  | 		</div> | ||||||
|  | 	{/if} | ||||||
|  | </div> | ||||||
|  |  | ||||||
|  | <style> | ||||||
|  | 	/* Ensure Tailwind classes handle additional styling */ | ||||||
|  | 	:global(.select-container input:focus) { | ||||||
|  | 		border-color: #3b82f6; /* Tailwind's blue-500 */ | ||||||
|  | 	} | ||||||
|  | 	:global([role="option"]:focus) { | ||||||
|  | 		outline: 2px solid #3b82f6; | ||||||
|  | 		outline-offset: -2px; | ||||||
|  | 	} | ||||||
|  | 	:global([role="button"]:focus) { | ||||||
|  | 		outline: 2px solid #3b82f6; | ||||||
|  | 		outline-offset: -2px; | ||||||
|  | 	} | ||||||
|  | </style> | ||||||
| @@ -199,6 +199,7 @@ | |||||||
|     "donation-amount": "Sponsoringbetrag", |     "donation-amount": "Sponsoringbetrag", | ||||||
|     "donation-amount-must-be-greater-that-0-00eur": "Der Sponsoringbetrag muss größer als 0.00€ sein.", |     "donation-amount-must-be-greater-that-0-00eur": "Der Sponsoringbetrag muss größer als 0.00€ sein.", | ||||||
|     "donation-created": "Sponsoring erstellt", |     "donation-created": "Sponsoring erstellt", | ||||||
|  |     "donation-created-successfully": "Sponsoring erstellt", | ||||||
|     "donation-deleted": "Sponsoring gelöscht", |     "donation-deleted": "Sponsoring gelöscht", | ||||||
|     "donation-quick-add": "Sponsoringschnelleingabe", |     "donation-quick-add": "Sponsoringschnelleingabe", | ||||||
|     "donation-updated": "Sponsoring wurde aktualisiert", |     "donation-updated": "Sponsoring wurde aktualisiert", | ||||||
| @@ -226,10 +227,12 @@ | |||||||
|     "enabled_large": "Aktiviert", |     "enabled_large": "Aktiviert", | ||||||
|     "english": "Englisch", |     "english": "Englisch", | ||||||
|     "enter-payment": "Zahlung eingeben", |     "enter-payment": "Zahlung eingeben", | ||||||
|  |     "error-creating-donation": "Fehler beim Erstellen des Sponsorings", | ||||||
|     "error-during-import": "Fehler beim Importieren", |     "error-during-import": "Fehler beim Importieren", | ||||||
|     "error-whyile-copying-to-clipboard": "Fehler beim Kopieren in die Zwischenablage", |     "error-whyile-copying-to-clipboard": "Fehler beim Kopieren in die Zwischenablage", | ||||||
|     "error_on_login": "😢Fehler beim Login", |     "error_on_login": "😢Fehler beim Login", | ||||||
|     "everything-concerning-your-profile": "Alles zu deinem Profil", |     "everything-concerning-your-profile": "Alles zu deinem Profil", | ||||||
|  |     "existing-donor": "Existierende Sponsor:in", | ||||||
|     "faq": "FAQ", |     "faq": "FAQ", | ||||||
|     "fast_card_replacement": "Karten-Schnellzusweisung (Mit Mobilgeräteunterstützung)", |     "fast_card_replacement": "Karten-Schnellzusweisung (Mit Mobilgeräteunterstützung)", | ||||||
|     "fast_donation_create": "Sponsoring-Schnellanlage", |     "fast_donation_create": "Sponsoring-Schnellanlage", | ||||||
| @@ -279,6 +282,7 @@ | |||||||
|     "key": "Schlüssel", |     "key": "Schlüssel", | ||||||
|     "laeufer-hinzufuegen": "Läufer hinzufügen", |     "laeufer-hinzufuegen": "Läufer hinzufügen", | ||||||
|     "laptime": "Rundenzeit", |     "laptime": "Rundenzeit", | ||||||
|  |     "last-created-donation": "Zuletzt erstellt", | ||||||
|     "last-name": "Nachname", |     "last-name": "Nachname", | ||||||
|     "last-name-is-required": "Nachname muss angegeben werden", |     "last-name-is-required": "Nachname muss angegeben werden", | ||||||
|     "lfk-is-os": "Das \"Lauf für Kaya!\" Frontend ist (wie alle anderen Projekte für den \"LfK!\" auch) ein OpenSource Projekt.", |     "lfk-is-os": "Das \"Lauf für Kaya!\" Frontend ist (wie alle anderen Projekte für den \"LfK!\" auch) ein OpenSource Projekt.", | ||||||
| @@ -311,6 +315,7 @@ | |||||||
|     "must-contain-a-uppercase-letter": "Passwort muss einen Kleinbuchstaben enthalten!", |     "must-contain-a-uppercase-letter": "Passwort muss einen Kleinbuchstaben enthalten!", | ||||||
|     "name": "Name", |     "name": "Name", | ||||||
|     "name-is-required": "Der Gruppenname muss angegeben werden", |     "name-is-required": "Der Gruppenname muss angegeben werden", | ||||||
|  |     "new-donor": "Neue Sponsor:in", | ||||||
|     "new-password": "Neues Passwort", |     "new-password": "Neues Passwort", | ||||||
|     "next_runner": "Nächster Läufer", |     "next_runner": "Nächster Läufer", | ||||||
|     "no-address": "Keine Adresse hinterlegt", |     "no-address": "Keine Adresse hinterlegt", | ||||||
| @@ -420,6 +425,7 @@ | |||||||
|     "scanstations-are-being-loaded": "Scannerstationen werden geladen...", |     "scanstations-are-being-loaded": "Scannerstationen werden geladen...", | ||||||
|     "search-for-an-organization-by-name-or-id": "Suche eine Organisation (via Name oder #ID)", |     "search-for-an-organization-by-name-or-id": "Suche eine Organisation (via Name oder #ID)", | ||||||
|     "search-for-an-organization-or-team-by-name-or-id": "Suche eine Organisation oder ein Team (via Name oder #ID)", |     "search-for-an-organization-or-team-by-name-or-id": "Suche eine Organisation oder ein Team (via Name oder #ID)", | ||||||
|  |     "search-for-donor": "Nach Sponsor:in suchen", | ||||||
|     "search-for-donor-name-or-id": "Suche eine Sponsor (via Name oder #ID)", |     "search-for-donor-name-or-id": "Suche eine Sponsor (via Name oder #ID)", | ||||||
|     "search-for-permission": "Berechtigungen durchsuchen", |     "search-for-permission": "Berechtigungen durchsuchen", | ||||||
|     "search-for-runner-by-name-or-id": "Suche einen Läufer (via Name oder #ID)", |     "search-for-runner-by-name-or-id": "Suche einen Läufer (via Name oder #ID)", | ||||||
|   | |||||||
| @@ -199,6 +199,7 @@ | |||||||
|     "donation-amount": "Donation amount", |     "donation-amount": "Donation amount", | ||||||
|     "donation-amount-must-be-greater-that-0-00eur": "Donation amount must be greater that 0.00€", |     "donation-amount-must-be-greater-that-0-00eur": "Donation amount must be greater that 0.00€", | ||||||
|     "donation-created": "Created sponsoring", |     "donation-created": "Created sponsoring", | ||||||
|  |     "donation-created-successfully": "Donation created", | ||||||
|     "donation-deleted": "Donation deleted", |     "donation-deleted": "Donation deleted", | ||||||
|     "donation-quick-add": "Mass sponsoring creation", |     "donation-quick-add": "Mass sponsoring creation", | ||||||
|     "donation-updated": "Donation updated", |     "donation-updated": "Donation updated", | ||||||
| @@ -226,10 +227,12 @@ | |||||||
|     "enabled_large": "Enabled", |     "enabled_large": "Enabled", | ||||||
|     "english": "English", |     "english": "English", | ||||||
|     "enter-payment": "Enter payment", |     "enter-payment": "Enter payment", | ||||||
|  |     "error-creating-donation": "error creating the sponsoring", | ||||||
|     "error-during-import": "Error during import", |     "error-during-import": "Error during import", | ||||||
|     "error-whyile-copying-to-clipboard": "Error while copying to clipboard", |     "error-whyile-copying-to-clipboard": "Error while copying to clipboard", | ||||||
|     "error_on_login": "Error on login", |     "error_on_login": "Error on login", | ||||||
|     "everything-concerning-your-profile": "Everything concerning your profile", |     "everything-concerning-your-profile": "Everything concerning your profile", | ||||||
|  |     "existing-donor": "Existing Donor", | ||||||
|     "faq": "FAQ", |     "faq": "FAQ", | ||||||
|     "fast_card_replacement": "Fast card replacement (with mobile support)", |     "fast_card_replacement": "Fast card replacement (with mobile support)", | ||||||
|     "fast_donation_create": "Mass donation creator", |     "fast_donation_create": "Mass donation creator", | ||||||
| @@ -279,6 +282,7 @@ | |||||||
|     "key": "Key", |     "key": "Key", | ||||||
|     "laeufer-hinzufuegen": "Add runner", |     "laeufer-hinzufuegen": "Add runner", | ||||||
|     "laptime": "Laptime", |     "laptime": "Laptime", | ||||||
|  |     "last-created-donation": "Last created", | ||||||
|     "last-name": "Last name", |     "last-name": "Last name", | ||||||
|     "last-name-is-required": "Last Name is required", |     "last-name-is-required": "Last Name is required", | ||||||
|     "lfk-is-os": "The \"Lauf für Kaya!\" Frontend is (like all other projects for the \"LfK!\" Also) an open source project.", |     "lfk-is-os": "The \"Lauf für Kaya!\" Frontend is (like all other projects for the \"LfK!\" Also) an open source project.", | ||||||
| @@ -310,6 +314,7 @@ | |||||||
|     "must-contain-a-uppercase-letter": "Must contain a uppercase letter!", |     "must-contain-a-uppercase-letter": "Must contain a uppercase letter!", | ||||||
|     "name": "Name", |     "name": "Name", | ||||||
|     "name-is-required": "Name is required", |     "name-is-required": "Name is required", | ||||||
|  |     "new-donor": "New donor", | ||||||
|     "new-password": "New password", |     "new-password": "New password", | ||||||
|     "next_runner": "Next Runner", |     "next_runner": "Next Runner", | ||||||
|     "no-address": "no address", |     "no-address": "no address", | ||||||
| @@ -419,6 +424,7 @@ | |||||||
|     "scanstations-are-being-loaded": "Loading scanstations...", |     "scanstations-are-being-loaded": "Loading scanstations...", | ||||||
|     "search-for-an-organization-by-name-or-id": "Search for an organization (by name or #ID)", |     "search-for-an-organization-by-name-or-id": "Search for an organization (by name or #ID)", | ||||||
|     "search-for-an-organization-or-team-by-name-or-id": "Search for an organization or team (by name or #ID)", |     "search-for-an-organization-or-team-by-name-or-id": "Search for an organization or team (by name or #ID)", | ||||||
|  |     "search-for-donor": "Search for donor", | ||||||
|     "search-for-donor-name-or-id": "Search for donor (by name or #ID)", |     "search-for-donor-name-or-id": "Search for donor (by name or #ID)", | ||||||
|     "search-for-permission": "Search for permission", |     "search-for-permission": "Search for permission", | ||||||
|     "search-for-runner-by-name-or-id": "Search for runner (by name or #ID)", |     "search-for-runner-by-name-or-id": "Search for runner (by name or #ID)", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user