Skip to content

Commit

Permalink
Link rating with backend, other edits
Browse files Browse the repository at this point in the history
  • Loading branch information
tkoibaev committed Dec 15, 2024
1 parent ce767b5 commit 12cd6f0
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 101 deletions.
Binary file removed public/assets/images/cowatchBackground.png
Binary file not shown.
Binary file added public/assets/images/cowatchBackground.webp
Binary file not shown.
Binary file removed public/assets/images/cowatchBackgroundMobile.png
Binary file not shown.
Binary file added public/assets/images/cowatchBackgroundMobile.webp
Binary file not shown.
2 changes: 1 addition & 1 deletion public/components/CoWatchBlock/CoWatchBlock.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</div>
<img
class='cowatch-block__background'
src='/assets/images/cowatchBackground.png'
src='/assets/images/cowatchBackground.webp'
alt=''
/>
{{/if}}
Expand Down
3 changes: 2 additions & 1 deletion public/components/CoWatchBlock/CoWatchBlock.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
&__background {
width: 100%;
user-select: none;
height: 35vw;
}
&__container {
position: absolute;
Expand Down Expand Up @@ -110,7 +111,7 @@
}
height: 420px;
&__container {
background-image: url('assets/images/cowatchBackgroundMobile.png');
background-image: url('assets/images/cowatchBackgroundMobile.webp');
background-size: cover;
background-position: center;
}
Expand Down
5 changes: 1 addition & 4 deletions public/components/RateBlock/RateBlock.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
<span class='rate-block__content_subtitle'>Оценки помогают сделать
сервис лучше</span>
</div>
<button
id='rate-block-delete-rate-button'
class='button rate-block__content_remove-rate'
>Удалить</button>

</div>
{{else}}
<div class='rate-block__content_description'>
Expand Down
41 changes: 21 additions & 20 deletions public/components/RateBlock/RateBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ export class RateBlock {
'.rating-star',
) as NodeListOf<HTMLElement>;

if (this.#movie?.userRating === 0) {
stars.forEach((star, index) => {
star.addEventListener('click', () => {
Actions.rateMovie(index + 1);
this.render();
});
stars.forEach((star, index) => {
star.addEventListener('click', () => {
Actions.rateMovie(index + 1);
this.render();
});
if (this.#movie?.userRating === 0) {
star.addEventListener('mouseenter', () => {
this.highlightStars(index);
});
star.addEventListener('mouseleave', () => {
this.resetStars();
});
});
}
}
});
}

highlightStars(index: number) {
Expand Down Expand Up @@ -102,18 +102,19 @@ export class RateBlock {
}
}

deleteRating() {
const deleteRatingButton = document.getElementById(
'rate-block-delete-rate-button',
) as HTMLElement;
// не удалять
// deleteRating() {
// const deleteRatingButton = document.getElementById(
// 'rate-block-delete-rate-button',
// ) as HTMLElement;

if (deleteRatingButton) {
deleteRatingButton.addEventListener('click', () => {
Actions.deleteRating();
this.render();
});
}
}
// if (deleteRatingButton) {
// deleteRatingButton.addEventListener('click', () => {
// Actions.deleteRating();
// this.render();
// });
// }
// }

renderTemplate() {
this.#parent.innerHTML = template({
Expand All @@ -126,6 +127,6 @@ export class RateBlock {
this.handleAuthClick();
this.coloringInitialRatingStars();
this.handleStarsHover();
this.deleteRating();
// this.deleteRating(); // не удалять
}
}
7 changes: 0 additions & 7 deletions public/components/RateModalBlock/RateModalBlock.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@
id='modal-rate-block-rate-button'
class='button rate-modal-block__content_add-rate'
>Оценить</button>
{{#if isUserVoted}}
<button
id='modal-rate-block-remove-rate-button'
class='button rate-modal-block__content_remove-rate'
>Удалить</button>

{{/if}}

</div>

Expand Down
2 changes: 1 addition & 1 deletion public/components/RateModalBlock/RateModalBlock.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}

&__content {
height: 320px;
height: 280px;
max-height: 100vh;
width: 100%;
max-width: 1150px;
Expand Down
25 changes: 13 additions & 12 deletions public/components/RateModalBlock/RateModalBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ export class RateModalBlock {
}
}

handleDeleteRatingClick() {
const deleteRatingButton = document.getElementById(
'modal-rate-block-remove-rate-button',
);
if (deleteRatingButton) {
deleteRatingButton.addEventListener('click', () => {
Actions.deleteRating();
this.hideModal();
});
}
}
// не удалять
// handleDeleteRatingClick() {
// const deleteRatingButton = document.getElementById(
// 'modal-rate-block-remove-rate-button',
// );
// if (deleteRatingButton) {
// deleteRatingButton.addEventListener('click', () => {
// Actions.deleteRating();
// this.hideModal();
// });
// }
// }

hideModal() {
const rateSheet = document.getElementById(
Expand Down Expand Up @@ -113,6 +114,6 @@ export class RateModalBlock {
this.handleRatingScrolling();
this.displayInitialRating();
this.handleRateClick();
this.handleDeleteRatingClick();
// this.handleDeleteRatingClick(); //не удалять
}
}
4 changes: 2 additions & 2 deletions public/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { User } from 'types/user';

export const PREV_HOST = 'http://185.241.195.151/';
export const HOST = 'https://cassette-world.ru/';
// export const API_URL = HOST + 'api/';
export const API_URL = 'http://localhost:8080/api/';
export const API_URL = HOST + 'api/';
// export const API_URL = 'http://localhost:8080/api/';

export const GRID_MOVIES_AMOUNT = 3;

Expand Down
17 changes: 8 additions & 9 deletions public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ root.appendChild(footerElement);
root.appendChild(notifierElement);
root.appendChild(previewElement);

// if ('serviceWorker' in navigator) {
// console.log('serviceWorker is supported');
// navigator.serviceWorker
// .register('sw.js', { scope: '/' })
// .then(() => console.log('serviceWorker has been registered'))
// .catch((err) => {
// console.log('SW ERR: ', err);
// });
// }
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('sw.js', { scope: '/' })
.then(() => console.log('serviceWorker has been registered'))
.catch((err) => {
console.log('SW ERR: ', err);
});
}

initialStore.start();
router.start();
4 changes: 2 additions & 2 deletions public/modules/Serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const serializeMovieDetailed = (movie: any) => {
}),
isFromFavorites: movie.is_favorite,
//For rating test
userRating: 7,
userRating: movie.rating_user,
};
};

