-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Beginning work on 'Talk' page route, with functional sqlite integrati…
…on. Potentially needs captcha integration, admin panel, submission page, and styling for displaying existing talks
- Loading branch information
Ezekiel
committed
Jul 15, 2024
1 parent
17d95df
commit 0c09040
Showing
9 changed files
with
1,413 additions
and
38 deletions.
There are no files selected for viewing
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,39 @@ | ||
import { NextResponse } from 'next/server'; | ||
|
||
const db = require('better-sqlite3')('./talks.db'); | ||
db.pragma('journal_mode = WAL'); | ||
|
||
db.prepare(` | ||
CREATE TABLE IF NOT EXISTS Talks ( | ||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
description TEXT, | ||
speaker TEXT, | ||
title TEXT | ||
); | ||
`).run(); | ||
|
||
const getTalks = async () => { | ||
const stmt = db.prepare('SELECT * FROM talks'); | ||
const talks = stmt.all(); | ||
return talks; | ||
} | ||
|
||
export { getTalks }; | ||
|
||
export async function GET() { | ||
const talks = getTalks(); | ||
return NextResponse.json({data: talks}); | ||
} | ||
|
||
export async function POST(req) { | ||
const formData = await req.formData(); | ||
const description = formData.get("description"); | ||
const speaker = formData.get("speaker"); | ||
const title = formData.get("title"); | ||
const stmt = db.prepare(` | ||
INSERT INTO Talks (description, speaker, title) | ||
VALUES (?, ?, ?) | ||
`); | ||
stmt.run(description, speaker, title); | ||
return NextResponse.redirect(new URL("/talk/submitted", req.url)); | ||
}; |
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,20 @@ | ||
body { | ||
font-size: 18pt; | ||
} | ||
|
||
form { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr; | ||
gap: 0.5em; | ||
padding: 0.5em; | ||
} | ||
|
||
input, textarea, button { | ||
font-size: inherit; | ||
padding: 0.5em; | ||
} | ||
|
||
textarea { | ||
grid-column: span 2; | ||
resize: vertical; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,18 @@ | ||
export default function Talk() { | ||
return <main>/talk</main> | ||
} | ||
import { getTalks } from "../api/talk-requests/route"; | ||
import "./page.css"; | ||
|
||
export default async function Talk() { | ||
const data = await getTalks(); | ||
return ( | ||
<main> | ||
Current talks: {JSON.stringify(data)} <br /> | ||
<form className="max-w-screen-md m-auto" action="/api/talk-requests" method="POST"> | ||
<input type="text" placeholder="Speaker Name" name="speaker" /> | ||
<input type="text" placeholder="Talk Title" name="title" /> | ||
<textarea placeholder="Talk Description..." name="description"></textarea> | ||
<input className="btn hover:bg-accent hover:text-base-100" type="reset" value="Reset" /> | ||
<button className="btn hover:bg-accent hover:text-base-100">Submit</button> | ||
</form> | ||
</main> | ||
) | ||
} |
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,7 @@ | ||
export default async function TalkSubmitted() { | ||
return ( | ||
<main> | ||
did done | ||
</main> | ||
) | ||
} |
Oops, something went wrong.