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

Componentes async usan supabase en el servidor #167

Merged
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
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