Expand Down Expand Up @@ -122,7 +122,7 @@ export const serializeUserData = (user: any) => {
birthdate: user.birthdate,
sex: user.sex,
avatar: HOST + user.avatar_url,
isPremium: user.subscription_status,
isPremium: true,
expirationDate: user.subscription_expiration_date,
};
};
Expand Down
5 changes: 4 additions & 1 deletion public/pages/ProfilePage/ProfilePage.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
<img
class='user__image-field_input_label_icon'
src='/assets/icons/upload.svg'
/>Выбрать изображение</label>
/>
{{! <span class='user__image-field_input_label_sub'>До 1мБ, png/jpg/jpeg</span> }}
Выбрать изображение</label>

<span class='user__file_error' id='user-image-type-error'></span>
</div>
<div class='user__text-fields'>
Expand Down
19 changes: 18 additions & 1 deletion public/pages/ProfilePage/ProfilePage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,15 @@
display: none;

&_label {
position: relative;

display: flex;
align-items: center;
gap: 8px;
font-size: $font-size-medium;
border: 1.5px solid $brand;
padding: 0.5em 1em;
padding: 0.5em 1em 1em 1em;

border-radius: 0.5em;
transition: transform 0.2s ease;

Expand All @@ -110,6 +113,15 @@
width: 24px;
user-select: none;
}

&_sub {
color: $text-secondary-color;
font-size: 12px;
bottom: 2px;
font-weight: 300;
right: 20%;
position: absolute;
}
}
}
}
Expand Down Expand Up @@ -296,6 +308,11 @@
&_input {
&_label {
font-size: 14px;

&_sub {
font-size: 10px;
right: 25%;
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions public/pages/ProfilePage/ProfilePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ export class ProfilePage {
this.#userAvatar = file;
this.renderAvatar(avatarUrl);
this.controlButtonDisable();
const notifier = new Notifier('info', 'Изображение загружено', 3000);
notifier.render();
}
}
}
Expand Down
42 changes: 19 additions & 23 deletions public/store/MoviePageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'modules/Serializer';
import { userStore } from './UserStore';
import { ErrorPage } from 'pages/ErrorPage/ErrorPage';
import { Notifier } from 'components/Notifier/Notifier';

const moviePage = new MoviePage();

Expand Down Expand Up @@ -222,42 +223,37 @@ class MoviePageStore {
}

async rateMovieRequest(rating: number) {
const tmp = this.#movie?.userRating;
try {
// const response = await apiClient.post({
// path: 'rate',
// body: { rate: rating },
// });
console.log(`Фильм ${this.#movie?.title} оценен на ${rating}`);
if (this.#movie?.userRating !== undefined) {
this.#movie.userRating = rating;
}
await apiClient.post({
path: `movies/${this.#movie?.id}/rating`,
body: { rating: rating },
});
if (this.#movie?.userRating !== undefined) {
this.#movie.userRating = rating;
}
} catch (e) {
console.log(e);
if (this.#movie?.userRating !== undefined) {
this.#movie.userRating = tmp;
}
const not = new Notifier('error', 'Что-то пошло не так', 2000);
not.render();
}

// if (this.#movie?.userRating !== undefined) {
// this.#movie.userRating = rating;
// }
// console.log(`Фильм ${this.#movie?.title} оценен на ${rating}`);
}

// не удалять
async deleteRatingRequest() {
try {
// const response = await apiClient.delete({
// path: 'rate',
// });
console.log(`Удалена оценка с ${this.#movie?.title}`);
const response = await apiClient.delete({
path: `movies/${this.#movie?.id}/rating`,
});
if (this.#movie?.userRating) {
this.#movie.userRating = 0;
}
} catch (e) {
console.log(e);
}

// if (this.#movie?.userRating) {
// this.#movie.userRating = 0;
// }
// console.log(`Удалена оценка с ${this.#movie?.title}`);
} catch (e) {}
}

async reduce(action: any) {
Expand Down
1 change: 0 additions & 1 deletion public/store/SearchBlockStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class SearchBlockStore {
const response = await apiClient.get({
path: `movies/movies/search?query=${searchQuery}`,
});
console.log(response);
this.#findItems = response.map((movie: Movie) => {
return serializeMovie(movie);
});
Expand Down
Loading

0 comments on commit 12cd6f0

Please sign in to comment.