Skip to content
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

Diploma (frontend) +JS #52

Merged
merged 2 commits into from
Jul 10, 2023
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* Frontend: https://movies-explorer.nomoredomains.rocks
* Backend: https://api.movies-explorer.nomoredomains.rocks
***
* Pull Request: https://github.com/MalakhN/movies-explorer-frontend/pull/51
* Pull Request: https://github.com/MalakhN/movies-explorer-frontend/pull/52
6 changes: 3 additions & 3 deletions src/components/Movies/Movies.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ function Movies({ movies, moviesError, savedMovies, onToggleLike }) {
}, []);

const renderMovies = React.useMemo(() => {
const cardsCounter = screenWidth < 768 ? 5 : screenWidth < 1280 ? 8 : 12;
const cardsCounter = screenWidth < 808 ? 5 : screenWidth < 1195 ? 8 : 12;
return filteredMovies.slice(0, cardsCounter + nextMovies);
}, [nextMovies, screenWidth, filteredMovies]);

const handleClickButtonMore = () => {
if (screenWidth < 1280) {
if (screenWidth < 1195) {
setNextMovies((prev) => prev + 2);
} else if (screenWidth >= 1280) {
} else if (screenWidth >= 1195) {
setNextMovies((prev) => prev + 3);
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/components/Movies/MoviesCard/MoviesCard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { useLocation, Link } from "react-router-dom";
import { movieLengthConv } from "../../../utils/movieLengthConv";
import "./MoviesCard.css";

function MoviesCard({ movie, savedMovies, onToggleLike, onRemoveMovie }) {
Expand Down Expand Up @@ -29,7 +30,7 @@ function MoviesCard({ movie, savedMovies, onToggleLike, onRemoveMovie }) {
<article className="movies-card">
<div className="movies-card__title-container">
<span className="movies-card__name">{movie.nameRU}</span>
<span className="movies-card__duration">{movie.duration} минут</span>
<span className="movies-card__duration">{movieLengthConv(movie.duration)}</span>
</div>
<Link
className="movies-card__trailer-link"
Expand Down
12 changes: 8 additions & 4 deletions src/components/NotFound/NotFound.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from "react";
import "./NotFound.css";
import {useNavigate} from "react-router-dom";
import { useNavigate } from "react-router-dom";

function NotFound() {
function NotFound({ loggedIn }) {
const navigate = useNavigate();

function handleBackButtonClick() {
navigate(-1);
loggedIn ? navigate(-2) : navigate('/');
}

return (
Expand All @@ -21,4 +22,7 @@ function NotFound() {
);
}

export default NotFound;
export default NotFound;



2 changes: 1 addition & 1 deletion src/components/Profile/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Profile(props) {
<div className="profile__container">
<h1 className="profile__title">Привет, {currentUser.name}!</h1>
<ProfileForm onUpdateProfile={props.onUpdateProfile} serverError={props.serverError} isRequestSuccessful={props.isRequestSuccessful} />
<Link to="/signin" className="profile__exit-button" onClick={props.onSignOut}>
<Link to="/" className="profile__exit-button" onClick={props.onSignOut}>
Выйти из аккаунта
</Link>
</div>
Expand Down
16 changes: 16 additions & 0 deletions src/utils/movieLengthConv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export function movieLengthConv(mins) {
const hours = Math.floor(mins / 60);
const minutes = mins % 60;

if (mins < 60) {
return `${mins} минут`
} else if (minutes > 0) {
return `${hours}ч ${minutes}м`;
} else if (hours = 1) {
return `${hours} час`;
} else if (hours != 1 && hours <= 4) {
return `${hours} часа`;
} else {
return `${hours} часов`;
}
}