Skip to content

Commit

Permalink
added onResume to each component controller
Browse files Browse the repository at this point in the history
  • Loading branch information
qiyundai committed May 3, 2024
1 parent c1293da commit dd0d97a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default function init(component) {
});
}

export function onResume() {
// TODO: handle form prepopulation on component level
}

export function onSubmit(component, inputMap) {
console.log(inputMap, 'checkbox onSubmit not built yet');
return {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ function initNewSeriesModal(component) {

function prepopulateTimeZone(component) {
const currentTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;

if (!currentTimeZone) return;

const timeZoneInput = component.querySelector('#time-zone-select-input');

if (!timeZoneInput) return;

const options = timeZoneInput.querySelectorAll('option');

options.forEach((opt) => {
Expand All @@ -35,6 +37,10 @@ export default function init(component) {
prepopulateTimeZone(component);
}

export function onResume() {
// TODO: handle form prepopulation on component level
}

export function onSubmit(component, inputMap) {
console.log(inputMap);
return {};
Expand Down
13 changes: 13 additions & 0 deletions blocks/form-handler/controllers/event-info-component-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,19 @@ export default function init(component) {
initCalendar(component);
}

export function onResume(component, eventObj, inputMap) {
inputMap.forEach((input) => {
const element = component.querySelector(input.selector);
if (!element) return;

if (element[input.accessPoint] !== undefined) {
element[input.accessPoint] = eventObj[input.key];
} else {
element.setAttirbute(input.accessPoint, eventObj[input.key]);
}
});
}

export function onSubmit(component, inputMap) {
const datePicker = component.querySelector('#event-info-date-picker');
const startDate = new Date(datePicker.dataset.startDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export default function init(component) {
});
}

export function onResume() {
// TODO: handle form prepopulation on component level
}

export function onSubmit(component, inputMap) {
console.log(inputMap);
return {};
Expand Down
10 changes: 8 additions & 2 deletions blocks/form-handler/controllers/share-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ export function getMappedInputsOutput(component, inputMap) {
const inputFound = component.querySelector(row.selector);

if (inputFound) {
const { key, accessPoint } = row;
output[key] = getElementOutput(inputFound, accessPoint);
const { key, accessPoint, shadowRootSelector } = row;
let targetInput = inputFound;

if (shadowRootSelector) {
targetInput = inputFound.shadowRoot.querySelector(shadowRootSelector);
}

output[key] = getElementOutput(targetInput, accessPoint);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export default function init(component) {
initVenueImageInput(component);
}

export function onResume() {
// TODO: handle form prepopulation on component level
}

export function onSubmit(component, inputMap) {
const venueInfoVisible = component.querySelector('#checkbox-venue-info-visible').checked;

Expand Down
17 changes: 8 additions & 9 deletions blocks/form-handler/form-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,14 @@ function prepopulateForm(el, inputMap) {

const eventObj = JSON.parse(localStorage.getItem(eventId));

inputMap.forEach((input) => {
const element = el.querySelector(input.selector);
if (!element) return;

if (element[input.accessPoint] !== undefined) {
element[input.accessPoint] = eventObj[input.key];
} else {
element.setAttirbute(input.accessPoint, eventObj[input.key]);
}
SUPPORTED_COMPONENTS.forEach((comp) => {
const mappedComponents = el.querySelectorAll(`.${comp}-component`);
if (!mappedComponents?.length) return;

mappedComponents.forEach(async (component) => {
const { onResume } = await import(`./controllers/${comp}-component-controller.js`);
await onResume(component, eventObj, inputMap);
});
});
}

Expand Down

0 comments on commit dd0d97a

Please sign in to comment.