1
|
mod data;
|
1
|
mod data;
|
2
|
|
2
|
|
|
|
3
|
+use artshop_common::types::MarkdownJson;
|
3
|
use js_sys::JsString;
|
4
|
use js_sys::JsString;
|
4
|
use log::Level;
|
5
|
use log::Level;
|
5
|
use mogwai::prelude::*;
|
6
|
use mogwai::prelude::*;
|
|
@@ -25,22 +26,13 @@ fn md_to_html(source: &str) -> String { |
|
@@ -25,22 +26,13 @@ fn md_to_html(source: &str) -> String { |
25
|
html_output
|
26
|
html_output
|
26
|
}
|
27
|
}
|
27
|
|
28
|
|
28
|
-#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
29
|
-pub struct MarkdownJson {
|
|
|
30
|
- pub name: String,
|
|
|
31
|
- pub content: String,
|
|
|
32
|
- pub number_of_versions: i32,
|
|
|
33
|
- pub date_created: String,
|
|
|
34
|
- pub date_updated: String,
|
|
|
35
|
-}
|
|
|
36
|
-
|
|
|
37
|
-async fn md_from_db() -> MarkdownJson {
|
29
|
+async fn md_from_db() -> Vec<MarkdownJson> {
|
38
|
let window = web_sys::window().unwrap();
|
30
|
let window = web_sys::window().unwrap();
|
39
|
let mut opts = RequestInit::new();
|
31
|
let mut opts = RequestInit::new();
|
40
|
opts.method("GET").mode(RequestMode::Cors);
|
32
|
opts.method("GET").mode(RequestMode::Cors);
|
41
|
|
33
|
|
42
|
let request = Request::new_with_str_and_init(
|
34
|
let request = Request::new_with_str_and_init(
|
43
|
- "/api/v0/markdowns/md-example?patch=3"
|
35
|
+ "/api/v0/markdowns/md-example?patch=1" // patch=1 always gets all patches.
|
44
|
, &opts ).unwrap();
|
36
|
, &opts ).unwrap();
|
45
|
request.headers().set("Accept", "application/json").unwrap();
|
37
|
request.headers().set("Accept", "application/json").unwrap();
|
46
|
|
38
|
|
|
@@ -51,9 +43,9 @@ async fn md_from_db() -> MarkdownJson { |
|
@@ -51,9 +43,9 @@ async fn md_from_db() -> MarkdownJson { |
51
|
. await.unwrap()
|
43
|
. await.unwrap()
|
52
|
. dyn_into::<JsString>().unwrap()
|
44
|
. dyn_into::<JsString>().unwrap()
|
53
|
);
|
45
|
);
|
54
|
- let data :MarkdownJson = serde_json::from_str(data.as_str()).unwrap();
|
46
|
+ let data :Vec<MarkdownJson> = serde_json::from_str(data.as_str()).unwrap();
|
55
|
|
47
|
|
56
|
- data.clone()
|
48
|
+ data
|
57
|
}
|
49
|
}
|
58
|
|
50
|
|
59
|
async fn md_to_db(md :MarkdownJson) {
|
51
|
async fn md_to_db(md :MarkdownJson) {
|
|
@@ -80,7 +72,7 @@ async fn md_to_db(md :MarkdownJson) { |
|
@@ -80,7 +72,7 @@ async fn md_to_db(md :MarkdownJson) { |
80
|
async fn editor_logic( mut rx_logic: broadcast::Receiver<AppLogic>
|
72
|
async fn editor_logic( mut rx_logic: broadcast::Receiver<AppLogic>
|
81
|
, tx_view: broadcast::Sender<String>
|
73
|
, tx_view: broadcast::Sender<String>
|
82
|
, mut rx_dom: broadcast::Receiver<Dom>
|
74
|
, mut rx_dom: broadcast::Receiver<Dom>
|
83
|
- , md :MarkdownJson ) {
|
75
|
+ , md :Vec<MarkdownJson> ) {
|
84
|
let dom = rx_dom.next().await.unwrap();
|
76
|
let dom = rx_dom.next().await.unwrap();
|
85
|
let mut show_edit = false;
|
77
|
let mut show_edit = false;
|
86
|
|
78
|
|
|
@@ -98,11 +90,11 @@ async fn editor_logic( mut rx_logic: broadcast::Receiver<AppLogic> |
|
@@ -98,11 +90,11 @@ async fn editor_logic( mut rx_logic: broadcast::Receiver<AppLogic> |
98
|
fn update(dom: &Dom) {
|
90
|
fn update(dom: &Dom) {
|
99
|
if let Either::Left(dom_js) = dom.inner_read() {
|
91
|
if let Either::Left(dom_js) = dom.inner_read() {
|
100
|
dom_js . to_owned()
|
92
|
dom_js . to_owned()
|
101
|
- . dyn_into::<Node>().unwrap()
|
|
|
102
|
- . child_nodes().get(1).unwrap()
|
|
|
103
|
- . child_nodes().get(1).unwrap()
|
|
|
104
|
- . dyn_into::<HtmlElement>().unwrap()
|
|
|
105
|
- . set_inner_html(md_to_html(get_md(dom).as_str()).as_str())
|
93
|
+ . dyn_into::<Node>().unwrap()
|
|
|
94
|
+ . child_nodes().get(1).unwrap()
|
|
|
95
|
+ . child_nodes().get(1).unwrap()
|
|
|
96
|
+ . dyn_into::<HtmlElement>().unwrap()
|
|
|
97
|
+ . set_inner_html(md_to_html(get_md(dom).as_str()).as_str())
|
106
|
};
|
98
|
};
|
107
|
}
|
99
|
}
|
108
|
|
100
|
|
|
@@ -137,7 +129,7 @@ async fn editor_logic( mut rx_logic: broadcast::Receiver<AppLogic> |
|
@@ -137,7 +129,7 @@ async fn editor_logic( mut rx_logic: broadcast::Receiver<AppLogic> |
137
|
while let Some(msg) = rx_logic.next().await {
|
129
|
while let Some(msg) = rx_logic.next().await {
|
138
|
match msg {
|
130
|
match msg {
|
139
|
AppLogic::Store => {
|
131
|
AppLogic::Store => {
|
140
|
- let mut new_md = md.clone();
|
132
|
+ let mut new_md = md[0].clone();
|
141
|
new_md.content = get_md(&dom);
|
133
|
new_md.content = get_md(&dom);
|
142
|
md_to_db(new_md).await;
|
134
|
md_to_db(new_md).await;
|
143
|
},
|
135
|
},
|
|
@@ -158,7 +150,7 @@ async fn editor_logic( mut rx_logic: broadcast::Receiver<AppLogic> |
|
@@ -158,7 +150,7 @@ async fn editor_logic( mut rx_logic: broadcast::Receiver<AppLogic> |
158
|
fn editor_view( tx_logic: broadcast::Sender<AppLogic>
|
150
|
fn editor_view( tx_logic: broadcast::Sender<AppLogic>
|
159
|
, rx_view: broadcast::Receiver<String>
|
151
|
, rx_view: broadcast::Receiver<String>
|
160
|
, tx_dom: broadcast::Sender<Dom>
|
152
|
, tx_dom: broadcast::Sender<Dom>
|
161
|
- , md: &MarkdownJson
|
153
|
+ , md: &Vec<MarkdownJson>
|
162
|
) -> ViewBuilder<Dom> {
|
154
|
) -> ViewBuilder<Dom> {
|
163
|
let ns = "http://www.w3.org/2000/svg";
|
155
|
let ns = "http://www.w3.org/2000/svg";
|
164
|
|
156
|
|
|
@@ -190,22 +182,151 @@ fn editor_view( tx_logic: broadcast::Sender<AppLogic> |
|
@@ -190,22 +182,151 @@ fn editor_view( tx_logic: broadcast::Sender<AppLogic> |
190
|
<div contenteditable="true"
|
182
|
<div contenteditable="true"
|
191
|
style:cursor="text"
|
183
|
style:cursor="text"
|
192
|
style:display=("none", rx_view)>
|
184
|
style:display=("none", rx_view)>
|
193
|
- <pre on:click=store_filter>{md.content.clone()}</pre>
|
185
|
+ <pre on:click=store_filter>{md[0].content.clone()}</pre>
|
194
|
</div>
|
186
|
</div>
|
195
|
<div>
|
187
|
<div>
|
|
|
188
|
+ <div>
|
|
|
189
|
+ <button>
|
|
|
190
|
+ <svg xmlns=ns viewBox="0 -1 24 24"
|
|
|
191
|
+ style:width="1.5em" style:height="1.5em"
|
|
|
192
|
+ style:fill="none">
|
|
|
193
|
+ <path xmlns=ns
|
|
|
194
|
+ style:fill="black"
|
|
|
195
|
+ d="M9.17154 11.508
|
|
|
196
|
+ L7.75732 10.0938
|
|
|
197
|
+ L12 5.85113
|
|
|
198
|
+ L16.2426 10.0938
|
|
|
199
|
+ L14.8284 11.508
|
|
|
200
|
+ L12 8.67956
|
|
|
201
|
+ L9.17154 11.508Z"/>
|
|
|
202
|
+ <path xmlns=ns
|
|
|
203
|
+ style:fill="black"
|
|
|
204
|
+ d="M9.17154 12.492
|
|
|
205
|
+ L7.75732 13.9062
|
|
|
206
|
+ L12 18.1489
|
|
|
207
|
+ L16.2426 13.9062
|
|
|
208
|
+ L14.8284 12.492
|
|
|
209
|
+ L12 15.3204
|
|
|
210
|
+ L9.17154 12.492Z"/>
|
|
|
211
|
+ <path xmlns=ns
|
|
|
212
|
+ style:fill="black"
|
|
|
213
|
+ style:fill_rule="evenodd"
|
|
|
214
|
+ style:clip_rule="evenodd"
|
|
|
215
|
+ d="M1 5
|
|
|
216
|
+ C1 2.79086 2.79086 1 5 1
|
|
|
217
|
+ H19
|
|
|
218
|
+ C21.2091 1 23 2.79086 23 5
|
|
|
219
|
+ V19
|
|
|
220
|
+ C23 21.2091 21.2091 23 19 23
|
|
|
221
|
+ H5
|
|
|
222
|
+ C2.79086 23 1 21.2091 1 19
|
|
|
223
|
+ V5Z
|
|
|
224
|
+ M5 3
|
|
|
225
|
+ H19
|
|
|
226
|
+ C20.1046 3 21 3.89543 21 5
|
|
|
227
|
+ V19
|
|
|
228
|
+ C21 20.1046 20.1046 21 19 21
|
|
|
229
|
+ H5
|
|
|
230
|
+ C3.89543 21 3 20.1046 3 19
|
|
|
231
|
+ V5
|
|
|
232
|
+ C3 3.89543 3.89543 3 5 3Z"/>
|
|
|
233
|
+ </svg>
|
|
|
234
|
+ </button>
|
|
|
235
|
+ <button>
|
|
|
236
|
+ <svg xmlns=ns viewBox="0 -1 32 32"
|
|
|
237
|
+ style:width="1.5em" style:height="1.5em"
|
|
|
238
|
+ style:enable_background="new 0 0 32 32"
|
|
|
239
|
+ style:fill="none"
|
|
|
240
|
+ style:stroke="#000"
|
|
|
241
|
+ style:stroke_width="2"
|
|
|
242
|
+ style:stroke_linecap="round"
|
|
|
243
|
+ style:stroke_linejoin="round"
|
|
|
244
|
+ style:stroke_miterlimit="10">
|
|
|
245
|
+ <ellipse xmlns=ns
|
|
|
246
|
+ cx="14" cy="8" rx="10" ry="5"/>
|
|
|
247
|
+ <line xmlns=ns
|
|
|
248
|
+ x1="24" y1="16" x2="24" y2="8"/>
|
|
|
249
|
+ <path xmlns=ns
|
|
|
250
|
+ d="M4,8 v8 c0,2.8,4.5,5,10,5
|
|
|
251
|
+ c1.2,0,2.3-0.1,3.4-0.3"/>
|
|
|
252
|
+ <path xmlns=ns
|
|
|
253
|
+ d="M4,16 v8 c0,2.8,4.5,5,10,5
|
|
|
254
|
+ c2,0,3.8-0.3,5.3-0.8"/>
|
|
|
255
|
+ <circle xmlns=ns
|
|
|
256
|
+ cx="24" cy="23" r="7"/>
|
|
|
257
|
+ <line xmlns=ns
|
|
|
258
|
+ x1="24" y1="16" x2="24" y2="26"/>
|
|
|
259
|
+ <polyline xmlns=ns
|
|
|
260
|
+ points="21,23 24,26 27,23"/>
|
|
|
261
|
+ </svg>
|
|
|
262
|
+ </button>
|
|
|
263
|
+ <button>
|
|
|
264
|
+ <svg xmlns=ns viewBox="10.3 3.8 76.2 88.7"
|
|
|
265
|
+ style:width="1.5em" style:height="1.5em">
|
|
|
266
|
+ <g xmlns=ns id="_x37_0">
|
|
|
267
|
+ <polygon xmlns=ns
|
|
|
268
|
+ points="35.4,18.1 31.1,4.3 31.1,16.3
|
|
|
269
|
+ 24.5,16.3 24.5,10.9 18.3,18.9
|
|
|
270
|
+ 13.8,23.7 17,23.7 19.8,31.8
|
|
|
271
|
+ 27.9,34.1 27.9,37.8 38.7,41.8
|
|
|
272
|
+ 38.7,34.1 38.7,30.4 38.7,25.2
|
|
|
273
|
+ 46.8,25.2 "/>
|
|
|
274
|
+ <path xmlns=ns
|
|
|
275
|
+ d="M75.7,39.9 h-8.3 h-40.5 h-8.3 h-3 v9.5
|
|
|
276
|
+ v2 h4.7 c2.2,13.3,6.8,42.2,6.8,42.2 h40
|
|
|
277
|
+ c0,0,4.6-27.6,7-42.2 h4.7 v-2 v-9.5
|
|
|
278
|
+ H75.7z
|
|
|
279
|
+ M67.7,51.4 l-2.6,15.6 l-6.1-6.9 l8-8.7
|
|
|
280
|
+ H67.7z
|
|
|
281
|
+ M63.7,75.6 l-1.3,7.9 l-2.9-3.2
|
|
|
282
|
+ L63.7,75.6z
|
|
|
283
|
+ M56.6,77.2
|
|
|
284
|
+ L50,70 l6.2-6.7 l6.4,7.3
|
|
|
285
|
+ L56.6,77.2z
|
|
|
286
|
+ M52.4,51.4 h8.9 l-5.1,5.5 l-4.8-5.4
|
|
|
287
|
+ C51.8,51.4,52.1,51.4,52.4,51.4z
|
|
|
288
|
+ M53.3,60 l-6.2,6.8 l-6.6-7.2 l6.4-6.9
|
|
|
289
|
+ L53.3,60z
|
|
|
290
|
+ M30.5,74.9 l4.6,5 l-3.2,3.5
|
|
|
291
|
+ L30.5,74.9z
|
|
|
292
|
+ M31.4,69.6 l6.2-6.8 l6.6,7.2 l-6.2,6.8
|
|
|
293
|
+ L31.4,69.6z
|
|
|
294
|
+ M41.9,51.4 c0.1,0,0.2,0,0.3,0 l-4.7,5.1
|
|
|
295
|
+ l-4.7-5.1
|
|
|
296
|
+ H41.9z
|
|
|
297
|
+ M27.1,51.4 l7.6,8.3 l-5.7,6.2l-2.3-14.5
|
|
|
298
|
+ H27.1z
|
|
|
299
|
+ M34.6,86.7 l3.3-3.6 l3.3,3.6
|
|
|
300
|
+ H34.6z
|
|
|
301
|
+ M47.1,86.7 l-6.2-6.8 l6.2-6.8 l6.6,7.2
|
|
|
302
|
+ l-5.8,6.4
|
|
|
303
|
+ H47.1z
|
|
|
304
|
+ M53.7,86.7 l2.9-3.2 l3,3.2
|
|
|
305
|
+ H53.7z"/>
|
|
|
306
|
+ </g>
|
|
|
307
|
+ </svg>
|
|
|
308
|
+ </button>
|
196
|
<button on:click=toggle_filter>
|
309
|
<button on:click=toggle_filter>
|
197
|
- <svg version="1.1" id="Capa_1" xmlns=ns
|
|
|
198
|
- x="0px" y="0px" viewBox="0 0 220.001 220.001"
|
310
|
+ <svg xmlns=ns viewBox="0 0 220.001 220.001"
|
199
|
style:width="1.5em" style:height="1.5em">
|
311
|
style:width="1.5em" style:height="1.5em">
|
200
|
<g xmlns=ns>
|
312
|
<g xmlns=ns>
|
201
|
- <polygon xmlns=ns points="0,220 59.34,213.86 6.143,160.661"></polygon>
|
|
|
202
|
- <path xmlns=ns d="M132.018,34.787l53.197,53.197L69.568,203.631L16.37,
|
|
|
203
|
- 150.434L132.018,34.787z M212.696,60.502c9.738-9.738,9.742-25.527,
|
|
|
204
|
- 0-35.268l-17.93-17.93c-9.738-9.74-25.529-9.738-35.268,0l-17.346,
|
|
|
205
|
- 17.347l53.199,53.196L212.696,60.502z"></path>
|
313
|
+ <polygon xmlns=ns
|
|
|
314
|
+ points="0,220 59.34,213.86 6.143,160.661"/>
|
|
|
315
|
+ <path xmlns=ns
|
|
|
316
|
+ d="M132.018,34.787 l53.197,53.197
|
|
|
317
|
+ L69.568,203.631
|
|
|
318
|
+ L16.37,150.434
|
|
|
319
|
+ L132.018,34.787z
|
|
|
320
|
+ M212.696,60.502
|
|
|
321
|
+ c9.738,-9.738,9.742,-25.527,0,-35.268
|
|
|
322
|
+ l-17.93,-17.93
|
|
|
323
|
+ c-9.738,-9.74,-25.529,-9.738,-35.268,0
|
|
|
324
|
+ l-17.346,17.347 l53.199,53.196
|
|
|
325
|
+ L212.696,60.502z"/>
|
206
|
</g>
|
326
|
</g>
|
207
|
</svg>
|
327
|
</svg>
|
208
|
</button>
|
328
|
</button>
|
|
|
329
|
+ </div>
|
209
|
<div></div>
|
330
|
<div></div>
|
210
|
<div></div>
|
331
|
<div></div>
|
211
|
<div></div>
|
332
|
<div></div>
|