Skip to content

Commit 8460885

Browse files
authored
Merge pull request #35 from ryukinix/add-share-button
feat: share button
2 parents be2f80f + 409203b commit 8460885

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

web/webapp.lisp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#:ui-widget)
1515
(:import-from #:reblocks/page
1616
#:init-page)
17+
(:import-from #:reblocks/request
18+
#:get-parameter)
1719
(:export #:start
1820
#:stop
1921
#:*notes*
@@ -62,16 +64,39 @@
6264
(update table))
6365

6466
(defmethod render ((table table))
67+
(let ((url-prop (get-parameter "prop")))
68+
(when (and url-prop (string/= url-prop "") (string/= url-prop (prop table)))
69+
(update-table table url-prop)))
6570
(reblocks/html:with-html ()
6671
(:h1 :align "center" "Lisp Inference Truth Table System")
6772
(:div :align "center"
6873
(reblocks-ui/form:with-html-form (:POST (lambda (&key prop &allow-other-keys)
6974
(update-table table prop)))
7075
(:input :type "text"
76+
:id "prop-input"
7177
:name "prop"
7278
:placeholder (prop table))
7379
(:input :type "submit"
74-
:value "Eval"))
80+
:value "Eval")
81+
(:input :type "button"
82+
:value "Share"
83+
:onclick "
84+
var prop = document.getElementById('prop-input').value || document.getElementById('prop-input').placeholder;
85+
var url = window.location.origin + window.location.pathname + '?prop=' + encodeURIComponent(prop);
86+
var shareUrlInput = document.getElementById('share-url');
87+
shareUrlInput.value = url;
88+
shareUrlInput.style.display = 'block';
89+
try {
90+
navigator.clipboard.writeText(url).then(function() {
91+
/* clipboard successfully set */
92+
}, function() {
93+
/* clipboard write failed */
94+
});
95+
} catch (e) {
96+
// ignore
97+
}
98+
"))
99+
(:input :type "text" :id "share-url" :style "display: none; width: 100%; margin-top: 10px;" :readonly "readonly")
75100
(:pre :style "font-size: 25px" (truth table))
76101
(:pre (format nil "Operators: ~a" inference:*valid-operators*)))
77102
(:p "Some notes: "
@@ -92,7 +117,10 @@
92117

93118
(defmethod reblocks/page:init-page ((app truth-table) (url-path string) expire-at)
94119
(declare (ignorable app url-path expire-at))
95-
(create-table *proposition*))
120+
(let ((prop (get-parameter "prop")))
121+
(create-table (if (or (null prop) (string= prop ""))
122+
*proposition*
123+
prop))))
96124

97125
(defun start (&optional (port *port*))
98126
(reblocks/debug:on)

0 commit comments

Comments
 (0)