-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters