From 895e61772fa551d20f2695747f713322162ba085 Mon Sep 17 00:00:00 2001 From: Nettika Date: Sun, 25 Jan 2026 15:29:12 -0800 Subject: [PATCH] Add a project creation form --- TODO.md | 2 +- src/main.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 01c514b..b7c2acf 100644 --- a/TODO.md +++ b/TODO.md @@ -9,4 +9,4 @@ [x] Using a Rouille router, create `GET /main.css` and `GET /project-card.js` endpoints that returns the relevant files. Use the include_bytes! macro. [x] Create a `GET /projects` endpoint. Using Maud for markup generation, have this endpoint return an HTML page that shows all projects. Each project should be a `project-card` web component. Keep the page simple: no title or any buttons currently. [x] Create a `POST /projects` endpoint that accepts URL encoded data and creates a new project. -[ ] Create a `GET /new-project` endpoint that returns a HTML page with a project creation form. Keep it simple. \ No newline at end of file +[x] Create a `GET /new-project` endpoint that returns a HTML page with a project creation form. Keep it simple. \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 09f6d1a..5bbc2ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ fn main() { rouille::Response::from_data("application/javascript", js.as_ref()) }, (GET) ["/projects"] => display_projects(), + (GET) ["/new-project"] => new_project_form(), (POST) ["/projects"] => create_project(request), _ => rouille::Response::empty_404() ) @@ -95,6 +96,32 @@ fn display_projects() -> rouille::Response { rouille::Response::html(markup.into_string()) } +fn new_project_form() -> rouille::Response { + let markup = html! { + (DOCTYPE) + html { + head { + meta charset="utf-8"; + meta name="viewport" content="width=device-width, initial-scale=1"; + link rel="stylesheet" href="/main.css"; + } + body { + main { + h1 { "New Project" } + form method="POST" action="/projects" { + label for="title" { "Project Title:" } + input type="text" id="title" name="title" required; + button type="submit" { "Create Project" } + } + a href="/projects" { "Cancel" } + } + } + } + }; + + rouille::Response::html(markup.into_string()) +} + fn create_project(request: &rouille::Request) -> rouille::Response { let input = try_or_400!(rouille::post_input!(request, { title: String,