Skip to content

Commit

Permalink
make the readme real-ish
Browse files Browse the repository at this point in the history
  • Loading branch information
swlkr committed May 7, 2024
1 parent 308563f commit b28e744
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ async fn index() -> Html {
use ryde::*;

db!(
create_todos = "create table if not exists todos (
id integer primary key,
content text not null,
created_at integer not null default(unixepoch())
)",
create_todos = "
create table if not exists todos (
id integer primary key,
content text not null,
created_at integer not null default(unixepoch())
);",
insert_todo = "insert into todos (content) values (?)",
todos = "select * from todos order by created_at desc limit 30"
);
Expand All @@ -73,7 +74,7 @@ struct AppState {
some_state: String
};

embed_static_files!("static", files_handler);
embed_static_files!("static");

#[main]
async fn main() {
Expand Down Expand Up @@ -102,7 +103,7 @@ async fn get_todos() -> Result<Html> {
})
}

async fn post_todos(Form(todo): Form<InsertTodo>) -> Result<Html> {
async fn post_todos(Form(todo): Form<InsertTodo>) -> Result<Response> {
let _todo = insert_todo(todo.content).await?;

Ok(redirect_to!(get_todos))
Expand All @@ -117,23 +118,21 @@ fn Form(action: &str, elements: Elements) -> Component {
}

fn TodoForm() -> Component {
let names = cols!(insert_todo);
let InsertTodoNames { content } = InsertTodo::names();

html! {
<Form action={url!(todos_create)}>
<input type="text" name={names.content} />
<input type="text" name={content} />
<input type="submit" name="save" />
</Form>
}
}

fn TodoList(todos: Vec<Todos>) -> Component {
let todos = map!(todos, TodoListItem);

html! {
<div class="text-black dark:text-white">
<h1 class="text-2xl">todos</h1>
<ul>{todos}</ul>
<ul>{todos.iter().map(|todo| html! { <TodoListItem todo=todo /> })}</ul>
<TodoForm />
</div>
}
Expand Down

0 comments on commit b28e744

Please sign in to comment.