Skip to content

Commit

Permalink
did some tweaking
Browse files Browse the repository at this point in the history
  • Loading branch information
philipye315 committed Oct 9, 2024
1 parent 3c0c547 commit cf323c4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
20 changes: 4 additions & 16 deletions src/screens/HealingResources/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import React, { useEffect, useState } from 'react';
import { Button, View } from 'react-native';
import supabase from '../../supabase/createClient';

interface Resource {
summary: string;
[key: string]: any;
}
import { Resource } from '@/types/types';
import { getHealingResourceData } from '../../supabase/queries/generalQueries';

export default function HealingResources() {
const [, setSummaries] = useState<Resource[]>([]);
Expand All @@ -16,16 +12,8 @@ export default function HealingResources() {

const fetchData = async () => {
try {
const { data, error } = await supabase
.from('healing_resources')
.select('*');

if (error) {
console.error('Error fetching resources:', error);
return;
}

setSummaries(data as Resource[]);
const data = await getHealingResourceData();
setSummaries(data);
} catch (error) {
console.error('Error fetching data:', error);
}
Expand Down
21 changes: 4 additions & 17 deletions src/screens/SeekHelp/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import React, { useEffect, useState } from 'react';
import { Button, Text, View } from 'react-native';
import supabase from '../../supabase/createClient';

interface Resource {
summary: string;
[key: string]: any;
}
import { getStateResourceData } from '@/supabase/queries/generalQueries';
import { Resource } from '@/types/types';

export default function SeekHelp() {
const [summaries, setSummaries] = useState<Resource[]>([]);
Expand All @@ -16,17 +12,8 @@ export default function SeekHelp() {

const fetchData = async () => {
try {
const { data, error } = await supabase
.from('state_resources')
.select('*')
.in('state', ['California', 'National']);

if (error) {
console.error('Error fetching resources:', error);
return;
}

setSummaries(data as Resource[]);
const data = await getStateResourceData();
setSummaries(data);
} catch (error) {
console.error('Error fetching data:', error);
}
Expand Down
1 change: 0 additions & 1 deletion src/supabase/createClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createClient } from '@supabase/supabase-js';

// Create a single supabase client for interacting with your database
if (
!process.env.EXPO_PUBLIC_SUPABASE_URL ||
!process.env.EXPO_PUBLIC_SUPABASE_ANON_KEY
Expand Down
27 changes: 27 additions & 0 deletions src/supabase/queries/generalQueries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import supabase from '../createClient';

interface Resource {
summary: string;
[key: string]: any;
}

export const getHealingResourceData = async (): Promise<Resource[]> => {
const { data, error } = await supabase.from('healing_resources').select('*');
if (error) {
throw new Error(`Error fetching resources: ${error.message}`);
}

return data as Resource[];
};

export const getStateResourceData = async (): Promise<Resource[]> => {
const { data, error } = await supabase
.from('state_resources')
.select('*')
.in('state', ['California', 'National']);

if (error) {
throw new Error(`Error fetching resources: ${error.message}`);
}
return data as Resource[];
};
4 changes: 4 additions & 0 deletions src/types/types.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Resource {
summary: string;
[key: string]: any;
}

0 comments on commit cf323c4

Please sign in to comment.