Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Venue Info Component update #13

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import makeFileInputDropZone from './share-controller.js';

function initVenueImageInput(component) {
const wrapper = component.querySelector('.img-file-input-wrapper');
makeFileInputDropZone(wrapper);
}

function loadGoogleMapsAPI(callback) {
const script = document.createElement('script');
script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyBStUMRpmG-vchdbtciHmqdQhzvLXmgQyI&libraries=places&callback=onGoogleMapsApiLoaded';
Expand Down Expand Up @@ -87,7 +80,6 @@ function initAutocomplete(el) {
}

export default function init(component) {
initVenueImageInput(component);
loadGoogleMapsAPI(() => initAutocomplete(component));
}

Expand Down
4 changes: 2 additions & 2 deletions blocks/venue-info-component/venue-info-component.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
}

.venue-info-component .venue-info-addition-wrapper {
display: grid;
grid-template-columns: 1fr 1fr;
display: flex;
justify-content: flex-end;
}

.venue-info-component .venue-info-addition-wrapper .venue-info-addition {
Expand Down
77 changes: 16 additions & 61 deletions blocks/venue-info-component/venue-info-component.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getLibs } from '../../scripts/utils.js';
import { getIcon, generateToolTip } from '../../utils/utils.js';
import { generateToolTip } from '../../utils/utils.js';

const { createTag } = await import(`${getLibs()}/utils/utils.js`);

Expand Down Expand Up @@ -34,68 +34,22 @@ function decorateSWCTextField(row, extraOptions) {
}

function buildAdditionalInfo(row) {
function decorateImageDropzones(col) {
col.classList.add('image-dropzone');
const paragraphs = col.querySelectorAll(':scope > p');
const fileInput = createTag('input', {
id: 'venue-image',
type: 'file',
class: 'img-file-input',
});
const inputWrapper = createTag('div', { class: 'img-file-input-wrapper' });
const inputLabel = createTag('label', { class: 'img-file-input-label' });

const previewWrapper = createTag('div', { class: 'preview-wrapper hidden' });
const previewImg = createTag('div', { class: 'preview-img-placeholder' });
const previewDeleteButton = getIcon('delete');

previewWrapper.append(previewImg, previewDeleteButton);

inputWrapper.append(previewWrapper, inputLabel);
inputLabel.append(fileInput, getIcon('image-add'));
paragraphs.forEach((p) => {
inputLabel.append(p);
});

col.innerHTML = '';
col.append(inputWrapper);
}
row.classList.add('venue-info-addition');
const fieldSet = createTag('fieldset', { class: 'checkboxes' });
const [inputLabel, comment] = [...row.querySelectorAll(':scope p')];
const labelText = inputLabel.textContent.trim();

function decorateVenueInfoVisible(col) {
const fieldSet = createTag('fieldset', { class: 'checkboxes' });
col.classList.add('venue-info-addition');
const [inputLabel, comment] = [...col.querySelectorAll(':scope > p')];
const cn = inputLabel.textContent.trim();

const handle = 'venue-info-visible';
const input = createTag('input', {
id: `checkbox-${handle}`,
name: `checkbox-${handle}`,
type: 'checkbox',
class: 'checkbox-input',
value: handle,
});
const label = createTag(
'label',
{ class: 'checkbox-label', for: `checkbox-${handle}` },
cn,
);
const wrapper = createTag('div', { class: 'checkbox-wrapper' });

wrapper.append(input, label);
fieldSet.append(wrapper);

const additionComment = createTag('div', { class: 'addition-comment' });
additionComment.append(comment.textContent.trim());
col.innerHTML = '';
fieldSet.append(additionComment);
col.append(fieldSet);
}
const checkbox = createTag('sp-checkbox', { id: 'checkbox-venue-info-visible' }, labelText);
const wrapper = createTag('div', { class: 'checkbox-wrapper' });

row.classList.add('img-upload-component');
const [imageUploader, venueVisible] = row.querySelectorAll(':scope > div');
decorateImageDropzones(imageUploader);
decorateVenueInfoVisible(venueVisible);
wrapper.append(checkbox);
fieldSet.append(wrapper);

const additionComment = createTag('div', { class: 'addition-comment' });
additionComment.append(comment.textContent.trim());
row.innerHTML = '';
fieldSet.append(additionComment);
row.append(fieldSet);
row.classList.add('venue-info-addition-wrapper');
}

Expand Down Expand Up @@ -171,6 +125,7 @@ export default function init(el) {
Promise.all([
import(`${miloLibs}/deps/lit-all.min.js`),
import(`${miloLibs}/features/spectrum-web-components/dist/textfield.js`),
import(`${miloLibs}/features/spectrum-web-components/dist/checkbox.js`),
]);

const rows = el.querySelectorAll(':scope > div');
Expand Down
Loading