Skip to content

Commit

Permalink
Merge pull request #587 from Studio-Yandex-Practicum/intersection-obs…
Browse files Browse the repository at this point in the history
…erver-polyfill

Добавление полифила IntersectionObserver
  • Loading branch information
AntonZelinsky authored Sep 20, 2024
2 parents 64e7cf9 + efc589a commit 6020af5
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 76 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"classnames": "2.3.1",
"date-fns": "2.29.3",
"express": "4.17.2",
"intersection-observer": "0.12.2",
"keen-slider": "6.8.5",
"lodash": "4.17.21",
"next": "12.0.8",
Expand Down
2 changes: 1 addition & 1 deletion src/components/donation-link/donation-link.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}

&:hover,
&.active {
&.active {
&::before,
&::after {
visibility: visible;
Expand Down
4 changes: 2 additions & 2 deletions src/components/main-header/main-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Menu } from 'components/ui/menu';
import { donationPath } from 'shared/constants/donation-path';
import { mainNavigationItems } from 'shared/constants/main-navigation-items';
import { socialLinkItems } from 'shared/constants/social-link-items';
import { useIntersectionObserver } from 'shared/hooks/use-intersection-observer';
import { useIntersection } from 'shared/hooks/use-intersection';

import styles from './main-header.module.css';

Expand All @@ -35,7 +35,7 @@ export const MainHeader: React.VFC<MainHeaderProps> = (props) => {
} = props;

const router = useRouter();
const [containerElRef, isContainerElInViewport] = useIntersectionObserver({ threshold: 0.1 });
const [containerElRef, isContainerElInViewport] = useIntersection({ threshold: 0.1 });

return (
<div
Expand Down
14 changes: 8 additions & 6 deletions src/components/main-layout/feed/main-layout-feed.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@
}

/* Псевдоэлемент для создания дополнительной зоны, где скрытие не будет происходить сразу */
&:after {
content: '';
&::after {
position: absolute;
z-index: -1; /* Псевдоэлемент не будет влиять на другие элементы */
top: -40px; /* 40px выше блока */
left: -40px; /* 40px левее блока */
right: -40px; /* 40px правее блока */
bottom: -40px;/* 40px ниже блока */
z-index: -1; /* Псевдоэлемент не будет влиять на другие элементы */
bottom: -40px;
left: -40px; /* 40px левее блока */
content: "";

/* 40px ниже блока */
}

/* Если курсор покидает расширенную область, блок скрывается */
&:not(:hover):after {
&:not(:hover)::after {
transition-delay: .4s; /* Добавляем небольшую задержку перед скрытием */
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/navbar/navbar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
right: 0;
bottom: 0;
display: block;
border-right: 1px solid black;
height: 80%;
border-right: 1px solid black;
background-color: var(--coal);
content: "";
}
Expand Down
18 changes: 11 additions & 7 deletions src/pages/[author].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { PlayList } from 'components/play-list';
import { Section } from 'components/section';
import { SEO } from 'components/seo';
import { useSettings } from 'services/api/settings-adapter';
import { fetcher } from 'services/fetcher';
import { fetcher, HttpRequestError } from 'services/fetcher';
import * as breakpoints from 'shared/breakpoints.js';
import { notFoundResult } from 'shared/constants/server-side-props';
import { InternalServerError } from 'shared/helpers/internal-server-error';
Expand Down Expand Up @@ -114,13 +114,17 @@ export const getServerSideProps = async ({ params }: GetServerSidePropsContext<R

try {
author = await fetcher<AuthorRetrieve>(`/library/authors/${slug}/`);
} catch ({ statusCode }) {
switch (statusCode) {
case 404:
return notFoundResult;
default:
throw new InternalServerError();
} catch (error) {
if (error instanceof HttpRequestError) {
switch (error.response.statusCode) {
case 404:
return notFoundResult;
default:
throw new InternalServerError();
}
}

throw error;
}

return {
Expand Down
18 changes: 11 additions & 7 deletions src/pages/blog/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { PageBreadcrumbs } from 'components/page';
import { Section } from 'components/section';
import { SEO } from 'components/seo';
import { ShareLinks } from 'components/share-links';
import { fetcher } from 'services/fetcher';
import { fetcher, HttpRequestError } from 'services/fetcher';
import { notFoundResult } from 'shared/constants/server-side-props';
import { InternalServerError } from 'shared/helpers/internal-server-error';

Expand Down Expand Up @@ -106,13 +106,17 @@ export const getServerSideProps = async ({ params }: GetServerSidePropsContext<R

try {
data = await fetcher<BlogItemDetailOutput>(`/blog/${id}/`);
} catch ({ statusCode }) {
switch (statusCode) {
case 404:
return notFoundResult;
default:
throw new InternalServerError();
} catch (error) {
if (error instanceof HttpRequestError) {
switch (error.response.statusCode) {
case 404:
return notFoundResult;
default:
throw new InternalServerError();
}
}

throw error;
}

return {
Expand Down
26 changes: 15 additions & 11 deletions src/pages/history/[year].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { HistoryTitle } from 'components/history-page/title';
import { SEO } from 'components/seo';
import { Menu } from 'components/ui/menu';
import { fetchSettings } from 'services/api/settings-adapter';
import { fetcher } from 'services/fetcher';
import { fetcher, HttpRequestError } from 'services/fetcher';
import { notFoundResult } from 'shared/constants/server-side-props';
import { InternalServerError } from 'shared/helpers/internal-server-error';
import { useHorizontalScroll } from 'shared/hooks/use-horizontal-scroll';
Expand Down Expand Up @@ -45,7 +45,7 @@ const History = (props: InferGetServerSidePropsType<typeof getServerSideProps>)
<HistoryTitle
data={festival}
currentYear={defaultYear}
showVolunteers={showVolunteers}
showVolunteers={showVolunteers}
/>
<HistoryItself data={itselfData}/>
</AppLayout>
Expand All @@ -71,19 +71,23 @@ export const getServerSideProps = async ({ params }: GetServerSidePropsContext<R
? Number(params.year)
: years[0];

festival = await fetcher<Festival>(`/info/festivals/${defaultYear}/`);
festival = await fetcher<Festival>(`/info/festivals/${defaultYear}/`);

} catch ({ statusCode }) {
switch (statusCode) {
case 404:
return notFoundResult;
default:
throw new InternalServerError();
} catch (error) {
if (error instanceof HttpRequestError) {
switch (error.response.statusCode) {
case 404:
return notFoundResult;
default:
throw new InternalServerError();
}
}

throw error;
}
const settings = await fetchSettings(); // Semicolon added
const settings = await fetchSettings();
const showVolunteers = settings.permissions.show_volunteers;

return {
props: {
festival,
Expand Down
18 changes: 11 additions & 7 deletions src/pages/news/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { PageBreadcrumbs } from 'components/page';
import { Section } from 'components/section';
import { SEO } from 'components/seo';
import { ShareLinks } from 'components/share-links';
import { fetcher } from 'services/fetcher';
import { fetcher, HttpRequestError } from 'services/fetcher';
import { notFoundResult } from 'shared/constants/server-side-props';
import { InternalServerError } from 'shared/helpers/internal-server-error';

Expand Down Expand Up @@ -94,13 +94,17 @@ export const getServerSideProps = async ({ params }: GetServerSidePropsContext<R

try {
data = await fetcher<NewsItemDetail>(`/news/${id}/`);
} catch ({ statusCode }) {
switch (statusCode) {
case 404:
return notFoundResult;
default:
throw new InternalServerError();
} catch (error) {
if (error instanceof HttpRequestError) {
switch (error.response.statusCode) {
case 404:
return notFoundResult;
default:
throw new InternalServerError();
}
}

throw error;
}

return {
Expand Down
18 changes: 11 additions & 7 deletions src/pages/performances/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Section } from 'components/section';
import { SEO } from 'components/seo';
import { ShareLinks } from 'components/share-links';
import { Video } from 'components/video';
import { fetcher } from 'services/fetcher';
import { fetcher, HttpRequestError } from 'services/fetcher';
import { notFoundResult } from 'shared/constants/server-side-props';
import { InternalServerError } from 'shared/helpers/internal-server-error';
import { isNonEmpty } from 'shared/helpers/is-non-empty';
Expand Down Expand Up @@ -209,13 +209,17 @@ export const getServerSideProps = async ({ params }: GetServerSidePropsContext<R
fetcher<PaginatedPerformanceMediaReviewList>(`/afisha/performances/${performanceId}/media-reviews/`),
fetcher<PaginatedPerformanceReviewList>(`/afisha/performances/${performanceId}/reviews/`),
]);
} catch ({ statusCode }) {
switch (statusCode) {
case 404:
return notFoundResult;
default:
throw new InternalServerError();
} catch (error) {
if (error instanceof HttpRequestError) {
switch (error.response.statusCode) {
case 404:
return notFoundResult;
default:
throw new InternalServerError();
}
}

throw error;
}

return {
Expand Down
26 changes: 0 additions & 26 deletions src/shared/hooks/use-intersection-observer.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/shared/hooks/use-intersection.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'intersection-observer';
import { useEffect, useRef, useState, useCallback } from 'react';

import type { RefCallback } from 'react';
Expand All @@ -20,7 +21,7 @@ export const useIntersection = <T extends Element>(options?: IntersectionObserve
};

useEffect(() => {
if ('IntersectionObserver' in window) {
if (typeof IntersectionObserver !== 'undefined') {
observerRef.current = new IntersectionObserver(handleIntersection, options);
}
}, [options]);
Expand Down

0 comments on commit 6020af5

Please sign in to comment.