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

[organization] cleaned up code #11

Merged
merged 1 commit into from
Oct 9, 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
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;
}
Loading