summaryrefslogtreecommitdiff
path: root/main.ur
blob: 54ccb141965530a1c0cfd381a0fd0c762962a4a7 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
(* Copyright 2016, 2017 Benjamin Barenblat

Licensed under the Apache License, Version 2.0 (the “License”); you may not use
this file except in compliance with the License.  You may obtain a copy of the
License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.  See the License for the
specific language governing permissions and limitations under the License. *)

table nextAction : { Id : int, Nam : string, Done : bool } PRIMARY KEY Id

sequence nextActionId

fun markNextActionStatus id done =
    dml (UPDATE nextAction SET Done = {[done]} WHERE Id = {[id]})

fun renderNextAction action : transaction xbody =
    c <- Material.Checkbox.make
             action.Done
             (fn b => rpc (markNextActionStatus action.Id b));
    return (Material.List.SingleLine.item {Icon = c,
                                           Content = cdata action.Nam})

val renderNextActions =
    queryX1' (SELECT * FROM nextAction WHERE nextAction.Done = FALSE)
             renderNextAction

fun newNextAction name =
    id <- nextval nextActionId;
    dml (INSERT INTO nextAction (Id, Nam, Done)
         VALUES ({[4 + id]}, {[name]}, FALSE));
    renderNextActions


style hidden
style visible

datatype mode = NextActions | NewNextAction

val main =
    actionItems <- bind renderNextActions source;
    mode <- source NextActions;
    floatingActionButton <- Material.FloatingActionButton.make
                                "add"
                                (fn _ => set mode NewNextAction);
    let
        val head = <xml>
          (* TODO(bbaren): Write a meta-description tag. *)
          <title>Next actions</title>

          (* TODO(bbaren): Support homescreen tiles for Chrome on Android,
          Safari on iOS, and Windows 8. *)

          <link rel="stylesheet" href="/ugtd.css" />
        </xml>

        val body = <xml>
          <div dynClass={currentMode <- signal mode;
                         return (case currentMode of
                                     NewNextAction => visible
                                   | _ => hidden)}>
            {Material.AppBar.make "New action"}
          </div>
          <div dynClass={currentMode <- signal mode;
                         return (case currentMode of
                                     NextActions => visible
                                   | _ => hidden)}>
            {Material.AppBar.make "Next actions"}
            {Material.List.SingleLine.make
                 <xml><dyn signal={signal actionItems} /></xml>}
            {floatingActionButton}
          </div>
        </xml>
    in
        return (Material.page {Head = head, Body = body})
    end