Compare commits

...

4 Commits

Author SHA1 Message Date
1731cff9c9 set log level in release build to info 2025-11-04 15:35:53 +01:00
336249fd12 added gitattributes 2025-11-04 15:26:24 +01:00
5ffeb969e2 chache idmap on client 2025-11-04 15:00:12 +01:00
a4ab0bad48 pessimistic id mapping loading on frontend 2025-11-04 14:47:46 +01:00
5 changed files with 68 additions and 16 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
/pcb/bom/ibom.html linguist-vendored

View File

@@ -19,7 +19,7 @@ esp-radio = { version = "0.16.0", features = ["esp32c6","esp-alloc", "wifi", "lo
esp-rtos = { version = "0.1.1", features = ["esp32c6", "embassy", "esp-radio", "esp-alloc"] }
critical-section = "1.2.0"
log = { version = "0.4" }
log = { version = "0.4", features = ["release_max_level_info"]}
static_cell = { version = "2.1.1", features = ["nightly"] }
heapless = { version = "0.8.0", default-features = false }
chrono = { version = "0.4.41", default-features = false }

View File

@@ -5,7 +5,12 @@
import AddIDModal from "./lib/AddIDModal.svelte";
import ExportModal from "./lib/ExportModal.svelte";
import { generateCSVFile } from "./lib/exporting";
import { fetchMapping, type IDMap } from "./lib/IDMapping";
import {
cacheMappingInLocalstore,
fetchMapping,
loadCachedMappingFromLocalstore,
type IDMap,
} from "./lib/IDMapping";
import { downloadBlob } from "./lib/downloadBlob";
let lastID: string = $state("");
@@ -15,7 +20,11 @@
let exportModal: ExportModal;
onMount(async () => {
mapping = await fetchMapping();
mapping = loadCachedMappingFromLocalstore();
let fetchedMapping = await fetchMapping();
mapping = fetchedMapping;
cacheMappingInLocalstore(fetchedMapping);
let sse = new EventSource("/api/idevent");
sse.addEventListener("msg", function (e) {
@@ -57,15 +66,22 @@
}}
/>
<span>Gesammmte einträge: {Object.keys(mapping).length}</span>
{:else}
Lade ...
{/if}
</div>
<AddIDModal
bind:this={addModal}
onSubmitted={async () => {
mapping = await fetchMapping();
onSubmitted={async (id, firstName, lastname) => {
if (mapping == null) {
return;
}
mapping[id] = {
first: firstName,
last: lastname,
};
}}
/>

View File

@@ -1,7 +1,11 @@
<script lang="ts">
import Modal from "./Modal.svelte";
let { onSubmitted }: { onSubmitted?: () => void } = $props();
let {
onSubmitted,
}: {
onSubmitted?: (id: string, firstName: string, lastName: string) => void;
} = $props();
let displayID = $state("");
let firstName = $state("");
@@ -9,7 +13,11 @@
let modal: Modal;
export function open(presetID: string, presetFirstName?: string, presetLastName?: string) {
export function open(
presetID: string,
presetFirstName?: string,
presetLastName?: string,
) {
displayID = presetID;
firstName = presetFirstName ?? "";
@@ -33,13 +41,14 @@
"Content-Type": "application/json",
},
body: JSON.stringify(data),
}).then(() => {
onSubmitted?.();
});
}).then((res) => {
if (res.status == 201) {
onSubmitted?.(displayID, firstName, lastName);
}
firstName = "";
lastName = "";
displayID = "";
});
}
</script>

View File

@@ -32,6 +32,32 @@ export async function fetchMapping(): Promise<IDMap> {
return map;
}
const CACHE_KEY = "idmap";
export function cacheMappingInLocalstore(mapping: IDMap) {
if (!localStorage) {
console.error("localStorage is not available");
return;
}
localStorage.setItem(CACHE_KEY, JSON.stringify(mapping));
}
export function loadCachedMappingFromLocalstore(): IDMap | null {
if (!localStorage) {
console.error("localStorage is not available");
return null;
}
const data = localStorage.getItem(CACHE_KEY);
if (!data) {
return null;
}
const mapping = JSON.parse(data);
return mapping;
}
export async function addMapping(id: string, firstName: string, lastName: string) {
let req = await fetch("/api/mapping", {
method: "POST",