From 867425cc9c2c685733dd18374930e93d26786d6a Mon Sep 17 00:00:00 2001 From: TatianaSenatorova <108460915+TatianaSenatorova@users.noreply.github.com> Date: Sat, 14 Dec 2024 16:53:14 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0?= =?UTF-8?q?=D1=89=D0=B0=D0=B5=D1=82=20=D0=BF=D1=83=D1=82=D1=8C=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=BE=D0=B2=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8E,=20=D1=82=D0=B0?= =?UTF-8?q?=D0=BA=20=D0=BA=D0=B0=D0=BA=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=20=D0=B7=D0=B0=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=BB?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/api.js | 6 ++---- js/main.js | 1 + js/upload-photo.js | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 js/upload-photo.js 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); + } +});