Delete api

This commit is contained in:
Clay Nicholson 2024-08-16 22:56:03 -04:00
parent 6aea94a519
commit e7bd3efbd7
4 changed files with 61 additions and 4 deletions

View file

@ -6,7 +6,18 @@ import { Button } from 'theme-ui'
const CohortCard = ({ id, title = "Title Not Found", desc = "Description Not Found", slack = "Slack Not Found", scrapbook = "", playLink = "", images = [], githubProf, githubLink = "", draggable = false, personal = false}) => {
const [isHovered, setIsHovered] = useState(false);
const handleDelete = async () => {
const { status, formProps, useField, data } = useForm(
`/api/arcade/showcase/projects/${project.id}/edit`,
publishedChanges,
{
method: 'PATCH',
initData: { ...project, recordId: project.id },
bearer: window.localStorage.getItem('arcade.authToken')
}
)
return;
}
@ -25,7 +36,7 @@ const CohortCard = ({ id, title = "Title Not Found", desc = "Description Not Fou
)}
<a href={`/arcade/showcase/project/${id}`} className={styles.linkWrapper} target="_blank" rel="noopener noreferrer">
<img
src={firstImage}
src={images[0] || "https://picsum.photos/200"}
alt="Project Image"
className={styles.card_img}
/>

View file

@ -1,7 +1,7 @@
import styles from './project-view.module.css'
import { Button } from 'theme-ui'
const ProjectView = ({ id, title = "Title Not Found", desc = "Description Not Found", slack = "Slack Not Found", scrapbook = "", playLink = "", images = [], githubProf, codeLink = ""}) => {
const ProjectView = ({ id, title = "Title Not Found", desc = "Description Not Found", slack = "Slack Not Found", scrapbook = "", playLink, images = [], githubProf, codeLink = ""}) => {
const codeHost = codeLink.includes('github') ? 'View on GitHub' : 'View code link'
return (
<div className={styles.container}>
@ -16,6 +16,7 @@ const ProjectView = ({ id, title = "Title Not Found", desc = "Description Not Fo
<p className={styles.description}>{desc}</p>
<div className={styles.buttonGroup}>
{playLink && (
<Button
as="a"
sx={{ backgroundColor: '#1d571d', color: '#ebebeb', textSizeAdjust: "16px" }}
@ -24,7 +25,9 @@ const ProjectView = ({ id, title = "Title Not Found", desc = "Description Not Fo
rel="noopener"
>
Play Game
</Button>
</Button>)}
<Button
as="a"
sx={{ backgroundColor: '#0f0f0f', color: '#ebebeb', textSizeAdjust: "16px" }}

View file

@ -0,0 +1,43 @@
import AirtablePlus from "airtable-plus";
import { ensureAuthed } from "../../login/test";
import { DefaultLegendContent } from "recharts";
export default async function handler(req, res) {
const user = await ensureAuthed(req)
if (user.error) {
return res.status(401).json(user)
}
const body = req.body
if (!body) {
return res.status(400).json({ error: "No body provided" })
}
const updatedFields = {}
updatedFields['deleted'] = true;
const airtable = new AirtablePlus({
apiKey: process.env.AIRTABLE_API_KEY,
baseID: 'app4kCWulfB02bV8Q',
tableName: "Showcase"
})
const { projectID } = req.query
const project = await airtable.update(projectID, updatedFields )
const results = {
id: project.id,
title: project.fields['Name'] || '',
desc: project.fields['Description'] || '',
slackLink: project.fields['Slack Link'] || '',
codeLink: project.fields['Code Link'] || '',
slackLink: project.fields['Slack Link'] || '',
playLink: project.fields['Play Link'] || '',
images: (project.fields['Screenshot'] || []).map(i => i.url),
githubProf: project.fields['Github Profile'] || '',
deleted: project.fields['deleted'] || ''
}
return res.status(200).json({ project: results })
}

View file

@ -14,7 +14,7 @@ export default async function handler(req, res) {
})
const projects = await airtable.read({
filterByFormula: `{User} = '${user.fields['Name']}'`
filterByFormula: `AND({User} = '${user.fields['Name']}', NOT({deleted}))`
})
const results = projects.map(p => ({