summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2024-11-25 23:30:16 -0500
committerLLLL Colonq <llll@colonq>2024-11-25 23:30:16 -0500
commit2e92b2e59b543c4c20f52295ef3913f229ed20d3 (patch)
tree5195cf47cc3a3a18547397554129809d92becd74
parentfe9ca701f26478bacdd52188b5e75045746ebb68 (diff)
Redeem submit
-rw-r--r--flake.nix1
-rw-r--r--main.css9
-rw-r--r--src/Main.purs7
-rw-r--r--src/UI.js16
-rw-r--r--src/UI.purs6
-rw-r--r--templates/api/menu.html13
6 files changed, 52 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix
index beedd35..e8249ea 100644
--- a/flake.nix
+++ b/flake.nix
@@ -24,6 +24,7 @@
"web-html"
"web-dom"
"web-uievents"
+ "web-xhr"
"canvas"
"argonaut"
"fetch"
diff --git a/main.css b/main.css
index b173959..f4ab83e 100644
--- a/main.css
+++ b/main.css
@@ -298,6 +298,9 @@ a.lcolonq-button-link :active {
padding-left: 1rem;
padding-right: 1rem;
padding-bottom: 1rem;
+ display: flex;
+ flex-direction: column;
+ user-select: none;
}
.lcolonq-menu-box:hover {
@@ -314,6 +317,12 @@ a.lcolonq-button-link :active {
grid-row-end: span 2;
}
+.lcolonq-menu-box textarea {
+ resize: none;
+ margin-top: 1rem;
+ flex: 1;
+}
+
/* auth */
.lcolonq-auth {
position: absolute;
diff --git a/src/Main.purs b/src/Main.purs
index 7897b49..983a805 100644
--- a/src/Main.purs
+++ b/src/Main.purs
@@ -37,6 +37,7 @@ import Web.HTML as HTML
import Web.HTML.HTMLDocument as HTML.Doc
import Web.HTML.HTMLInputElement as HTML.Input
import Web.HTML.Window as HTML.Win
+import Web.XHR.FormData as FD
maybeToArray :: forall a. Maybe a -> Array a
maybeToArray (Just x) = [x]
@@ -228,6 +229,12 @@ mainRegister = launchAff_ do
mainMenu :: Effect Unit
mainMenu = launchAff_ do
liftEffect $ log "hello from menu"
+ textareas <- queryAll "textarea"
+ for_ textareas \ta -> listen ta "click" Ev.stopPropagation
+ boxes <- queryAll ".lcolonq-menu-box"
+ for_ boxes \box -> do
+ listen box "click" \_ev -> do
+ UI.submitRedeem box
mainAuth :: Effect Unit
mainAuth = launchAff_ do
diff --git a/src/UI.js b/src/UI.js
index b27b10b..5f1aaa0 100644
--- a/src/UI.js
+++ b/src/UI.js
@@ -1,9 +1,25 @@
export const _cheatLog = (a) => () => console.log(a);
export const _setInterval = (delay) => (f) => () => setInterval(f, delay);
export const _toJSON = (x) => JSON.stringify(x);
+
export const _reload = () => {
window.location.reload();
};
+
export const _redirect = (url) => () => {
window.location.href = url;
};
+
+export const _submitRedeem = (url) => (el) => () => {
+ const redeem = el.children[0].textContent;
+ const inp = el.children[1]?.value;
+ console.log(redeem, inp);
+ const data = new FormData();
+ data.append("ayem", "test");
+ data.append("name", redeem);
+ data.append("input", inp);
+ fetch(url, {
+ method: "post",
+ body: data,
+ });
+};
diff --git a/src/UI.purs b/src/UI.purs
index ac4d694..a01422f 100644
--- a/src/UI.purs
+++ b/src/UI.purs
@@ -1,8 +1,10 @@
module UI where
import Prelude
+import Config as Config
import Effect (Effect)
import Effect.Class (class MonadEffect, liftEffect)
+import Web.DOM.Element as DOM.El
foreign import _cheatLog :: forall a. a -> Effect Unit
cheatLog :: forall m a. MonadEffect m => a -> m Unit
@@ -23,3 +25,7 @@ reload = liftEffect _reload
foreign import _redirect :: String -> Effect Unit
redirect :: forall m. MonadEffect m => String -> m Unit
redirect url = liftEffect $ _redirect url
+
+foreign import _submitRedeem :: String -> DOM.El.Element -> Effect Unit
+submitRedeem :: forall m. MonadEffect m => DOM.El.Element -> m Unit
+submitRedeem el = liftEffect $ _submitRedeem (Config.apiServer <> "/redeem") el
diff --git a/templates/api/menu.html b/templates/api/menu.html
index b8e8673..b5d32b8 100644
--- a/templates/api/menu.html
+++ b/templates/api/menu.html
@@ -50,6 +50,7 @@ CONFIG_SUBST
bread sandwich enriched with extra iron.
the latest and greatest.
read all about it.
+ <textarea></textarea>
</div>
<div class="lcolonq-menu-box">
<h3>cycle gizmos</h3>
@@ -66,6 +67,7 @@ CONFIG_SUBST
long pork.
cooked at table.
optional floral garnish.
+ <textarea></textarea>
</div>
<div class="lcolonq-menu-box">
<h3>deslug</h3>
@@ -117,33 +119,39 @@ CONFIG_SUBST
izakaya fare par excellence.
human sacrifices not included.
go ask the tengu.
+ <textarea></textarea>
</div>
<div class="lcolonq-menu-box lcolonq-menu-box-long">
<h3>bells of bezelea</h3>
bronze and dreamstuff.
mountain thyme garnish.
ϕιλία.
+ <textarea></textarea>
</div>
<div class="lcolonq-menu-box lcolonq-menu-box-long">
<h3>palette swap (eyes)</h3>
it is eyes.
what did you expect.
+ <textarea></textarea>
</div>
<div class="lcolonq-menu-box lcolonq-menu-box-long">
<h3>palette swap (hair)</h3>
it is hair.
what did you expect.
+ <textarea></textarea>
</div>
<div class="lcolonq-menu-box lcolonq-menu-box-long">
<h3>palette swap (highlight)</h3>
it is highlight.
what did you expect.
+ <textarea></textarea>
</div>
<div class="lcolonq-menu-box lcolonq-menu-box-long">
<h3>hex</h3>
wiedźmin geralt z rivii.
zwany również białym wilkiem.
zwalcza zagrażające ludziom potwory.
+ <textarea></textarea>
</div>
<div class="lcolonq-menu-box">
<h3>antipiracy</h3>
@@ -164,6 +172,7 @@ CONFIG_SUBST
stuffed inside a freshly-hunted pheasant.
stuffed inside a freshly-hunted grouse.
boiled.
+ <textarea></textarea>
</div>
<div class="lcolonq-menu-box">
<h3>gamer</h3>
@@ -186,24 +195,28 @@ CONFIG_SUBST
or maybe it depends on the moon phase.
we play this one by ear.
surprise.
+ <textarea></textarea>
</div>
<div class="lcolonq-menu-box lcolonq-menu-box-long">
<h3>feed friend</h3>
hamburber colon three.
are these still funny.
i love you.
+ <textarea></textarea>
</div>
<div class="lcolonq-menu-box lcolonq-menu-box-long">
<h3>show friend wikipedia page</h3>
copper ore and longing.
big red donation prompt.
free.
+ <textarea></textarea>
</div>
<div class="lcolonq-menu-box lcolonq-menu-box-long">
<h3>friend composes song</h3>
one hundred and fifty tiny singing birds.
they've never heard of salt.
before.
+ <textarea></textarea>
</div>
</div>
</div>