From 1175a57539359689ca172f49c56e59775f59ded6 Mon Sep 17 00:00:00 2001 From: Gunwant Jain Date: Tue, 13 Jul 2021 01:38:22 +0530 Subject: [PATCH] index: Add select for choosing languages when pasting Signed-off-by: Gunwant Jain --- src/routes/submit.rs | 8 +- templates/index.html.tera | 157 +++++++++++++++++++++++++++++--------- 2 files changed, 125 insertions(+), 40 deletions(-) diff --git a/src/routes/submit.rs b/src/routes/submit.rs index 4e2547f..521a218 100644 --- a/src/routes/submit.rs +++ b/src/routes/submit.rs @@ -7,6 +7,7 @@ use crate::models::paste_id::PasteId; #[derive(FromForm)] pub struct PasteIdForm { val: String, + ext: String, } #[post("/submit", data = "")] @@ -14,9 +15,10 @@ pub async fn submit(paste: Form) -> Redirect { let id = PasteId::new(6); let filename = format!("upload/{id}", id = id); - let content = paste.into_inner().val; + let content = &paste.val; + let ext = &paste.ext; fs::write(&filename, content).expect("Unable to write to the file"); - Redirect::to(format!("/p/{id}", id = id)) -} \ No newline at end of file + Redirect::to(format!("/p/{id}.{ext}", id = id, ext = ext)) +} diff --git a/templates/index.html.tera b/templates/index.html.tera index 268a46b..f9d4649 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -3,58 +3,76 @@ {% block styles %} html, body { -overflow-y:hidden; + overflow-y:hidden; } body { -height: 100vh; -font-family: monospace; + height: 100vh; + font-family: monospace; -display: flex; + display: grid; } -form { flex: 1; } +.grid_form { + display: grid; + grid-template-columns: 4fr 1fr 1fr; + height: 100vh; + align-items: start; + justify-items: center; +} textarea { -height: 100%; -width: 100%; + height: 90%; + width: 100%; -background: none; -border: none; + background: none; + border: none; -resize: none; -overflow: auto; + resize: none; + overflow: auto; -color: inherit; -font-family: monospace; -line-height: inherit; + color: inherit; + font-family: monospace; + line-height: inherit; +} + +select { + color: inherit; + background-color: #0f1419; + border: none; + padding: 0 1em 0 0; + margin: 0; + width: 80%; + font-family: inherit; + font-size: inherit; + cursor: inherit; + line-height: inherit; } button[type="submit"] { -position: absolute; -bottom: 1rem; -right: 1rem; - -height: 4rem; -width: 4rem; -border: none; -border-radius: 50%; -background: #F29718; - -font-size: 0rem; - -cursor: pointer; + background-color: #F29718; + border: none; + padding: 0 1em 0 0; + margin: 0; + width: 70%; + font-family: inherit; + font-size: inherit; + line-height: inherit; + cursor: pointer; } *:focus { -outline: none; + outline: none; } +select.hidden { display: none; } button[type="submit"].hidden { display: none; } + {% endblock styles %} {% block body %}
+
- + + + +