Skip to content

Commit

Permalink
async components use server supabase
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloGracia committed Nov 8, 2024
1 parent f71cbed commit 91f8f32
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ node_modules/
/playwright-report/
/blob-report/
/playwright/.cache/

# Snaplet
/.snaplet/
27 changes: 14 additions & 13 deletions src/app/casos-activos/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { supabase } from '@/lib/supabase/client';
import { createClient } from '@/lib/supabase/server';
import TabNavigation from '@/components/TabNavigation';
import { PropsWithChildren } from 'react';
const getCount = async () => {
const {
data: solicitaData,
count: solicitaCount,
error: solicitaError,
} = await supabase.from('help_requests').select('id', { count: 'exact' }).eq('type', 'necesita');
import { SupabaseClient } from '@supabase/supabase-js';
import { Database } from '@/types/database';
const getCount = async (supabase: SupabaseClient<Database>) => {
const { count: solicitaCount, error: solicitaError } = await supabase
.from('help_requests')
.select('id', { count: 'exact' })
.eq('type', 'necesita');

const {
data: ofreceData,
count: ofreceCount,
error: ofreceError,
} = await supabase.from('help_requests').select('id', { count: 'exact' }).eq('type', 'ofrece');
const { count: ofreceCount, error: ofreceError } = await supabase
.from('help_requests')
.select('id', { count: 'exact' })
.eq('type', 'ofrece');

if (solicitaError) {
throw new Error('Error fetching solicita:', solicitaError);
Expand All @@ -28,7 +28,8 @@ const getCount = async () => {
};

export default async function CasosActivosLayout({ children }: PropsWithChildren) {
const count = await getCount();
const supabase = await createClient();
const count = await getCount(supabase);
return (
<>
<div className="space-y-6 mx-auto max-w-7xl px-4 sm:px-6">
Expand Down
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PhoneNumberDialog from '@/components/auth/PhoneNumberDialog';
import Image from 'next/image';
import { CallCenterLink } from '@/components/CallCenterLink';

export default function Home() {
export default async function Home() {
const emergencyNumbers = [
{ name: 'Emergencias', number: '112', description: 'Para situaciones de peligro inmediato' },
{ name: 'Policía Local', number: '092', description: 'Asistencia y seguridad local' },
Expand Down
2 changes: 2 additions & 0 deletions src/lib/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { supabase } from './supabase/client';
import { Database } from '@/types/database';
import { HelpRequestAssignmentInsert, HelpRequestUpdate } from '@/types/Requests';
import { createClient } from '@/lib/supabase/server';
import { SupabaseClient } from '@supabase/supabase-js';

export const helpRequestService = {
async createRequest(requestData: Database['public']['Tables']['help_requests']['Insert']) {
Expand Down Expand Up @@ -114,6 +115,7 @@ export const helpRequestService = {
};
},
async getTodaysCountByTown() {
const supabase = await getSupabaseClient();
const today = new Date().toISOString().split('T')[0];

const { data: towns, error: townError } = await supabase.from('towns').select('id, name');
Expand Down

0 comments on commit 91f8f32

Please sign in to comment.