Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix build #164

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions apps/registry/app/api/jobs/[uuid]/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ import { createClient } from '@supabase/supabase-js';
import { NextResponse } from 'next/server';

const supabaseUrl = 'https://itxuhvvwryeuzuyihpkp.supabase.co';
const supabaseKey = process.env.SUPABASE_KEY;
const supabase = createClient(supabaseUrl, supabaseKey);

// This ensures the route is always dynamic
export const dynamic = 'force-dynamic';

export async function GET(request, { params }) {
// During build time or when SUPABASE_KEY is not available
if (!process.env.SUPABASE_KEY) {
return NextResponse.json(
{ message: 'API not available during build' },
{ status: 503 }
);
}

try {
const supabase = createClient(supabaseUrl, process.env.SUPABASE_KEY);

const { data: job, error } = await supabase
.from('jobs')
.select('*')
Expand All @@ -26,7 +37,7 @@ export async function GET(request, { params }) {

return NextResponse.json(job);
} catch (error) {
console.error('Error fetching job:', error);
console.error('Error:', error);
return NextResponse.json(
{ message: 'Internal server error' },
{ status: 500 }
Expand Down
89 changes: 61 additions & 28 deletions apps/registry/app/api/resumes/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ import { NextResponse } from 'next/server';
import gravatar from 'gravatar';

const supabaseUrl = 'https://itxuhvvwryeuzuyihpkp.supabase.co';
const supabaseKey = process.env.SUPABASE_KEY;
const supabase = createClient(supabaseUrl, supabaseKey);

// This ensures the route is always dynamic
export const dynamic = 'force-dynamic';

export async function GET(request) {
// During build time or when SUPABASE_KEY is not available
if (!process.env.SUPABASE_KEY) {
return NextResponse.json(
{ message: 'API not available during build' },
{ status: 503 }
);
}

try {
const supabase = createClient(supabaseUrl, process.env.SUPABASE_KEY);
const { searchParams } = new URL(request.url);
const limit = parseInt(searchParams.get('limit')) || 3000;
const page = parseInt(searchParams.get('page')) || 1;
Expand All @@ -21,50 +31,73 @@ export async function GET(request) {
.limit(limit)
.range((page - 1) * limit, page * limit - 1);

if (search) {
query.ilike('name', `%${search}%`);
if (search && search.trim() !== '') {
query.textSearch('resume', search.trim(), {
config: 'english',
type: 'websearch',
});
}

const { data, error } = await query;
console.timeEnd('getResumes');

if (error) {
console.error('Error fetching resumes:', error);
return NextResponse.json(
{ message: 'Error fetching resumes' },
{ status: 500 }
);
}

console.timeEnd('getResumes');

if (!data) {
return NextResponse.json(
{ message: 'No resumes found' },
{ status: 404 }
);
}

console.time('mapResumes');
const resumes = data.map((row) => {
const resume = JSON.parse(row.resume);
return {
username: row.username,
label: resume?.basics?.label,
image:
resume?.basics?.image ||
gravatar.url(
resume?.basics?.email,
{ s: '200', r: 'x', d: 'retro' },
true
),
name: resume?.basics?.name,
location: resume?.basics?.location,
updated_at: row.updated_at,
created_at: row.created_at,
};
try {
const resume = JSON.parse(row.resume);
return {
username: row.username,
label: resume?.basics?.label,
image:
resume?.basics?.image ||
gravatar.url(
resume?.basics?.email || '',
{
s: '200',
r: 'x',
d: 'retro',
},
true
),
name: resume?.basics?.name,
location: resume?.basics?.location,
updated_at: row.updated_at,
created_at: row.created_at,
};
} catch (e) {
console.error('Error parsing resume:', e);
return {
username: row.username,
label: 'Error parsing resume',
image: gravatar.url('', { s: '200', r: 'x', d: 'retro' }, true),
name: row.username,
location: null,
updated_at: row.updated_at,
created_at: row.created_at,
};
}
Comment on lines +62 to +94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor duplicate gravatar URL construction

The gravatar URL construction logic is duplicated between the success and error cases. Consider extracting this into a helper function.

+ const getGravatarUrl = (email = '') => {
+   return gravatar.url(
+     email,
+     { s: '200', r: 'x', d: 'retro' },
+     true
+   );
+ };

  try {
    const resume = JSON.parse(row.resume);
    return {
      username: row.username,
      label: resume?.basics?.label,
-     image: resume?.basics?.image || gravatar.url(
-       resume?.basics?.email || '',
-       { s: '200', r: 'x', d: 'retro' },
-       true
-     ),
+     image: resume?.basics?.image || getGravatarUrl(resume?.basics?.email),
      // ... rest of the properties
    };
  } catch (e) {
    return {
      username: row.username,
      label: 'Error parsing resume',
-     image: gravatar.url('', { s: '200', r: 'x', d: 'retro' }, true),
+     image: getGravatarUrl(),
      // ... rest of the properties
    };
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try {
const resume = JSON.parse(row.resume);
return {
username: row.username,
label: resume?.basics?.label,
image:
resume?.basics?.image ||
gravatar.url(
resume?.basics?.email || '',
{
s: '200',
r: 'x',
d: 'retro',
},
true
),
name: resume?.basics?.name,
location: resume?.basics?.location,
updated_at: row.updated_at,
created_at: row.created_at,
};
} catch (e) {
console.error('Error parsing resume:', e);
return {
username: row.username,
label: 'Error parsing resume',
image: gravatar.url('', { s: '200', r: 'x', d: 'retro' }, true),
name: row.username,
location: null,
updated_at: row.updated_at,
created_at: row.created_at,
};
}
const getGravatarUrl = (email = '') => {
return gravatar.url(
email,
{ s: '200', r: 'x', d: 'retro' },
true
);
};
try {
const resume = JSON.parse(row.resume);
return {
username: row.username,
label: resume?.basics?.label,
image: resume?.basics?.image || getGravatarUrl(resume?.basics?.email),
name: resume?.basics?.name,
location: resume?.basics?.location,
updated_at: row.updated_at,
created_at: row.created_at,
};
} catch (e) {
console.error('Error parsing resume:', e);
return {
username: row.username,
label: 'Error parsing resume',
image: getGravatarUrl(),
name: row.username,
location: null,
updated_at: row.updated_at,
created_at: row.created_at,
};
}

});
console.timeEnd('mapResumes');

console.time('sortResumes');
resumes.sort((a, b) => {
return new Date(b.created_at) - new Date(a.created_at);
});
console.timeEnd('sortResumes');

return NextResponse.json(resumes);
} catch (error) {
console.error('Error processing resumes:', error);
console.error('Error:', error);
return NextResponse.json(
{ message: 'Internal server error' },
{ status: 500 }
Expand Down
12 changes: 10 additions & 2 deletions apps/registry/app/explore/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import ClientResumes from './ClientResumes';
import gravatar from 'gravatar';

const supabaseUrl = 'https://itxuhvvwryeuzuyihpkp.supabase.co';
const supabaseKey = process.env.SUPABASE_KEY;
const supabase = createClient(supabaseUrl, supabaseKey);

const ITEMS_PER_PAGE = 100;

Expand All @@ -20,8 +18,18 @@ export const metadata = {
},
};

// This makes the page static at build time
export const dynamic = 'force-dynamic';
Comment on lines +21 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix incorrect comment about page behavior

The comment "This makes the page static at build time" contradicts the actual behavior of force-dynamic, which ensures the page is dynamically rendered at runtime. This comment could mislead developers.

-// This makes the page static at build time
+// This ensures the page is dynamically rendered at runtime
export const dynamic = 'force-dynamic';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// This makes the page static at build time
export const dynamic = 'force-dynamic';
// This ensures the page is dynamically rendered at runtime
export const dynamic = 'force-dynamic';


async function getResumes(page = 1, search = '') {
try {
// During build time, return empty data
if (!process.env.SUPABASE_KEY) {
return { resumes: [], totalCount: 0, totalPages: 0 };
}

const supabase = createClient(supabaseUrl, process.env.SUPABASE_KEY);

// First get the total count
let countQuery = supabase
.from('resumes')
Expand Down
45 changes: 28 additions & 17 deletions apps/registry/app/jobs/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,40 @@ const ClientJobBoard = dynamic(() => import('./ClientJobBoard'), {
});

const supabaseUrl = 'https://itxuhvvwryeuzuyihpkp.supabase.co';
const supabaseKey = process.env.SUPABASE_KEY;
const supabase = createClient(supabaseUrl, supabaseKey);

// This ensures the page is dynamic at runtime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add export configuration for Next.js dynamic behavior

The comment indicates the page should be dynamic, but the configuration is missing.

Add the following configuration:

+export const dynamic = 'force-dynamic';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// This ensures the page is dynamic at runtime
// This ensures the page is dynamic at runtime
export const dynamic = 'force-dynamic';


async function getJobs() {
const ninetyDaysAgo = new Date();
ninetyDaysAgo.setDate(ninetyDaysAgo.getDate() - 90);

const { data: jobs, error } = await supabase
.from('jobs')
.select('*')
.gte('created_at', ninetyDaysAgo.toISOString())
.order('created_at', { ascending: false });

if (error) {
console.error('Error fetching jobs:', error);
return [];
// During build time or when SUPABASE_KEY is not available
if (!process.env.SUPABASE_KEY) {
return { jobs: [], error: null };
}

return jobs || [];
try {
const supabase = createClient(supabaseUrl, process.env.SUPABASE_KEY);
const ninetyDaysAgo = new Date();
ninetyDaysAgo.setDate(ninetyDaysAgo.getDate() - 90);

const { data: jobs, error } = await supabase
.from('jobs')
.select('*')
.gte('created_at', ninetyDaysAgo.toISOString())
.order('created_at', { ascending: false });

if (error) {
console.error('Error fetching jobs:', error);
return { jobs: [], error };
}

return { jobs: jobs || [], error: null };
} catch (error) {
console.error('Error:', error);
return { jobs: [], error };
}
}

export default async function JobsPage() {
const initialJobs = await getJobs();
const { jobs } = await getJobs();

return (
<div className="min-h-screen bg-gray-100 p-8">
Expand All @@ -42,7 +53,7 @@ export default async function JobsPage() {
</div>
}
>
<ClientJobBoard initialJobs={initialJobs} />
<ClientJobBoard initialJobs={jobs} />
</Suspense>
</div>
</div>
Expand Down
22 changes: 17 additions & 5 deletions apps/registry/pages/api/jobs/all.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
const { createClient } = require('@supabase/supabase-js');

const supabaseUrl = 'https://itxuhvvwryeuzuyihpkp.supabase.co';
const supabaseKey = process.env.SUPABASE_KEY;
const supabase = createClient(supabaseUrl, supabaseKey);

export const config = {
runtime: 'edge',
};

export default async function handler(req, res) {
if (req.method !== 'GET') {
return res.status(405).json({ message: 'Method not allowed' });
}

// During build time or when SUPABASE_KEY is not available
if (!process.env.SUPABASE_KEY) {
return res.status(503).json({ message: 'API not available during build' });
}

try {
const supabase = createClient(supabaseUrl, process.env.SUPABASE_KEY);

// Get all jobs from the last 90 days, sorted by creation date descending
const { data: jobs, error } = await supabase
.from('jobs')
.select('*')
.gte('created_at', new Date(Date.now() - 60 * 24 * 60 * 90 * 1000).toISOString())
.gte(
'created_at',
new Date(Date.now() - 60 * 24 * 60 * 90 * 1000).toISOString()
)
.order('created_at', { ascending: false });

if (error) throw error;

return res.status(200).json(jobs);
return res.status(200).json(jobs || []);
} catch (error) {
console.error('Error fetching jobs:', error);
return res.status(500).json({ message: 'Error fetching jobs', error: error.message });
return res.status(500).json({ message: 'Internal server error' });
}
}
Loading