Преглед на файлове

Move new posts to their own page

master
Dylan Baker преди 4 години
родител
ревизия
09be7fa83e
променени са 7 файла, в които са добавени 52 реда и са изтрити 12 реда
  1. 3
    0
      oslo-lib/src/lib.rs
  2. 5
    0
      oslo-lib/src/routes.rs
  3. 20
    2
      static/style.css
  4. 7
    4
      templates/edit.html
  5. 3
    3
      templates/index.html
  6. 9
    3
      templates/layout.html
  7. 5
    0
      templates/new.html

+ 3
- 0
oslo-lib/src/lib.rs Целия файл

@@ -31,6 +31,9 @@ pub async fn build_app() -> Result<tide::Server<State>, tide::Error> {
31 31
     app.at("/posts")
32 32
         .with(require_auth)
33 33
         .post(routes::create_post);
34
+    app.at("/posts/new")
35
+        .with(require_auth)
36
+        .get(routes::new_post);
34 37
     app.at("/posts/:id")
35 38
         .get(routes::single_post)
36 39
         .post(routes::update_post)

+ 5
- 0
oslo-lib/src/routes.rs Целия файл

@@ -31,6 +31,11 @@ pub async fn single_post(req: Request<State>) -> Result {
31 31
     render_html_response("single.html", &context, req)
32 32
 }
33 33
 
34
+pub async fn new_post(req: Request<State>) -> Result {
35
+    let context = Context::new();
36
+    render_html_response("new.html", &context, req)
37
+}
38
+
34 39
 pub async fn edit_post(req: Request<State>) -> Result {
35 40
     let mut context = Context::new();
36 41
     let post_id = req.param("id")?;

+ 20
- 2
static/style.css Целия файл

@@ -42,7 +42,7 @@ a:hover {
42 42
   border-radius: 0;
43 43
   font-family: inherit;
44 44
   font-size: inherit;
45
-  padding: 0.15em 0.3em;
45
+  padding: 0.25em 0.5em;
46 46
   text-decoration: none;
47 47
 }
48 48
 
@@ -74,6 +74,7 @@ a:hover {
74 74
 .header {
75 75
   align-items: center;
76 76
   display: flex;
77
+  flex-wrap: wrap;
77 78
   justify-content: space-between;
78 79
   margin: 1em 0;
79 80
 }
@@ -83,10 +84,19 @@ a:hover {
83 84
   font-style: italic;
84 85
   font-weight: bold;
85 86
   letter-spacing: 2px;
87
+  margin: 0.5em 0.5em 0.5em 0;
86 88
   padding: 0.25em 0.5em;
87 89
   text-decoration: none;
88 90
 }
89 91
 
92
+.header__form {
93
+  display: flex;
94
+}
95
+
96
+.header__form .btn:first-child {
97
+  margin-right: 0.5em;
98
+}
99
+
90 100
 .form__field {
91 101
   margin: 1em 0;
92 102
 }
@@ -98,6 +108,7 @@ a:hover {
98 108
 
99 109
 .form__textarea,
100 110
 .form__text-field {
111
+  border: 2px solid var(--foreground);
101 112
   font-family: monospace;
102 113
   font-size: 14px;
103 114
   padding: 0.25em;
@@ -177,8 +188,15 @@ a:hover {
177 188
   background-color: var(--success-green);
178 189
 }
179 190
 
191
+.error {
192
+  background: var(--white);
193
+  border: 5px solid var(--danger-red);
194
+  padding: 1em;
195
+}
196
+
180 197
 .error__heading {
181
-  margin: 2em 0 1em;
198
+  color: var(--danger-red);
199
+  margin-bottom: 1em;
182 200
 }
183 201
 
184 202
 .error__message {

+ 7
- 4
templates/edit.html Целия файл

@@ -1,5 +1,8 @@
1
-{% extends "layout.html" %} {% block content %}
2
-<div class="posts">
3
-  {{ components::form(post=post, action="/posts/{{ post.id }}") }}
4
-</div>
1
+{% extends "layout.html" %}
2
+{% block content %}
3
+
4
+  <div class="posts">
5
+    {{ components::form(post=post, action="/posts/{{ post.id }}") }}
6
+  </div>
7
+
5 8
 {% endblock %}

+ 3
- 3
templates/index.html Целия файл

@@ -1,6 +1,5 @@
1
-{% extends "layout.html" %} {% block content %} {% if logged_in %}
2
-<h1 class="heading">New Post</h1>
3
-{{ components::form(action="/posts") }} {% endif %}
1
+{% extends "layout.html" %}
2
+{% block content %}
4 3
 
5 4
 <div class="posts">
6 5
   {% for post in posts %}
@@ -9,4 +8,5 @@
9 8
     No posts yet
10 9
   {% endfor %}
11 10
 </div>
11
+
12 12
 {% endblock %}

+ 9
- 3
templates/layout.html Целия файл

@@ -11,10 +11,16 @@
11 11
     <div class="container">
12 12
       <header class="header">
13 13
         <a class="header__logo btn" href="/">:: dlyan.net</a>
14
+
14 15
         {% if logged_in %}
15
-        <form action="/logout" method="POST">
16
-          <input class="btn" type="submit" value="Log out" />
17
-        </form>
16
+          <div class="header__auth">
17
+            <form class="header__form" action="/logout" method="POST">
18
+              <a href="/posts/new" class="btn">
19
+                new post
20
+              </a>
21
+              <input class="btn" type="submit" value="log out" />
22
+            </form>
23
+          </div>
18 24
         {% endif %}
19 25
       </header>
20 26
       <div class="messages">

+ 5
- 0
templates/new.html Целия файл

@@ -0,0 +1,5 @@
1
+{% extends 'layout.html' %}
2
+{% block content %}
3
+  <h1 class="heading">New Post</h1>
4
+  {{ components::form(action="/posts") }}
5
+{% endblock %}

Loading…
Отказ
Запис