mirror of
https://github.com/ershisan99/vacancies-trends-front.git
synced 2026-02-01 21:02:08 +00:00
add index page
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { json, MetaFunction } from '@remix-run/node'
|
||||
import { vacanciesService } from '~/services/vacancies/vacancies.service'
|
||||
import { useLoaderData } from '@remix-run/react'
|
||||
import { VacanciesChart } from '~/components/vacancies-chart'
|
||||
import type { ShouldRevalidateFunction } from '@remix-run/react'
|
||||
import { Link, ShouldRevalidateFunction, useLoaderData } from '@remix-run/react'
|
||||
import { Tooltip } from '~/components/ui/tooltip'
|
||||
|
||||
export const shouldRevalidate: ShouldRevalidateFunction = ({ nextParams }) => {
|
||||
return !nextParams
|
||||
}
|
||||
|
||||
export const meta: MetaFunction = () => {
|
||||
return [
|
||||
{ title: 'Vacancies trends' },
|
||||
@@ -15,15 +15,48 @@ export const meta: MetaFunction = () => {
|
||||
}
|
||||
|
||||
export const loader = async () => {
|
||||
const promises = [
|
||||
vacanciesService.getAggregateByCreatedAt(),
|
||||
vacanciesService.getKeywords(),
|
||||
] as const
|
||||
const [vacancies, keywords] = await Promise.all(promises)
|
||||
return json({ vacancies, keywords })
|
||||
const keywords = await vacanciesService.getKeywords()
|
||||
return json({ keywords })
|
||||
}
|
||||
|
||||
export default function Index() {
|
||||
const { vacancies, keywords } = useLoaderData<typeof loader>()
|
||||
return <VacanciesChart data={vacancies} keywords={keywords} />
|
||||
const { keywords } = useLoaderData<typeof loader>()
|
||||
return (
|
||||
<div>
|
||||
<h1 className={'text-2xl font-semibold mb-6'}>Compare vacancies trends over time</h1>
|
||||
<div className={'flex flex-col gap-2'} role={'list'}>
|
||||
{Object.entries(keywords?.presets ?? {}).map(([label, values]) => {
|
||||
if (values.length === 0) return null
|
||||
|
||||
return (
|
||||
<Tooltip content={<TooltipContent values={values} />} key={label}>
|
||||
<Link
|
||||
role={'listitem'}
|
||||
className={'text-blue-300 hover:underline w-max'}
|
||||
to={{
|
||||
pathname: '/trends',
|
||||
search: new URLSearchParams({
|
||||
preset: label,
|
||||
categories: values.join(','),
|
||||
}).toString(),
|
||||
}}
|
||||
>
|
||||
{label}
|
||||
</Link>
|
||||
</Tooltip>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const TooltipContent = ({ values }: { values: string[] }) => {
|
||||
return (
|
||||
<div>
|
||||
{[...values].sort().map(v => (
|
||||
<div key={v}>{v}</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
40
app/routes/trends/route.tsx
Normal file
40
app/routes/trends/route.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { json, 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'
|
||||
|
||||
export const shouldRevalidate: ShouldRevalidateFunction = ({ nextParams }) => {
|
||||
return !nextParams
|
||||
}
|
||||
export const meta: MetaFunction = ({ location }) => {
|
||||
const preset = new URLSearchParams(location.search).get('preset')
|
||||
|
||||
return [
|
||||
{ title: preset ? `Vacancies trends for ${preset}` : 'Vacancies trends' },
|
||||
{ name: 'description', content: 'See how software vacancies change over time' },
|
||||
]
|
||||
}
|
||||
|
||||
export const loader = async () => {
|
||||
const promises = [
|
||||
vacanciesService.getAggregateByCreatedAt(),
|
||||
vacanciesService.getKeywords(),
|
||||
] as const
|
||||
const [vacancies, keywords] = await Promise.all(promises)
|
||||
return json({ vacancies, keywords })
|
||||
}
|
||||
|
||||
export default function Trends() {
|
||||
const { vacancies, keywords } = useLoaderData<typeof loader>()
|
||||
const [searchParams] = useSearchParams()
|
||||
const preset = searchParams.get('preset')
|
||||
const heading = preset ? `Trends for ${preset}` : 'Trends'
|
||||
|
||||
return (
|
||||
<div className={'flex h-full flex-col gap-6'}>
|
||||
<h1 className={'text-2xl font-semibold'}>{heading}</h1>
|
||||
<VacanciesChart data={vacancies} keywords={keywords} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user