Skip to content

Commit

Permalink
Beginning work on 'Talk' page route, with functional sqlite integrati…
Browse files Browse the repository at this point in the history
…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
Show file tree
Hide file tree
Showing 9 changed files with 1,413 additions and 38 deletions.
39 changes: 39 additions & 0 deletions app/api/talk-requests/route.js
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));
};
20 changes: 20 additions & 0 deletions app/talk/page.css
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;
}
21 changes: 18 additions & 3 deletions app/talk/page.tsx
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>
)
}
7 changes: 7 additions & 0 deletions app/talk/submitted/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default async function TalkSubmitted() {
return (
<main>
did done
</main>
)
}
Loading

0 comments on commit 0c09040

Please sign in to comment.