Skip to content

Week 4 #470

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions projects/loft-photo-lite-3/images/arrow-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions projects/loft-photo-lite-3/images/button.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions projects/loft-photo-lite-3/images/chat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions projects/loft-photo-lite-3/images/exit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions projects/loft-photo-lite-3/images/heart-red.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions projects/loft-photo-lite-3/images/heart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions projects/loft-photo-lite-3/images/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions projects/loft-photo-lite-3/images/send.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions projects/loft-photo-lite-3/images/vert1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions projects/loft-photo-lite-3/images/vert2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions projects/loft-photo-lite-3/images/vert3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions projects/loft-photo-lite-3/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pages from './pages';
import mainPage from './mainPage';
import loginPage from './loginPage';
import('./styles.css');

pages.openPage('login');
loginPage.handleEvents();
mainPage.handleEvents();
64 changes: 64 additions & 0 deletions projects/loft-photo-lite-3/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=360,user-scalable=false" />
<title>Loft Photo</title>
<script src="http://vk.com/js/api/openapi.js"></script>
</head>
<body>
<div id="app">
<div class="page page-login hidden">
<div class="page-login-vert1"></div>
<div class="page-login-vert2"></div>
<div class="page-login-vert3"></div>
<div class="page-login-logo">
<div class="page-login-image"></div>
<div class="page-login-text">Не пропустите лучшие моменты из жизни ваших друзей!</div>
</div>
<button class="page-login-button"></button>
</div>
<div class="page page-main hidden">
<div class="component-photo"></div>
<div class="component-header">
<a class="component-header-profile-link" href="#">
<div class="component-header-photo"></div>
<div class="component-header-name"></div>
</a>
</div>
<div class="component-footer">
<div class="component-footer-container">
<a href="#" class="component-footer-container-social-comments">
0
</a>
<a href="#" class="component-footer-container-social-likes">
0
</a>
<a class="component-footer-container-profile-link" href="#">
<div class="component-footer-photo"></div>
</a>
<div class="component-comments hidden">
<div class="component-comments-container">
<div class="component-comments-container-title">Комментарии</div>
<div class="component-comments-container-list"></div>
<div class="component-comments-container-form">
<input type="text" class="component-comments-container-form-input" placeholder="Введите текст"/>
<div class="component-comments-container-form-send"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="page page-profile hidden">
<a href="#" class="page-profile-back"></a>
<a href="#" class="page-profile-exit"></a>
<div class="component-user-info">
<div class="component-user-info-photo"></div>
<div class="component-user-info-name"></div>
</div>
<div class="component-user-photos"></div>
</div>
</div>
</body>
</html>
15 changes: 15 additions & 0 deletions projects/loft-photo-lite-3/loginPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import model from './model';
import pages from './pages';
import mainPage from './mainPage';

export default {
handleEvents() {
document.querySelector('.page-login-button').addEventListener('click', async () => {
await model.login();
await model.init();

pages.openPage('main');
await mainPage.getNextPhoto();
});
},
};
35 changes: 35 additions & 0 deletions projects/loft-photo-lite-3/mainPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { doc } from 'prettier';
import model from './model';

export default {
async getNextPhoto() {
const { friend, id, url } = await model.getNextPhoto();
this.setFriendAndPhoto(friend, id, url);
},

setFriendAndPhoto(friend, id, url) {
const photoComp = document.querySelector('.component-photo');
const headerPhotoComp = document.querySelector('.component-header-photo');
const photoNameComp = document.querySelector('.component-header-name');

photoComp.style.backgrounImage = `url(${url})`;
headerPhotoComp.style.backgrounImage = `url('${frind.photo_50}')`;
photoNameComp.innerText = `${fiend.first_name ?? ''} ${frind.last_name ?? ''}`;
},

handleEvents() {
let startFrom;

document.querySelector('.component-photo').addEventListener('touchstart', (e) => {
e.preventDefault();
startFrom = {y: e.changedTouches[0].pageY};
});

document.querySelector('.component-photo').addEventListener('touchend', async (e) => {
const direction = e.changedTouches[0].pageY - startFrom.y;
if (direction < 0) {
await this.getNextPhoto();
}
});
},
};
89 changes: 89 additions & 0 deletions projects/loft-photo-lite-3/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
export default {
getRandomElement(array) {},

async getNextPhoto() {
const friend = this.getRandomElement(this.friends.item);
const photos = await this.getFriendPhotos(friend.id);
const photo = this.getRandomElement(photos.items);
const size = this.findSize(photo);

return {fiend, id: photo.id, url: size.url};
},

findSize(photo){
const size = photo.sizes.find ((size) =>{size.width >= 360})
if (!size) {
return photo.sizes.reduce ((biggest, current) => {
if (current.width > biggest.width) {
return current;
}
return biggest;
}, photo.sizes[0]);
}
},

async init (){
this.photoCache = {};
this.friends = await this.getFriends();
},

login() {
return new Promise((resolve, reject) => {
VK.init ({
apiId: APP_ID,
})
VK.Auth.login((response) => {
if(response.session) {
resolve(response)
} else {
console.error (response);
reject(response);
}
});
});
},

logout () {

},

callApi (method, params) {
params.v = params.v || '5.120';

return new Promise ((resolve, reject) => {
VK.api (method, params, (response) => {
if (response.error) {reject(new Error(response.error.error_msg));} else {resolve(response.response);}
});
});

},

getPhotos(owner) {
const params = {
owner_if: owner,
};

return this.callApi ('photos.getAll', params);
},

getFriends () {
const params = {
friends: ['photo_50', 'photo_100'],
}
return this.callApi('friends.get', params);
},

async getFriendPhotos(id) {
let photos = this.photoCache[id];

if (photos) {
return photos;
}

photos = await this.getPhotos (id);

this.photoCache[id] = photos;

return photos;
},
};
9 changes: 9 additions & 0 deletions projects/loft-photo-lite-3/pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const pagesMap = {
login: '.page-login',
main: '.page-main',
profile: '.page-profile',
};

export default {
openPage(name) {},
};
Loading