Skip to content

Commit

Permalink
Merge pull request #589 from Studio-Yandex-Practicum/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
AntonZelinsky authored Sep 22, 2024
2 parents b1fce33 + 2e9c48c commit 46599ca
Show file tree
Hide file tree
Showing 22 changed files with 177 additions and 95 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
27 changes: 13 additions & 14 deletions src/components/app-layout/app-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import { mainNavigationItems } from 'shared/constants/main-navigation-items';
import { participationFormPath } from 'shared/constants/participation-form-path';
import { socialLinkItems } from 'shared/constants/social-link-items';
import { useDisableBodyScroll } from 'shared/hooks/use-disable-body-scroll';
import { useEffectSkipMount } from 'shared/hooks/use-effect-skip-mount';
import { useMediaQuery } from 'shared/hooks/use-media-query';
import useOrientation from 'shared/hooks/use-orientation';

import type { NavbarProps } from 'components/navbar';

Expand All @@ -42,12 +44,15 @@ export const AppLayout: React.VFC<React.PropsWithChildren<AppLayoutProps>> = (pr
navbarAddon,
hiddenPartners,
} = props;

const router = useRouter();
const { settings } = useSettings();
const { partners } = usePartners({ onlyGeneral: true });
const isMobile = useMediaQuery(`(max-width: ${breakpoints['tablet-portrait']})`);
const screenOrientation = useOrientation();

const [isOverlayMenuOpen, setIsOverlayMenuOpen] = useState(false);
const [scrollPosition, setScrollPosition] = useState(0);
const isMobile = useMediaQuery(`(max-width: ${breakpoints['tablet-portrait']})`);
const router = useRouter();

const toggleOverlayMenu = useCallback(() => {
setIsOverlayMenuOpen(!isOverlayMenuOpen);
Expand All @@ -61,19 +66,13 @@ export const AppLayout: React.VFC<React.PropsWithChildren<AppLayoutProps>> = (pr
}
}, [isMobile]);

useEffect(() => {
const onChange = () => {
setScrollPosition(window.scrollY);
if (screen.orientation.type === 'landscape-primary') {
window.scroll(0, scrollPosition * (window.outerWidth / window.outerHeight));
}
};
screen.orientation.addEventListener('change', onChange);
useEffectSkipMount(() => {
setScrollPosition(window.scrollY);

return () => {
screen.orientation.removeEventListener('change', onChange);
};
}, [scrollPosition]);
if (screenOrientation === 'landscape-primary') {
window.scroll(0, scrollPosition * (window.outerWidth / window.outerHeight));
}
}, [screenOrientation]);

return (
<Page>
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
9 changes: 9 additions & 0 deletions src/components/event-card/event-card.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,12 @@
}
}
}

.timeZone {
@mixin text;
@mixin textSmall;

margin-left: 5px;
line-height: 1;
vertical-align: super;
}
3 changes: 3 additions & 0 deletions src/components/event-card/event-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export const EventCard = forwardRef<HTMLDivElement, EventCardProps>((props, ref)
</span>
<span>
{time}
<span className={cx('timeZone')}>
мск
</span>
</span>
</time>
<h3 className={cx('title')}>
Expand Down
10 changes: 10 additions & 0 deletions src/components/festival-event-card/festival-event-card.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,13 @@
}
}
}

.timeZone {
@mixin text;
@mixin textMedium;

margin-left: 5px;
font-weight: normal;
line-height: 1;
vertical-align: super;
}
3 changes: 3 additions & 0 deletions src/components/festival-event-card/festival-event-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export const FestivalEventCard: React.VFC<FestivalEventCardProps> = (props) => {
</dt>
<dd className={cx('time')}>
{time}
<span className={cx('timeZone')}>
мск
</span>
</dd>
<dt className={cx('hiddenText')}>
Место
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;
width: 1px;
height: 80%;
border-right: 1px solid black;
background-color: var(--coal);
content: "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@
min-width: 240px;
}
}

.timeZone {
@mixin text;
@mixin textLarge;

margin-left: 5px;
font-weight: normal;
line-height: 1;
vertical-align: super;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export const PerformanceEventListItem: FC<PerformanceEventListProps> = (props) =
{date && (
<time className={cx('date')}>
{date}
<span className={cx('timeZone')}>
мск
</span>
</time>
)}
{actionText && actionUrl && (
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
25 changes: 20 additions & 5 deletions src/pages/contacts/contacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,21 @@ const contactFormReducer = (state: ContactFormState, action: ContactFormAction)
}
};

const getSubmitButtonText = (formSuccessfullySent: boolean, isSubmitting: boolean) => {
if (formSuccessfullySent) {
return 'Отправлено';
}
if (isSubmitting) {
return 'Отправляется';
}

return 'Отправить';
};

const Contacts: NextPage = () => {
const [contactFormState, dispatch] = useReducer(contactFormReducer, initialContactFormState);
const [formSuccessfullySent, setFormSuccessfullySent] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
const { settings } = useSettings();

const {
Expand Down Expand Up @@ -153,6 +165,7 @@ const Contacts: NextPage = () => {

const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
setIsSubmitting(true);

const data = {
author_name: name.value,
Expand All @@ -168,6 +181,9 @@ const Contacts: NextPage = () => {
},
body: JSON.stringify(data),
});

setFormSuccessfullySent(true);
resetContactForm();
} catch (err) {
if (isHttpRequestError(err)) {
const { statusCode } = err.response;
Expand All @@ -192,10 +208,9 @@ const Contacts: NextPage = () => {
throw new InternalServerError();
}
}
} finally {
setIsSubmitting(false);
}

setFormSuccessfullySent(true);
resetContactForm();
};

const canSubmit = name.wasChanged && !name.error
Expand Down Expand Up @@ -252,11 +267,11 @@ const Contacts: NextPage = () => {
)}
iconPosition="right"
border="full"
disabled={!canSubmit}
disabled={!canSubmit || isSubmitting}
upperCase
fullWidth
>
{formSuccessfullySent ? 'Отправлено' : 'Отправить'}
{getSubmitButtonText(formSuccessfullySent, isSubmitting)}
</Button>
</Form.Actions>
<Form.Disclaimer className={styles.container}>
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
Loading

0 comments on commit 46599ca

Please sign in to comment.