gourami

[UNMAINTAINED] Activitypub server in Rust
Log | Files | Refs | README | LICENSE

commit ed468817f797cbc688b50bb5f711fbe30ec4055a
parent cbbe0c4c1e2414ff3a59e127902b51f4cad15702
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Fri, 17 Apr 2020 13:06:04 -0500

Allow deleted notes

Diffstat:
Msrc/db/status.rs | 1-
Msrc/main.rs | 13++++++++++++-
Mstatic/css/style.css | 19+++++++++++++++++++
Mtemplates/timeline.html | 8+++++++-
4 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/src/db/status.rs b/src/db/status.rs @@ -22,7 +22,6 @@ impl Note { pub fn get_for_user(conn: &SqliteConnection, user_id: i32) -> Vec<Self> { let results = note .filter(creator_id.eq(user_id)) - .limit(5) .load::<Self>(conn) .expect("Error loading posts"); results diff --git a/src/main.rs b/src/main.rs @@ -53,6 +53,13 @@ pub fn render_template<T: askama::Template>(t: &T) -> Response { .unwrap() } +fn delete_note(note_id: i32) -> impl Reply { + use db::schema::note::dsl::*; + let conn = establish_connection(); + diesel::delete(note.filter(id.eq(note_id))).execute(&conn).unwrap(); + warp::redirect::redirect(warp::http::Uri::from_static("/")) +} + #[derive(Deserialize)] struct NewNoteRequest { note_input: String, // has to be String @@ -120,12 +127,16 @@ async fn main() { .and(warp::body::form()) .map(|note_req: NewNoteRequest| new_note(&note_req)); + let delete_note = warp::path::param::<i32>() + .and(warp::path("delete")) + .map(|note_id| delete_note(note_id)); + // catch all for any other paths let not_found = warp::any().map(|| "404 not found"); let routes = warp::get().and( home.or(test).or(static_files).or(not_found)) - .or(warp::post().and(create_note)); + .or(warp::post().and(create_note.or(delete_note))); warp::serve(routes) .run(([127, 0, 0, 1], 3030)) .await; diff --git a/static/css/style.css b/static/css/style.css @@ -1,3 +1,22 @@ +.inline { + display: inline; +} + +.link-button { + background: none; + border: none; + color: blue; + text-decoration: underline; + cursor: pointer; + font-size: 1em; +} +.link-button:focus { + outline: none; +} +.link-button:active { + color:red; +} + .monospace { font-family: "courier", monospace } diff --git a/templates/timeline.html b/templates/timeline.html @@ -10,7 +10,13 @@ {% for note in notes %} <div class="row"> <div class="note"> - <a href="/note/{{note.id}}">#{{note.id}}</a> {{note.published}} | {{note.content}} <a href=/delete_note/{{note.id}}>x</a> + <a href="/note/{{note.id}}">#{{note.id}}</a> {{note.published}} | {{note.content}} + <form method="post" action="/{{note.id}}/delete" class="inline"> + <input type="hidden" name="extra_submit_param" value="extra_submit_value"> + <button type="submit" name="submit_param" value="submit_value" class="link-button"> + x + </button> + </form> </div> </div> {% endfor %}