This commit is contained in:
Tommy Parnell
2022-04-07 10:18:09 -04:00
parent 5645408d75
commit 6e18c2c7ef
8 changed files with 59 additions and 7 deletions

View File

@@ -1,4 +1,3 @@
import 'dotenv/config'
import type { EntryContext } from "@remix-run/node"; import type { EntryContext } from "@remix-run/node";
import { RemixServer } from "@remix-run/react"; import { RemixServer } from "@remix-run/react";
import { renderToString } from "react-dom/server"; import { renderToString } from "react-dom/server";

View File

@@ -19,9 +19,10 @@ export default function Index() {
return ( return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.4" }}> <div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.4" }}>
<h1>Welcome to Remix Heroku</h1> <h1>Welcome to Remix Heroku</h1>
<a href="/new">Add a new note</a>
<p> Notes: </p> <p> Notes: </p>
<ul> <ul>
{data.notes.map(({ id, name }) => ( <li key={name}>id: {id} name: {name}</li>))} {data.notes.map(({ id, name, content }) => ( <li key={name}>id: {id} name: {name} content: {content}</li>))}
</ul> </ul>

50
app/routes/new.tsx Normal file
View File

@@ -0,0 +1,50 @@
import type { ActionFunction } from "@remix-run/node";
import { redirect } from "@remix-run/node";
import { db } from "~/utils/db.server";
export const action: ActionFunction = async ({
request,
}) => {
const form = await request.formData();
const name = form.get("name");
const content = form.get("content");
// we do this type check to be extra sure and to make TypeScript happy
if (
typeof name !== "string" ||
typeof content !== "string"
) {
throw new Error(`Form not submitted correctly.`);
}
const fields = { name, content };
await db.note.create({ data: fields });
return redirect(`/`);
};
export default function NewNote() {
return (
<div>
<p>Add your own note</p>
<form method="post">
<div>
<label>
Name: <input type="text" name="name" />
</label>
</div>
<div>
<label>
Content: <textarea name="content" />
</label>
</div>
<div>
<button type="submit" className="button">
Add
</button>
</div>
</form>
</div>
);
}

5
package-lock.json generated
View File

@@ -10,7 +10,6 @@
"@remix-run/node": "^1.3.4", "@remix-run/node": "^1.3.4",
"@remix-run/react": "^1.3.4", "@remix-run/react": "^1.3.4",
"@remix-run/serve": "^1.3.4", "@remix-run/serve": "^1.3.4",
"dotenv": "^16.0.0",
"prisma": "^3.12.0", "prisma": "^3.12.0",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2" "react-dom": "^17.0.2"
@@ -3116,6 +3115,7 @@
"version": "16.0.0", "version": "16.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz",
"integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==", "integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==",
"dev": true,
"engines": { "engines": {
"node": ">=12" "node": ">=12"
} }
@@ -12104,7 +12104,8 @@
"dotenv": { "dotenv": {
"version": "16.0.0", "version": "16.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz",
"integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==" "integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==",
"dev": true
}, },
"duplexify": { "duplexify": {
"version": "3.7.1", "version": "3.7.1",

View File

@@ -14,7 +14,6 @@
"@remix-run/node": "^1.3.4", "@remix-run/node": "^1.3.4",
"@remix-run/react": "^1.3.4", "@remix-run/react": "^1.3.4",
"@remix-run/serve": "^1.3.4", "@remix-run/serve": "^1.3.4",
"dotenv": "^16.0.0",
"prisma": "^3.12.0", "prisma": "^3.12.0",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2" "react-dom": "^17.0.2"

View File

@@ -2,6 +2,7 @@
CREATE TABLE "Note" ( CREATE TABLE "Note" (
"id" SERIAL NOT NULL, "id" SERIAL NOT NULL,
"name" TEXT NOT NULL, "name" TEXT NOT NULL,
"content" TEXT NOT NULL,
CONSTRAINT "Note_pkey" PRIMARY KEY ("id") CONSTRAINT "Note_pkey" PRIMARY KEY ("id")
); );

View File

@@ -14,4 +14,5 @@ datasource db {
model Note { model Note {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
name String name String
content String
} }

View File

@@ -2,7 +2,7 @@ import { PrismaClient } from "@prisma/client";
const db = new PrismaClient(); const db = new PrismaClient();
async function seed() { async function seed() {
return db.note.create({ data: { name: "Note from the databae" }}); return db.note.create({ data: { name: "Note from the databae", content: " I am a new note :) " }});
} }
seed(); seed();