-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathClickToLoad.fs
More file actions
67 lines (59 loc) · 1.7 KB
/
Copy pathClickToLoad.fs
File metadata and controls
67 lines (59 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
open System
open Falco
open Falco.Markup
open Falco.Routing
open Falco.Htmx
open Microsoft.AspNetCore.Builder
let view (page : int) =
let loadMoreButton (page : int) =
_tr [ _id_ "replace-me" ] [
_td [ _colspan_ "3" ] [
_button [
Hx.get $"/contacts?page={page}"
Hx.targetCss "#replace-me"
Hx.swapOuterHtml
Hx.select "tr"
] [ _text "Load More Agents..." ] ]
]
let agentRows (page : int) =
[
let min = (page - 1) * 10 + 1
let max = page * 10
for i = min to max do
_tr [] [
_td [] [ _text "Agent Smith" ]
_td [] [ _text $"void{i}@null.org" ]
_td [] [ _text (Guid.NewGuid().ToString "n") ]
]
loadMoreButton (page + 1)
]
_html [] [
_head [] [
_script [ _src_ HtmxScript.cdnSrc ] [] ]
_body [] [
_table [] [
_thead [] [
_th [] [ _text "Name" ]
_th [] [ _text "Email" ]
_th [] [ _text "ID" ]
]
_tbody [ _id_ "agent-rows" ] (agentRows page)
]
]
]
let handleIndex : HttpHandler =
Response.ofHtml (view 1)
let handleClick : HttpHandler =
Request.mapQuery
(fun q -> q.GetInt "page")
(fun page ->
Response.ofFragment "agent-rows" (view page))
let wapp = WebApplication.Create()
let endpoints =
[
get "/" handleIndex
get "/contacts" handleClick
]
wapp.UseRouting()
.UseFalco(endpoints)
.Run()