Skip to content

Commit

Permalink
added database and page
Browse files Browse the repository at this point in the history
  • Loading branch information
jxmoose committed Mar 11, 2024
1 parent bbc19c7 commit 72ba091
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
Empty file added database.types.ts
Empty file.
30 changes: 30 additions & 0 deletions src/app/exhibitsPage/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use client';

import React, { useEffect, useState} from 'react';
import NavBar from '../../components/userComponents/navBar/navBar';
import { ExhibitRow } from '../../types/types';
import { fetchAllExhibits } from '../../supabase/exhibits/queries';

function App() {
const [exhibits, setExhibits] = useState<ExhibitRow[]>([]);
useEffect(() => {
// Get exhibits
const getExhibits = async () => {
const fetchedExhibits: ExhibitRow[] = await fetchAllExhibits();
setExhibits(fetchedExhibits);
};
getExhibits();
}, [exhibits]);
return (
<div style={{ backgroundColor: '#ebf0e4', height: '100vh' }}>
<NavBar />
<div style={{ padding: '16px' }}>
<h1 style={{ color: '#333333', fontSize: '2rem', fontWeight: 700 }}>
Exhibits
</h1>
</div>
</div>
);
}

export default App;
65 changes: 65 additions & 0 deletions src/supabase/exhibits/queries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use client';

import { ExhibitRow } from '../../types/types';
import supabase from '../client';

/**
*
*/
export async function fetchAllExhibits() {
const { data, error } = await supabase.from('exhibits').select('*');
if (error) {
throw new Error(`An error occurred trying to read exhibits: ${error}`);
}
return data;
}

/**
*
* @param id
*/
export async function deleteDisplay(id: string) {
const { error } = await supabase.from('exhibits').delete().eq('id', id);

if (error) {
throw new Error(`An error occurred trying to delete displays: ${error}`);
} else {
fetchAllExhibits();
}
}

/**
*
* @param exhibitData
*/
export async function createExhibit(exhibitData: ExhibitRow) {
const { data, error } = await supabase.from('exhibits').upsert([exhibitData]);

if (error) {
throw new Error(
`An error occurred trying to create displays: ${error.message}`,
);
}
const newExhibit = data;
return newExhibit;
}

/**
*
* @param id - id number
* @param updatedInfo - the exhibit row to update
* @returns - updates that given exhibit row
*/
export async function updateExhibit(id: number, updatedInfo: ExhibitRow) {
const { data, error } = await supabase
.from('exhibits')
.update(updatedInfo)
.eq('id', updatedInfo.id);

if (error) {
throw new Error(`Error updating exhibit data: ${error.message}`);
}

const newExhibit = data;
return newExhibit;
}
1 change: 1 addition & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type TourDisplaysRow =
Database['public']['Tables']['tour_displays']['Row'];
export type TourMediaRow = Database['public']['Tables']['tour_media']['Row'];
export type TourRow = Database['public']['Tables']['tours']['Row'];
export type ExhibitRow = Database['public']['Tables']['exhibits']['Row'];
export type SpotlightRow = {
tour_row: TourRow;
url: string;
Expand Down

0 comments on commit 72ba091

Please sign in to comment.