From 18b26edf08b15fc895da18cc11c23764bc8700bc Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Thu, 25 Jun 2015 20:29:30 -0400 Subject: Make editing modal --- main.ur | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 14 deletions(-) (limited to 'main.ur') diff --git a/main.ur b/main.ur index 6eb1562..4110c96 100644 --- a/main.ur +++ b/main.ur @@ -30,6 +30,20 @@ table article : { Title : string, CONSTRAINT Head FOREIGN KEY Head REFERENCES commit(Id) +datatype mode = View | Edit +val eq_mode = + mkEq (fn x y => + case (x, y) of + (View, View) => True + | (Edit, Edit) => True + | _ => False) + +fun only_in mode_source target_mode = + current_mode <- signal mode_source; + return (if current_mode = target_mode + then null + else Style.invisible) + fun commit_article title text : transaction unit = id <- nextval commit_id_next; creation_time <- now; @@ -49,6 +63,7 @@ fun commit_article title text : transaction unit = WHERE Title = {[title]}) fun wiki requested_article_title = + (* Look up the article. *) extant_articles <- queryL (SELECT article.Title, commit.Content FROM article LEFT JOIN commit ON article.Head = commit.Id @@ -65,7 +80,12 @@ fun wiki requested_article_title = ‘{[requested_article_title]}’ in + (* Stuff the article text in a source so we can live-update it as the user + edits. *) article_body_source <- source article.Body; + (* Initially, we're in View mode, and we can switch to Edit mode on user + request. *) + page_mode <- source View; return @@ -74,24 +94,40 @@ fun wiki requested_article_title = then Configuration.wiki_title else article.Title ^ " – " ^ Configuration.wiki_title]} + -

{[Configuration.wiki_title]}

- + (* Page headings *) +
+

{[Configuration.wiki_title]}

+ +
+ (* Article *) {[text]}
} />
-
-