Compare commits

...

4 Commits

Author SHA1 Message Date
andrzej ed8e71694f add create story page 2024-06-11 19:14:30 +02:00
andrzej d54b8180ce fix imports 2024-06-11 19:14:08 +02:00
andrzej b36f0edfb1 rename db with .ts extension
(it turns out typescript/nextjs is buggy with mjs)
2024-06-11 19:13:37 +02:00
andrzej 25f8f728c9 add lettercase function 2024-06-11 19:12:52 +02:00
7 changed files with 44 additions and 2 deletions

3
src/app/lib/functions.ts Normal file
View File

@ -0,0 +1,3 @@
export function letterCase(str: String) {
return str.charAt(0).toUpperCase() + str.slice(1)
}

View File

@ -1,4 +1,5 @@
import prisma from "../../lib/db.mjs" // "use server"
import prisma from "app/lib/db"
async function getStory(id: string) { async function getStory(id: string) {
const story = await prisma.story.findFirst({ where: { id: Number(id) } }) const story = await prisma.story.findFirst({ where: { id: Number(id) } })

View File

@ -0,0 +1,5 @@
import StoryForm from "app/ui/forms/story";
export default function Page() {
return <StoryForm />
}

View File

@ -0,0 +1,21 @@
import prisma from "app/lib/db"
import React from "react"
import { letterCase } from "app/lib/functions"
export default async function GenreCheckboxes() {
async function getGenres() {
"use server"
const genres = await prisma.genre.findMany()
return genres
}
const genres = await getGenres()
const genreCheckboxes = genres.map(e => {
const label = letterCase(e.name)
return (<React.Fragment key={`fragment${e.name}`}>
<input type="checkbox" id={e.name} key={`genreCheckboxInput${e.id}`} />
<label htmlFor={e.name} key={`genreCheckboxLabel${e.id}`}>{label}</label>
</React.Fragment>
)
})
return <>{genreCheckboxes}</>
}

View File

@ -0,0 +1,10 @@
import GenreCheckboxes from "./genreCheckboxes"
export default async function StoryForm() {
return <form>
<label htmlFor="title">Title:</label>
<input type="text" id="title" />
<label htmlFor="word-count">Word Count:</label>
<input type="text" id="word-count" />
<GenreCheckboxes />
</form>
}

View File

@ -1,5 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"baseUrl": "src/",
"lib": [ "lib": [
"dom", "dom",
"dom.iterable", "dom.iterable",
@ -26,7 +27,8 @@
"next-env.d.ts", "next-env.d.ts",
".next/types/**/*.ts", ".next/types/**/*.ts",
"**/*.ts", "**/*.ts",
"**/*.tsx" "**/*.tsx",
"src/app/lib/db.ts"
], ],
"exclude": [ "exclude": [
"node_modules" "node_modules"