Skip to content

Commit

Permalink
feat: fix infinite scroll (#325)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Luisfp0 and github-actions[bot] authored Oct 4, 2024
1 parent 7efccf0 commit f422a7f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion apps/web/app/(roles)/vagas/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const fetchJobs = async (
ascending: orderOption[0].option.value === 'ascending',
})
} else {
query = query.order('createdAt', { ascending: true })
query = query.order('salary', { nullsFirst: false })
}

if (type === 'refetch') {
Expand Down
23 changes: 12 additions & 11 deletions apps/web/app/(roles)/vagas/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RolesPage } from './RolesPage'
import { createClient } from '@supabase/supabase-js'
import { createClient as createClientRedis } from 'redis'
import { fetchJobs } from './action'

export const revalidate = 0

Expand All @@ -27,16 +28,17 @@ async function getJobs() {
return JSON.parse(jobsFromCache)
}

const { data: jobs } = await supabase
.from('Roles')
.select('*', { count: 'exact' })
.eq('ready', true)
.order('salary', { nullsFirst: false })
.limit(21)
const result = await fetchJobs('initial', [], [])

await client.set('web_jobs', JSON.stringify(jobs), { EX: ONE_DAY_IN_MINUTES })

return jobs
if (result.isSuccess && result.data) {
await client.set('web_jobs', JSON.stringify(result.data), {
EX: ONE_DAY_IN_MINUTES,
})
return result.data
} else {
console.error('Failed to fetch jobs:', result.message)
return []
}
}

async function getSkills() {
Expand Down Expand Up @@ -71,11 +73,10 @@ export default async function Page() {
const skills = await getSkills()
const jobs = await getJobs()
const countries = await getCountries()
const jobsReady = jobs.filter((job) => job.ready === true)

return (
<RolesPage
jobsFromServer={jobsReady}
jobsFromServer={jobs}
skillsFromServer={skills}
countries={countries}
/>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web",
"version": "1.0.36",
"version": "1.0.37",
"private": true,
"scripts": {
"dev": "development=true next dev",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10135,7 +10135,7 @@ web-streams-polyfill@^3.0.3:
integrity sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==

"web@file:/home/runner/work/trampar-de-casa/trampar-de-casa/apps/web":
version "1.0.36"
version "1.0.37"
resolved "file:apps/web"
dependencies:
"@headlessui/react" "^1.7.15"
Expand Down

0 comments on commit f422a7f

Please sign in to comment.