Skip to content

Commit d1991bc

Browse files
Made page static friendly.
1 parent 0241aa4 commit d1991bc

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

src/app/jobs/page.tsx

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1-
import React from 'react'
2-
import JobsTable from '@/components/jobs/JobsTable'
3-
import VideoPlayer from '../../components/video-player'
1+
"use client"
42

3+
import React, { useEffect, useState } from 'react'
4+
import JobsTable from '@/components/jobs/JobsTable'
55

6-
export default async function Home(props: { searchParams: Promise<{ page?: string }> }) {
7-
const searchParams = await props.searchParams
6+
export default function Home() {
7+
const [jobs, setJobs] = useState([])
8+
const [totalJobs, setTotalJobs] = useState(0)
9+
const [currentPage, setCurrentPage] = useState(1)
810
const postsPerPage = 10
9-
const currentPage = parseInt(searchParams.page || '1', 10)
1011

11-
// Fetch jobs from external API
12-
const res = await fetch(`https://api.codebuilder.org/jobs?page=${currentPage}&limit=${postsPerPage}`)
13-
if (!res.ok) {
14-
throw new Error('Failed to fetch jobs from external API')
15-
}
16-
const data = await res.json()
17-
const jobs = data.jobs || []
18-
const totalJobs = data.total || 0
12+
useEffect(() => {
13+
// Get page from URL search params
14+
const params = new URLSearchParams(window.location.search)
15+
const page = parseInt(params.get('page') || '1', 10)
16+
setCurrentPage(page)
17+
18+
fetch(`https://api.codebuilder.org/jobs?page=${page}&limit=${postsPerPage}`)
19+
.then(res => res.json())
20+
.then(data => {
21+
setJobs(data.jobs || [])
22+
setTotalJobs(data.total || 0)
23+
})
24+
.catch(() => {
25+
setJobs([])
26+
setTotalJobs(0)
27+
})
28+
}, [window.location.search])
1929

2030
return (
2131
<div className="flex flex-col inset-0 z-50 bg-primary transition-transform">

0 commit comments

Comments
 (0)