From 58f7b91b9ca10899bf0517c0d300e12535502f98 Mon Sep 17 00:00:00 2001 From: Mahmoud Galal Date: Sat, 20 May 2023 04:47:21 +0300 Subject: [PATCH 01/10] init optimiztion --- components/DataGrid.tsx | 4 +--- pages/index.tsx | 6 ------ 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/components/DataGrid.tsx b/components/DataGrid.tsx index 95af523..de9842c 100644 --- a/components/DataGrid.tsx +++ b/components/DataGrid.tsx @@ -70,7 +70,7 @@ const DataTable = ( {jobs, refershData}:DataTableProps ) => { }, ], [rowId]) - + // this should be called after the set render, avoiding the limit let rows = crawlerjobs.map((crawlerjobs:Job)=>{ const {id,company,title,type,link,deadline,logo,skills}=crawlerjobs; return { @@ -115,7 +115,6 @@ const DataTable = ( {jobs, refershData}:DataTableProps ) => { } const handleConfirm = async () => { - console.log('confirm') const res = await fetch ('/api/confirm', { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -243,7 +242,6 @@ const DataTable = ( {jobs, refershData}:DataTableProps ) => { onRowSelectionModelChange={(params) => { setSelectedJobs(params) - console.log(params) }} diff --git a/pages/index.tsx b/pages/index.tsx index 3558fdf..cfb9dd8 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -7,12 +7,6 @@ import type { Job } from '@/Database/interface'; export default function Home( {jobs}:{jobs:CrawledJob[]}) { - - const router = useRouter(); - - const refershData = () => { - router.replace(router.asPath); - } return ( <> From edefefab0500dfdcc242e4b6fc54711850ca92e7 Mon Sep 17 00:00:00 2001 From: Mahmoud Galal Date: Sat, 20 May 2023 04:53:58 +0300 Subject: [PATCH 02/10] hotfix --- pages/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.tsx b/pages/index.tsx index cfb9dd8..098d63b 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -18,7 +18,7 @@ export default function Home( {jobs}:{jobs:CrawledJob[]}) {
- +
From 87f95a24b44664b6d16415664b21f0777291054a Mon Sep 17 00:00:00 2001 From: Mahmoud Galal Date: Sat, 20 May 2023 04:58:16 +0300 Subject: [PATCH 03/10] hotfix - remove the refresh function --- components/DataGrid.tsx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/components/DataGrid.tsx b/components/DataGrid.tsx index de9842c..7466973 100644 --- a/components/DataGrid.tsx +++ b/components/DataGrid.tsx @@ -12,11 +12,10 @@ import { DataGrid, GridRowId, GridRowSpacingParams, gridClasses, GridRenderCellP interface DataTableProps { jobs: CrawledJob[]; - refershData: () => void; } -const DataTable = ( {jobs, refershData}:DataTableProps ) => { +const DataTable = ( {jobs}:DataTableProps ) => { const [rowId, setRowId] = useState('') const [loading, setLoading] = useState(false) @@ -153,11 +152,6 @@ const DataTable = ( {jobs, refershData}:DataTableProps ) => { } - const handeelRefershData = async () => { - refershData() - setCrawlerSuccess(false) - setKey((prev) => prev + 1) - } return ( @@ -263,7 +257,6 @@ const DataTable = ( {jobs, refershData}:DataTableProps ) => {
Crawler finished successfully

if you have unfinished business you can close the popup and refresh it manually later

From 44d1da7fbdefa3506fece78cebceedfbbc32598d Mon Sep 17 00:00:00 2001 From: Mahmoud Galal Date: Sat, 20 May 2023 05:09:03 +0300 Subject: [PATCH 04/10] test- preview --- pages/index.tsx | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 098d63b..52b36b7 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -26,10 +26,45 @@ export default function Home( {jobs}:{jobs:CrawledJob[]}) { } export async function getServerSideProps(){ - const jobs = await getJobs(); + // const jobs = await getJobs(); return { props:{ - jobs + [ + { + id:"20022", + company:"Apple", + title:"Software engineer", + link:"https://zjunior.com", + email:"", + type:"Internship", + deadline:"2023-06-02", + logo:"https:/zjunior.com/images/logo.png", + skills:"React, NodeJs, Docker" + }, + { + id:"23132", + company:"Google", + title:"Software Engineer", + link:"https://zjunior.com", + email:"", + type:"Internship", + deadline:"2023-06-02", + logo:"https:/zjunior.com/images/logo.png", + skills:"React, NodeJs, Docker" + }, + { + id:"21312412", + company:"zJunior", + title:"Software engineer", + link:"https://zjunior.com", + email:"", + type:"EntryLevel", + deadline:"2023-06-02", + logo:"https:/zjunior.com/images/logo.png", + skills:"React, NodeJs, Docker" + }, + + ] } } From 41446db806b812836534f7c591b046eda6e1d30e Mon Sep 17 00:00:00 2001 From: Mahmoud Galal Date: Sat, 20 May 2023 05:11:56 +0300 Subject: [PATCH 05/10] test- preview --- pages/index.tsx | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 52b36b7..938fb1d 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -29,42 +29,7 @@ export async function getServerSideProps(){ // const jobs = await getJobs(); return { props:{ - [ - { - id:"20022", - company:"Apple", - title:"Software engineer", - link:"https://zjunior.com", - email:"", - type:"Internship", - deadline:"2023-06-02", - logo:"https:/zjunior.com/images/logo.png", - skills:"React, NodeJs, Docker" - }, - { - id:"23132", - company:"Google", - title:"Software Engineer", - link:"https://zjunior.com", - email:"", - type:"Internship", - deadline:"2023-06-02", - logo:"https:/zjunior.com/images/logo.png", - skills:"React, NodeJs, Docker" - }, - { - id:"21312412", - company:"zJunior", - title:"Software engineer", - link:"https://zjunior.com", - email:"", - type:"EntryLevel", - deadline:"2023-06-02", - logo:"https:/zjunior.com/images/logo.png", - skills:"React, NodeJs, Docker" - }, - - ] + } } From 6901074d925cafff57032ba183fd51a4f9e0d936 Mon Sep 17 00:00:00 2001 From: Mahmoud Galal Date: Sat, 20 May 2023 19:18:43 +0300 Subject: [PATCH 06/10] deploy on CF --- pages/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 938fb1d..d8adbf5 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -5,6 +5,7 @@ import { CrawledJob } from '@prisma/client'; import DataTable from '@/components/DataGrid' import type { Job } from '@/Database/interface'; +export const runtime = 'edge'; export default function Home( {jobs}:{jobs:CrawledJob[]}) { @@ -26,10 +27,10 @@ export default function Home( {jobs}:{jobs:CrawledJob[]}) { } export async function getServerSideProps(){ - // const jobs = await getJobs(); + const jobs = await getJobs(); return { props:{ - + jobs } } From eb96828c2f631fda1120e2a15b3f73c0f32ce908 Mon Sep 17 00:00:00 2001 From: Mahmoud Galal Date: Sat, 20 May 2023 19:19:19 +0300 Subject: [PATCH 07/10] export edge prop --- pages/api/confirm.ts | 1 + pages/api/crawler.ts | 1 + pages/api/create.ts | 1 + pages/api/delete.ts | 1 + pages/api/update.ts | 1 + 5 files changed, 5 insertions(+) diff --git a/pages/api/confirm.ts b/pages/api/confirm.ts index a3f5584..0128824 100644 --- a/pages/api/confirm.ts +++ b/pages/api/confirm.ts @@ -3,6 +3,7 @@ import { CrawledJob, PrismaClient } from "@prisma/client"; const prisma = new PrismaClient(); +export const runtime = 'edge'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { diff --git a/pages/api/crawler.ts b/pages/api/crawler.ts index e49403c..b24959c 100644 --- a/pages/api/crawler.ts +++ b/pages/api/crawler.ts @@ -1,4 +1,5 @@ import { NextApiRequest, NextApiResponse } from 'next' +export const runtime = 'edge'; export default async function handler(req : NextApiRequest, res: NextApiResponse) { if (req.method !== 'POST') { diff --git a/pages/api/create.ts b/pages/api/create.ts index 00c0d55..9a1d61a 100644 --- a/pages/api/create.ts +++ b/pages/api/create.ts @@ -2,6 +2,7 @@ import { PrismaClient } from "@prisma/client"; import { NextApiRequest, NextApiResponse } from "next"; const prisma = new PrismaClient(); +export const runtime = 'edge'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method !== 'POST') { diff --git a/pages/api/delete.ts b/pages/api/delete.ts index 1f189b8..d8c32b7 100644 --- a/pages/api/delete.ts +++ b/pages/api/delete.ts @@ -4,6 +4,7 @@ import { CrawledJob, PrismaClient } from "@prisma/client"; const prisma = new PrismaClient(); +export const runtime = 'edge'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method !== 'POST') { diff --git a/pages/api/update.ts b/pages/api/update.ts index 7ee840c..c78e3a2 100644 --- a/pages/api/update.ts +++ b/pages/api/update.ts @@ -3,6 +3,7 @@ import { CrawledJob, PrismaClient } from "@prisma/client"; const prisma = new PrismaClient(); +export const runtime = 'edge'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method !== 'PUT') { From 7978698902ea91a0a43042f4c8d0b2d82c04c0f4 Mon Sep 17 00:00:00 2001 From: Mahmoud Galal Date: Sat, 20 May 2023 19:39:42 +0300 Subject: [PATCH 08/10] export edge on next --- next.config.js | 3 +++ pages/api/confirm.ts | 1 - pages/api/crawler.ts | 1 - pages/api/create.ts | 2 +- pages/api/delete.ts | 2 -- pages/api/update.ts | 2 +- pages/index.tsx | 2 +- 7 files changed, 6 insertions(+), 7 deletions(-) diff --git a/next.config.js b/next.config.js index 53823c4..dd08e7d 100644 --- a/next.config.js +++ b/next.config.js @@ -1,6 +1,9 @@ /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, + experimental: { + runtime: 'edge' + } } diff --git a/pages/api/confirm.ts b/pages/api/confirm.ts index 0128824..a3f5584 100644 --- a/pages/api/confirm.ts +++ b/pages/api/confirm.ts @@ -3,7 +3,6 @@ import { CrawledJob, PrismaClient } from "@prisma/client"; const prisma = new PrismaClient(); -export const runtime = 'edge'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { diff --git a/pages/api/crawler.ts b/pages/api/crawler.ts index b24959c..e49403c 100644 --- a/pages/api/crawler.ts +++ b/pages/api/crawler.ts @@ -1,5 +1,4 @@ import { NextApiRequest, NextApiResponse } from 'next' -export const runtime = 'edge'; export default async function handler(req : NextApiRequest, res: NextApiResponse) { if (req.method !== 'POST') { diff --git a/pages/api/create.ts b/pages/api/create.ts index 9a1d61a..22ce3af 100644 --- a/pages/api/create.ts +++ b/pages/api/create.ts @@ -2,7 +2,7 @@ import { PrismaClient } from "@prisma/client"; import { NextApiRequest, NextApiResponse } from "next"; const prisma = new PrismaClient(); -export const runtime = 'edge'; + export default async function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method !== 'POST') { diff --git a/pages/api/delete.ts b/pages/api/delete.ts index d8c32b7..6754da1 100644 --- a/pages/api/delete.ts +++ b/pages/api/delete.ts @@ -4,8 +4,6 @@ import { CrawledJob, PrismaClient } from "@prisma/client"; const prisma = new PrismaClient(); -export const runtime = 'edge'; - export default async function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method !== 'POST') { return res.status(405).json({ message: 'Method not allowed' }); diff --git a/pages/api/update.ts b/pages/api/update.ts index c78e3a2..0daa033 100644 --- a/pages/api/update.ts +++ b/pages/api/update.ts @@ -3,7 +3,7 @@ import { CrawledJob, PrismaClient } from "@prisma/client"; const prisma = new PrismaClient(); -export const runtime = 'edge'; + export default async function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method !== 'PUT') { diff --git a/pages/index.tsx b/pages/index.tsx index d8adbf5..2bb70a3 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -5,7 +5,7 @@ import { CrawledJob } from '@prisma/client'; import DataTable from '@/components/DataGrid' import type { Job } from '@/Database/interface'; -export const runtime = 'edge'; + export default function Home( {jobs}:{jobs:CrawledJob[]}) { From 99c7707cfbccb075234db7c147eb1dd134db3506 Mon Sep 17 00:00:00 2001 From: Mahmoud Galal Date: Sat, 20 May 2023 19:48:27 +0300 Subject: [PATCH 09/10] Revert "export edge prop" This reverts commit eb96828c2f631fda1120e2a15b3f73c0f32ce908. --- pages/api/create.ts | 1 - pages/api/update.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/pages/api/create.ts b/pages/api/create.ts index 22ce3af..00c0d55 100644 --- a/pages/api/create.ts +++ b/pages/api/create.ts @@ -3,7 +3,6 @@ import { NextApiRequest, NextApiResponse } from "next"; const prisma = new PrismaClient(); - export default async function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method !== 'POST') { return res.status(405).json({ message: 'Method not allowed' }); diff --git a/pages/api/update.ts b/pages/api/update.ts index 0daa033..7ee840c 100644 --- a/pages/api/update.ts +++ b/pages/api/update.ts @@ -4,7 +4,6 @@ import { CrawledJob, PrismaClient } from "@prisma/client"; const prisma = new PrismaClient(); - export default async function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method !== 'PUT') { return res.status(405).json({ message: 'Method not allowed' }); From 5968c63e55d40b2f898bb9c115a4d046cdc791ec Mon Sep 17 00:00:00 2001 From: Mahmoud Galal Date: Sat, 20 May 2023 19:50:49 +0300 Subject: [PATCH 10/10] use client on client components --- components/DataGrid.tsx | 1 + components/Header.tsx | 1 + components/Layout.tsx | 2 ++ components/UserAction.tsx | 2 ++ components/editButtons.tsx | 1 + next.config.js | 3 --- 6 files changed, 7 insertions(+), 3 deletions(-) diff --git a/components/DataGrid.tsx b/components/DataGrid.tsx index 7466973..aa0c6ab 100644 --- a/components/DataGrid.tsx +++ b/components/DataGrid.tsx @@ -1,3 +1,4 @@ +'use client' import UserAction from './UserAction'; import { toast } from 'react-toastify'; import EditButtons from './editButtons'; diff --git a/components/Header.tsx b/components/Header.tsx index fdf8b0b..4d862c2 100644 --- a/components/Header.tsx +++ b/components/Header.tsx @@ -1,3 +1,4 @@ +'use client' import Image from "next/image"; const Header = ( ) => { diff --git a/components/Layout.tsx b/components/Layout.tsx index f6e525b..f5af744 100644 --- a/components/Layout.tsx +++ b/components/Layout.tsx @@ -1,6 +1,8 @@ +'use client' import Header from "./Header"; import { useTheme } from 'next-themes' + interface LayoutProps { children: React.ReactNode; } diff --git a/components/UserAction.tsx b/components/UserAction.tsx index 6e048ca..c02921e 100644 --- a/components/UserAction.tsx +++ b/components/UserAction.tsx @@ -1,3 +1,5 @@ +'use client' + import { toast } from 'react-toastify'; import { useState, useEffect } from 'react'; import { green } from '@mui/material/colors'; diff --git a/components/editButtons.tsx b/components/editButtons.tsx index a5ecc6e..327e7f7 100644 --- a/components/editButtons.tsx +++ b/components/editButtons.tsx @@ -1,3 +1,4 @@ +'use client' import { useState } from 'react'; import { GridRowId } from '@mui/x-data-grid'; import { green } from '@mui/material/colors'; diff --git a/next.config.js b/next.config.js index dd08e7d..53823c4 100644 --- a/next.config.js +++ b/next.config.js @@ -1,9 +1,6 @@ /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, - experimental: { - runtime: 'edge' - } }