add grouping and totals

This commit is contained in:
2024-08-29 02:32:30 +02:00
parent 796d866a33
commit bfb0949c25
13 changed files with 636 additions and 25 deletions

View File

@@ -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)