Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
275 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React, { useMemo } from 'react' | ||
import CompaniesView from 'src/pages/Companies/View' | ||
import { CityPageViewProps } from './interfaces' | ||
|
||
const CityPageView: React.FC<CityPageViewProps> = ({ | ||
city, | ||
companies, | ||
...other | ||
}) => { | ||
return useMemo(() => { | ||
return ( | ||
<> | ||
<CompaniesView companies={companies} city={city} {...other} /> | ||
</> | ||
) | ||
}, [companies, city, other]) | ||
} | ||
|
||
export default CityPageView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { CityFragment } from 'src/modules/gql/generated' | ||
import { CompaniesViewProps } from 'src/pages/Companies/View/interfaces' | ||
|
||
export type CityPageViewProps = { | ||
city: CityFragment | ||
} & CompaniesViewProps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { NextSeo } from 'next-seo' | ||
import { useRouter } from 'next/router' | ||
import { ParsedUrlQuery } from 'querystring' | ||
import React, { useMemo } from 'react' | ||
import { | ||
QueryCompaniesArgs, | ||
useCompaniesQuery, | ||
} from 'src/modules/gql/generated' | ||
import { Page } from 'src/pages/_App/interfaces' | ||
import { CityPageProps } from './interfaces' | ||
import CityPageView from './View' | ||
|
||
/** | ||
* Параметры для запроса компаний | ||
*/ | ||
export const getCompaniesVariables = ({ | ||
city, | ||
query, | ||
}: { | ||
city: CityPageProps['city'] | undefined | ||
query: ParsedUrlQuery | ||
}): { | ||
variables: QueryCompaniesArgs | ||
page: number | ||
} => { | ||
let skip: number | undefined | ||
|
||
const take = 10 | ||
|
||
const page = | ||
(query.page && typeof query.page === 'string' && parseInt(query.page)) || 0 | ||
|
||
if (page > 1) { | ||
skip = (page - 1) * take | ||
} | ||
|
||
const variables: QueryCompaniesArgs = { | ||
take: 12, | ||
skip, | ||
} | ||
|
||
if (city?.coords) { | ||
variables.orderBy = { | ||
coords: { | ||
lat: city.coords.lat, | ||
lng: city.coords.lng, | ||
}, | ||
} | ||
} | ||
|
||
return { | ||
variables, | ||
page, | ||
} | ||
} | ||
|
||
const CityPage: Page<CityPageProps> = ({ city, ...other }) => { | ||
const router = useRouter() | ||
|
||
const { variables, page } = useMemo(() => { | ||
return getCompaniesVariables({ | ||
city, | ||
query: router.query, | ||
}) | ||
}, [city, router.query]) | ||
|
||
const companiesResponse = useCompaniesQuery({ | ||
variables, | ||
}) | ||
|
||
return useMemo(() => { | ||
return ( | ||
<> | ||
<NextSeo | ||
title={`Общественные бани в городе "${city.pagetitle}"`} | ||
description={`Все общественные бани и сауны в городе "${city.pagetitle}"`} | ||
/> | ||
<CityPageView | ||
city={city} | ||
companies={companiesResponse.data?.companies || []} | ||
pagination={{ | ||
page, | ||
limit: companiesResponse.variables?.take || 0, | ||
total: 100, | ||
}} | ||
{...other} | ||
/> | ||
</> | ||
) | ||
}, [ | ||
city, | ||
companiesResponse.data?.companies, | ||
companiesResponse.variables?.take, | ||
other, | ||
page, | ||
]) | ||
} | ||
|
||
export default CityPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { PageProps } from 'src/pages/_App/interfaces' | ||
import { CityPageViewProps } from './View/interfaces' | ||
|
||
export type CityPageProps = PageProps & { | ||
city: CityPageViewProps['city'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import { CompaniesQuery } from 'src/modules/gql/generated' | ||
import { PaginationProps } from 'src/components/ui/Pagination' | ||
import { CityFragment, CompaniesQuery } from 'src/modules/gql/generated' | ||
|
||
export type CompaniesViewProps = { | ||
companies: CompaniesQuery['companies'] | ||
city: CityFragment | undefined | ||
pagination: PaginationProps | undefined | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { PageProps } from '../_App/interfaces' | ||
import { CityFragment } from 'src/modules/gql/generated' | ||
|
||
export type MainPageProps = { | ||
city: CityFragment | undefined | ||
} & PageProps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.