Skip to content

Commit

Permalink
Reset EBD input upon format version change
Browse files Browse the repository at this point in the history
  • Loading branch information
OLILHR committed Nov 5, 2024
1 parent 01a0556 commit 8d09aea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/lib/components/features/ebd-form-header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@
return matchingEbd ? matchingEbd.ebd_code : "";
}
let formatVersionChanged = false;
// new format version <select> only causes ebd <input> to reset to placeholder
function handleFormatVersionSelect(event: CustomEvent<string>) {
const newFormatVersion = event.detail;
if (newFormatVersion !== currentFormatVersion) {
currentFormatVersion = newFormatVersion;
currentEbd = ""; // reset the EBD selection
currentEbd = ""; // reset EBD selection
formatVersionChanged = true;
setTimeout(() => {
formatVersionChanged = false;
}, 0);
}
}
Expand Down Expand Up @@ -76,6 +82,7 @@
<EbdInput
ebds={currentEbds}
{selectedEbdCode}
{formatVersionChanged}
disabled={!currentFormatVersion}
on:select={handleEbdInput}
/>
Expand Down
10 changes: 10 additions & 0 deletions src/lib/components/features/ebd-input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
export let ebds: EbdNameExtended[] = [];
export let disabled: boolean = false;
export let selectedEbdCode: string = "";
export let formatVersionChanged = false;
const dispatch = createEventDispatcher<{ select: string }>();
Expand All @@ -15,6 +16,15 @@
let isFocused: boolean = false; // used for setting the focus state of the EBD input to show/hide the window containing the selectable EBDs
let selectedEbdNameExtended: EbdNameExtended | undefined;
$: {
if (formatVersionChanged) {
selectedEbdCode = "";
selectedEbdNameExtended = undefined;
inputValue = "";
filteredEbds = ebds;
}
}
function updateSelectedEbdNameExtended() {
selectedEbdNameExtended = selectedEbdCode
? ebds.find((ebd) => ebd.ebd_code === selectedEbdCode)
Expand Down
6 changes: 3 additions & 3 deletions src/server/ebd-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export function getEbds(): Record<string, EbdNameExtended[]> {
const parseMetaData = JSON.parse(jsonContent) as MetaData;
// only update extended ebd_name if corresponding metadata <value> of ebd_name <key> exists
if (
parseMetaData.metadata.ebd_name &&
parseMetaData.metadata.ebd_name.trim()
parseMetaData.metadata.chapter &&
parseMetaData.metadata.chapter.trim()
) {
ebd_name = `${ebdCode}_${parseMetaData.metadata.ebd_name}`;
ebd_name = `${ebdCode}_${parseMetaData.metadata.chapter}`;
}
} catch (error) {
console.warn(`no metadata available for ${ebdCode}: ${error}`);
Expand Down

0 comments on commit 8d09aea

Please sign in to comment.