diff --git a/js/api.js b/js/api.js index c3200d2..b76a648 100644 --- a/js/api.js +++ b/js/api.js @@ -1,9 +1,7 @@ -// const BASE_URL = 'https://31.javascript.htmlacademy.pro/kekstagram'; -const BASE_URL = 'https://a4583caa5935373e.mokky.dev/html_keksogram'; +const BASE_URL = 'https://31.javascript.htmlacademy.pro/kekstagram'; const Route = { - GET_DATA: '', - // GET_DATA: '/data', + GET_DATA: '/data', SEND_DATA: '/', }; diff --git a/js/main.js b/js/main.js index 7b8cfe7..6c3b120 100644 --- a/js/main.js +++ b/js/main.js @@ -7,6 +7,7 @@ import './effects-photo.js'; import { getData, ErrorIdTemplates } from './api.js'; import { showRequestInfoTimeout, debounce } from './utils.js'; import { showFilters, setFilterClick } from './filters.js'; +import './upload-photo.js'; const PHOTO_ITEMS_NUMBER = 25; const RERENDER_DELAY = 500; diff --git a/js/upload-photo.js b/js/upload-photo.js new file mode 100644 index 0000000..5420e64 --- /dev/null +++ b/js/upload-photo.js @@ -0,0 +1,18 @@ +import { imgUploadForm } from './open-form.js'; + +const FILE_TYPES = ['jpg', 'jpeg', 'png']; + +const fileChooser = imgUploadForm.querySelector('.img-upload__input'); + +const imgPhotoPreview = imgUploadForm.querySelector('.img-upload__preview img'); + +fileChooser.addEventListener('change', () => { + const file = fileChooser.files[0]; + const fileName = file.name.toLowerCase(); + + const matches = FILE_TYPES.some((it) => fileName.endsWith(it)); + + if (matches) { + imgPhotoPreview.src = URL.createObjectURL(file); + } +});