mirror of
https://github.com/ershisan99/vacancies-trends-front.git
synced 2026-02-02 05:12:07 +00:00
add grouping and totals
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { json, MetaFunction } from '@remix-run/node'
|
||||
import { json, LoaderFunctionArgs, MetaFunction } from '@remix-run/node'
|
||||
import { vacanciesService } from '~/services/vacancies/vacancies.service'
|
||||
import { useLoaderData, useSearchParams } from '@remix-run/react'
|
||||
import { VacanciesChart } from '~/components/vacancies-chart'
|
||||
import type { ShouldRevalidateFunction } from '@remix-run/react'
|
||||
import { GroupByPeriod } from '~/services/vacancies/vacancies.types'
|
||||
|
||||
export const shouldRevalidate: ShouldRevalidateFunction = ({ nextParams }) => {
|
||||
return !nextParams
|
||||
export const shouldRevalidate: ShouldRevalidateFunction = ({ currentUrl, nextUrl }) => {
|
||||
return currentUrl.searchParams.get('groupBy') !== nextUrl.searchParams.get('groupBy')
|
||||
}
|
||||
export const meta: MetaFunction = ({ location }) => {
|
||||
const preset = new URLSearchParams(location.search).get('preset')
|
||||
@@ -16,9 +17,13 @@ export const meta: MetaFunction = ({ location }) => {
|
||||
]
|
||||
}
|
||||
|
||||
export const loader = async () => {
|
||||
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
const url = new URL(request.url)
|
||||
const groupByParam = url.searchParams.get('groupBy')
|
||||
const groupBy = groupByParam ? (groupByParam as GroupByPeriod) : GroupByPeriod.DAY
|
||||
|
||||
const promises = [
|
||||
vacanciesService.getAggregateByCreatedAt(),
|
||||
vacanciesService.getAggregateByCreatedAt({ groupBy }),
|
||||
vacanciesService.getKeywords(),
|
||||
] as const
|
||||
const [vacancies, keywords] = await Promise.all(promises)
|
||||
|
||||
Reference in New Issue
Block a user