Browse Source

Move new posts to their own page

master
Dylan Baker 4 years ago
parent
commit
09be7fa83e
7 changed files with 52 additions and 12 deletions
  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 View File

31
     app.at("/posts")
31
     app.at("/posts")
32
         .with(require_auth)
32
         .with(require_auth)
33
         .post(routes::create_post);
33
         .post(routes::create_post);
34
+    app.at("/posts/new")
35
+        .with(require_auth)
36
+        .get(routes::new_post);
34
     app.at("/posts/:id")
37
     app.at("/posts/:id")
35
         .get(routes::single_post)
38
         .get(routes::single_post)
36
         .post(routes::update_post)
39
         .post(routes::update_post)

+ 5
- 0
oslo-lib/src/routes.rs View File

31
     render_html_response("single.html", &context, req)
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
 pub async fn edit_post(req: Request<State>) -> Result {
39
 pub async fn edit_post(req: Request<State>) -> Result {
35
     let mut context = Context::new();
40
     let mut context = Context::new();
36
     let post_id = req.param("id")?;
41
     let post_id = req.param("id")?;

+ 20
- 2
static/style.css View File

42
   border-radius: 0;
42
   border-radius: 0;
43
   font-family: inherit;
43
   font-family: inherit;
44
   font-size: inherit;
44
   font-size: inherit;
45
-  padding: 0.15em 0.3em;
45
+  padding: 0.25em 0.5em;
46
   text-decoration: none;
46
   text-decoration: none;
47
 }
47
 }
48
 
48
 
74
 .header {
74
 .header {
75
   align-items: center;
75
   align-items: center;
76
   display: flex;
76
   display: flex;
77
+  flex-wrap: wrap;
77
   justify-content: space-between;
78
   justify-content: space-between;
78
   margin: 1em 0;
79
   margin: 1em 0;
79
 }
80
 }
83
   font-style: italic;
84
   font-style: italic;
84
   font-weight: bold;
85
   font-weight: bold;
85
   letter-spacing: 2px;
86
   letter-spacing: 2px;
87
+  margin: 0.5em 0.5em 0.5em 0;
86
   padding: 0.25em 0.5em;
88
   padding: 0.25em 0.5em;
87
   text-decoration: none;
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
 .form__field {
100
 .form__field {
91
   margin: 1em 0;
101
   margin: 1em 0;
92
 }
102
 }
98
 
108
 
99
 .form__textarea,
109
 .form__textarea,
100
 .form__text-field {
110
 .form__text-field {
111
+  border: 2px solid var(--foreground);
101
   font-family: monospace;
112
   font-family: monospace;
102
   font-size: 14px;
113
   font-size: 14px;
103
   padding: 0.25em;
114
   padding: 0.25em;
177
   background-color: var(--success-green);
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
 .error__heading {
197
 .error__heading {
181
-  margin: 2em 0 1em;
198
+  color: var(--danger-red);
199
+  margin-bottom: 1em;
182
 }
200
 }
183
 
201
 
184
 .error__message {
202
 .error__message {

+ 7
- 4
templates/edit.html View File

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
 {% endblock %}
8
 {% endblock %}

+ 3
- 3
templates/index.html View File

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
 <div class="posts">
4
 <div class="posts">
6
   {% for post in posts %}
5
   {% for post in posts %}
9
     No posts yet
8
     No posts yet
10
   {% endfor %}
9
   {% endfor %}
11
 </div>
10
 </div>
11
+
12
 {% endblock %}
12
 {% endblock %}

+ 9
- 3
templates/layout.html View File

11
     <div class="container">
11
     <div class="container">
12
       <header class="header">
12
       <header class="header">
13
         <a class="header__logo btn" href="/">:: dlyan.net</a>
13
         <a class="header__logo btn" href="/">:: dlyan.net</a>
14
+
14
         {% if logged_in %}
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
         {% endif %}
24
         {% endif %}
19
       </header>
25
       </header>
20
       <div class="messages">
26
       <div class="messages">

+ 5
- 0
templates/new.html View File

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

Loading…
Cancel
Save