File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const FILE_TYPES = [ 'jpg' , 'jpeg' , 'png' ] ;
2+
3+ const imagePreviewWrapper = document . querySelector ( '.img-upload__preview' ) ;
4+ const imagePreview = imagePreviewWrapper . querySelector ( 'img' ) ;
5+
6+ const handleUpload = ( target ) => {
7+ const file = target . files [ 0 ] ;
8+ const fileName = file . name . toLowerCase ( ) ;
9+
10+ const matches = FILE_TYPES . some ( ( it ) => fileName . endsWith ( it ) ) ;
11+
12+ if ( matches ) {
13+ imagePreview . src = URL . createObjectURL ( file ) ;
14+ }
15+ } ;
16+
17+ export {
18+ handleUpload ,
19+ } ;
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { checkValidaty } from './form-validation.js';
55import { resetEffects } from './effects.js' ;
66import { postPhoto } from './api.js' ;
77import { showPostSuccessMessage } from './messages.js' ;
8+ import { handleUpload } from './upload-image.js' ;
89
910const modalWindow = document . querySelector ( '.img-upload__overlay' ) ;
1011const uploadForm = document . querySelector ( '.img-upload__form' ) ;
@@ -13,11 +14,15 @@ const modalCloseButton = document.querySelector('.img-upload__cancel');
1314const hashTagsInput = document . querySelector ( '.text__hashtags' ) ;
1415const descriptionInput = document . querySelector ( '.text__description' ) ;
1516
17+
1618uploadForm . method = 'post' ;
1719uploadForm . action = 'https://31.javascript.htmlacademy.pro/kekstagram' ;
1820uploadForm . enctype = 'multipart/form-data' ;
1921
20- const onUploadClick = ( ) => handleOpen ( ) ;
22+ const onUploadClick = ( { target} ) => {
23+ handleUpload ( target ) ;
24+ handleOpen ( ) ;
25+ } ;
2126const onEscapeKeydown = ( evt ) => {
2227 if ( document . activeElement === hashTagsInput
2328 ||
You can’t perform that action at this time.
0 commit comments