Skip to content

Commit

Permalink
Folasade/imp 5 supabase client (#6)
Browse files Browse the repository at this point in the history
* wip: intializing db

* wip: fixing branch name

* feat: intialized database

* update to feature

* fixed eslint errors

* current supabase update

* fixed client initialization

* feat: intialize database is done

* changed touchableopactiy imports

---------

Co-authored-by: foloy <[email protected]>
Co-authored-by: Stephanie Wong <[email protected]>
  • Loading branch information
3 people authored Oct 11, 2023
1 parent 5a796d2 commit 26bb1be
Show file tree
Hide file tree
Showing 6 changed files with 560 additions and 58 deletions.
17 changes: 16 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ module.exports = api => {
api.cache(true);
return {
presets: ['babel-preset-expo'],
plugins: ['expo-router/babel'],
plugins: [
'expo-router/babel',
[
'module:react-native-dotenv',
{
envName: 'APP_ENV',
moduleName: '@env',
path: '.env',
blocklist: null,
allowlist: null,
safe: false,
allowUndefined: true,
verbose: false,
},
],
],
};
};
62 changes: 62 additions & 0 deletions lib/DummyQueries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { TouchableOpacity, View } from 'react-native';
import { Text } from 'react-native-elements';
import styles from '../src/app/styles';
import supabase from './supabase';

export default function DummyQueries() {
let queryHolder;

async function allCases() {
const { data, error } = await supabase.from('Cases').select();
queryHolder = data;
queryHolder = error;
}
async function approvedCases() {
const { data, error } = await supabase
.from('Cases')
.select()
.filter('approved', 'is', 'True');
queryHolder = data;
queryHolder = error;
}
async function unapprovedCases() {
const { data, error } = await supabase
.from('Cases')
.select()
.filter('approved', 'is', 'False');
queryHolder = data;
queryHolder = error;
}
async function addCase() {
const dummyCase = {
approved: false,
title: 'Dummy Case',
summary: 'Testing intializing db',
image: 'no.jpg',
case_status: 'In Progress',
claim_link: 'berkeley.edu',
case_site: 'berkeley.edu',
opt_out_link: 'berkeley.edu',
};
const { error } = await supabase.from('Cases').insert(dummyCase);
queryHolder = error;
}

return (
<View>
<TouchableOpacity style={styles.button} onPress={() => allCases()}>
<Text>Get All Cases</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={() => approvedCases()}>
<Text>Get Approved Cases</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={() => unapprovedCases()}>
<Text>Get Unapproved Cases</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={() => addCase()}>
<Text>Add a Dummy Case</Text>
</TouchableOpacity>
<Text>{queryHolder ? '' : queryHolder}</Text>
</View>
);
}
12 changes: 12 additions & 0 deletions lib/supabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createClient } from '@supabase/supabase-js';
import 'react-native-url-polyfill/auto';

if (!process.env.SUPABASE_URL || !process.env.SUPABASE_ANON_KEY) {
throw new Error('Supabase environment variables are not defined.');
}
const supabase = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_ANON_KEY,
);

export default supabase;
Loading

0 comments on commit 26bb1be

Please sign in to comment.