Skip to content

Commit

Permalink
fixed some supabase issues
Browse files Browse the repository at this point in the history
  • Loading branch information
philipye314 committed Oct 21, 2023
1 parent 9e393f4 commit e83fd77
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 53 deletions.
64 changes: 13 additions & 51 deletions src/app/(BottomTabNavigation)/Cases/QRCodeScanner/AddCase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,28 @@ import { useLocalSearchParams, useRouter } from 'expo-router';
import React, { useEffect, useState } from 'react';
import { Image, Text, TouchableOpacity, View } from 'react-native';
import { getCase, uploadCase } from '../../../../../supabase/queries/case';
import { CaseUid } from '../../../../../types/types';
import styles from './styles';

enum caseStatus {
NotStarted,
InProgress,
Settled,
Cancelled,
}

export interface Case {
id: number;
approved: boolean;
title: string;
summary: string;
image: string;
caseStatus: caseStatus;
}

function AddCase() {
const local = useLocalSearchParams();
const { caseId } = local;
const { id, title, summary, image } = useLocalSearchParams<{
id: CaseUid;
title: string;
summary: string;
image: string;
}>();
console.log(id, title, summary, image);
const router = useRouter();

const [dataImage, setDataImage] = useState('');
const [dataTitle, setDataTitle] = useState('');
const [dataSummary, setDataSummary] = useState('');

const parseData = (data: any) => {
const myData = {
...(data[0] as Partial<Case>),
};
return myData as Case;
};

useEffect(() => {
const getData = async () => {
const { data, error } = await getCase(caseId);
if (error) {
console.log('error');
}

const myData = parseData(data);
const { image, title, summary } = myData;

setDataImage(image);
setDataTitle(title);
setDataSummary(summary);
console.log(data);
};
getData();
}, []);

const addToCases = async () => {
uploadCase(caseId);
uploadCase(id);
router.push('/Cases');
};
return (
<View style={styles.container}>
<Text style={styles.title}>{dataTitle}</Text>
<Image style={styles.image} source={{ uri: dataImage }} />
<Text style={styles.blurb}>{dataSummary}</Text>
<Text style={styles.title}>{title}</Text>
<Image style={styles.image} source={{ uri: image }} />
<Text style={styles.blurb}>{summary}</Text>
<TouchableOpacity onPress={addToCases} style={styles.button}>
<Text>ADD TO CASES</Text>
</TouchableOpacity>
Expand Down
4 changes: 3 additions & 1 deletion src/app/(BottomTabNavigation)/Cases/QRCodeScanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BarCodeScanner, BarCodeScannerResult } from 'expo-barcode-scanner';
import { router } from 'expo-router';
import React, { useEffect, useState } from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import { getCaseById } from '../../../../supabase/queries/cases';
import styles from './styles';

enum permissions {
Expand All @@ -28,9 +29,10 @@ function QRCodeScannerScreen() {

const handleBarCodeScanned = async (result: BarCodeScannerResult) => {
if (isValidBarcode(result.data)) {
const { id, title, summary, image } = await getCaseById(result.data);
router.push({
pathname: '/Cases/QRCodeScanner/AddCase',
params: { caseId: result.data },
params: { id, title, summary, image },
});
} else {
setMessage('INVALID QR CODE!');
Expand Down
2 changes: 1 addition & 1 deletion src/supabase/queries/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function getCasesByIds(caseIds: CaseUid[]): Promise<Case[]> {
*/
export function parseCase(item: any): Case {
const formattedCase: Case = {
id: item.id,
id: item.caseId,
approved: item.approved,
title: item.title,
blurb: item.blurb,
Expand Down

0 comments on commit e83fd77

Please sign in to comment.