Skip to content

Commit

Permalink
[organization] cleaned up code (#11)
Browse files Browse the repository at this point in the history
Co-authored-by: philipye314 <[email protected]>
  • Loading branch information
philipye314 and philipye315 authored Oct 9, 2024
1 parent 3c0c547 commit 79337e2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 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 { getHealingResourceData } from '@/supabase/queries/generalQueries';
import { Resource } from '@/types/types';

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 { getSeekHelpData } 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 getSeekHelpData();
setSummaries(data);
} catch (error) {
console.error('Error fetching data:', error);
}
Expand Down
23 changes: 23 additions & 0 deletions src/supabase/queries/generalQueries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Resource } from '@/types/types';
import supabase from '../createClient';

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 getSeekHelpData = 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 79337e2

Please sign in to comment.