|
1 | | -import React from 'react' |
2 | | -import JobsTable from '@/components/jobs/JobsTable' |
3 | | -import VideoPlayer from '../../components/video-player' |
| 1 | +"use client" |
4 | 2 |
|
| 3 | +import React, { useEffect, useState } from 'react' |
| 4 | +import JobsTable from '@/components/jobs/JobsTable' |
5 | 5 |
|
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) |
8 | 10 | const postsPerPage = 10 |
9 | | - const currentPage = parseInt(searchParams.page || '1', 10) |
10 | 11 |
|
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]) |
19 | 29 |
|
20 | 30 | return ( |
21 | 31 | <div className="flex flex-col inset-0 z-50 bg-primary transition-transform"> |
|
0 commit comments