Commit 6a2eca9e authored by Cédric F.'s avatar Cédric F.

Allow navigation through both keyboard and mouse clicks

parent bd79196c
elm-stuff/
/public/elm.min.js
/public/assets/js/elm.min.js
all: trappisto
trappisto: src/*.elm
elm-make src/Trappisto.elm --warn --output public/elm.js
uglifyjs --mangle --screw-ie8 --output public/elm.min.js -- public/elm.js
rm public/elm.js
elm-make src/Trappisto.elm --warn --output public/assets/js/elm.js
uglifyjs --mangle --screw-ie8 --output public/assets/js/elm.min.js -- public/assets/js/elm.js
rm public/assets/js/elm.js
test: src/*.elm tests/*.elm
elm-test
......@@ -12,4 +12,4 @@ nginx: nginx/nginx.conf
nginx -c nginx/nginx.conf -p . -g 'daemon off;'
clean:
$(RM) public/elm.js
$(RM) public/assets/js/elm*.js
......@@ -15,6 +15,7 @@
"elm-lang/http": "1.0.0 <= v < 2.0.0",
"elm-lang/keyboard": "1.0.1 <= v < 2.0.0",
"elm-lang/mouse": "1.0.1 <= v < 2.0.0",
"elm-lang/navigation": "2.1.0 <= v < 3.0.0",
"elm-lang/virtual-dom": "2.0.4 <= v < 3.0.0",
"elm-lang/window": "1.0.1 <= v < 2.0.0"
},
......
......@@ -66,12 +66,20 @@ http {
return 200;
}
location /rpc {
location /assets/ {
break;
}
location = /rpc {
limit_req zone=default burst=10;
proxy_set_header Authorization "Basic SWp4enNybXNybHFoZGRna2ZqNTVmZ2tjZU1jc3Rzb2F6aWthc2VzdWM6c3RhMmJqYmZ5cWN0eXRxdWpvbGNhdGJ2dmtzanVsclVxcnpjNnd1TWM=";
proxy_set_header Host $host;
proxy_pass https://localhost:9109;
}
location / {
try_files $uri /index.html;
}
}
}
......@@ -21,7 +21,7 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="elm.min.js" async defer></script>
<script src="assets/js/elm.min.js" async defer></script>
<style>
/* inconsolata-regular - latin */
......@@ -30,7 +30,7 @@
font-style: normal;
font-weight: 400;
src: local('Inconsolata Regular'), local('Inconsolata-Regular'),
url('../fonts/inconsolata-v15-latin-regular.woff2') format('woff2');
url('assets/fonts/inconsolata-v15-latin-regular.woff2') format('woff2');
}
body {
......@@ -78,7 +78,7 @@
<script src="https://cdn.jsdelivr.net/npm/particles.js@2.0.0/particles.min.js"></script>
<script>
particlesJS.load('particles-js', 'particles.json', function() {
particlesJS.load('particles-js', 'assets/js/particles.json', function() {
console.log('callback - particles.js config loaded');
});
......
......@@ -2,6 +2,7 @@ module Components.Block exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Http exposing (Error)
import Json.Encode as Encode
import Json.Decode as Decode
......@@ -90,7 +91,9 @@ view model =
List.map
(\ticket ->
li [ class "list-group-item bg-dark" ]
[ a [ href <| "#" ++ ticket ] [ text <| "Stake transaction " ++ ticket ]
[ a
[ href ticket ]
[ text <| "Stake transaction " ++ ticket ]
]
)
model.tickets
......
module Trappisto exposing (main)
import Html exposing (program)
import Trappisto.Model exposing (Model, Msg)
import Navigation
import Trappisto.Model
import Trappisto.Update exposing (init, update, subscriptions)
import Trappisto.View exposing (view)
main : Program Never Model Msg
main : Program Never Trappisto.Model.Model Trappisto.Model.Msg
main =
program
Navigation.program Trappisto.Model.NewUrl
{ init = init
, view = view
, update = update
......
module Trappisto.Model exposing (..)
import Navigation
import Mouse
import Window
import Keyboard
......@@ -43,7 +44,8 @@ initialModel =
type Msg
= StatusMsg StatusComponent.Msg
= NewUrl Navigation.Location
| StatusMsg StatusComponent.Msg
| BlockMsg BlockComponent.Msg
| JsMsg String
| Query String
......
port module Trappisto.Update exposing (init, update, subscriptions)
import Navigation
import Keyboard
import Mouse
import Task exposing (Task)
......@@ -16,13 +17,25 @@ port elmToJs : String -> Cmd msg
port jsToElm : (String -> msg) -> Sub msg
init : ( Model, Cmd Msg )
init =
init : Navigation.Location -> ( Model, Cmd Msg )
init location =
let
query =
extractQuery location
( model, msg ) =
update FetchStatus initialModel
if String.isEmpty query then
update FetchStatus { initialModel | query = query }
else
update (Query query) { initialModel | query = query }
in
( model, Cmd.batch [ elmToJs "focus", msg, Task.perform Resize Window.size ] )
( model
, Cmd.batch
[ elmToJs "focus"
, msg
, Task.perform Resize Window.size
]
)
subscriptions : Model -> Sub Msg
......@@ -49,6 +62,9 @@ update action model =
in
( { updatedModel | time = time }, cmd )
NewUrl location ->
( { model | query = extractQuery location }, Cmd.none )
FetchStatus ->
let
( updatedModel, cmd ) =
......@@ -68,16 +84,14 @@ update action model =
possibleBlockHash query =
(String.length query == 64 && String.left 8 query == "00000000") || query == genesis
possibleBlockHeight query =
case String.toInt query of
Ok int ->
True
parseBlockHeight string =
String.toInt string |> Result.toMaybe |> Maybe.withDefault -1
Err _ ->
False
possibleBlockHeight query =
parseBlockHeight query /= -1
possibleTransaction query =
False
String.length query == 64 && String.left 8 query /= "00000000" && query /= genesis
statusModel =
model.statusModel
......@@ -87,17 +101,22 @@ update action model =
updatedModel =
{ model | query = query, statusModel = updatedStatusModel }
updateUrl ( model, cmd ) =
( model
, Cmd.batch [ newUrl model, cmd ]
)
in
if query == "" then
( { updatedModel | template = Status }, Cmd.none )
( { updatedModel | template = Status }, Cmd.none ) |> updateUrl
else if possibleTransaction query then
fetchTransaction query updatedModel
fetchTransaction query updatedModel |> updateUrl
else if possibleBlockHash query then
fetchBlockByHash query updatedModel
fetchBlockByHash query updatedModel |> updateUrl
else if possibleBlockHeight query then
fetchBlockByHeight (String.toInt query |> Result.toMaybe |> Maybe.withDefault -1) updatedModel
fetchBlockByHeight (parseBlockHeight query) updatedModel |> updateUrl
else if possibleAddress query then
fetchAddress query updatedModel
fetchAddress query updatedModel |> updateUrl
else
let
statusModel =
......@@ -106,7 +125,7 @@ update action model =
updatedStatusModel =
{ statusModel | error = Just "Not sure what you're looking for :|" }
in
( { updatedModel | statusModel = updatedStatusModel }, Cmd.none )
( { updatedModel | statusModel = updatedStatusModel }, Cmd.none ) |> updateUrl
StatusMsg statusMsg ->
let
......@@ -178,7 +197,7 @@ fetchBlockByHeight height model =
fetchTransaction : String -> Model -> ( Model, Cmd Msg )
fetchTransaction transaction model =
( model, Cmd.none )
fetchBlockByHash transaction model
decodeKeys : Bool -> Keyboard.KeyCode -> Keys -> Keys
......@@ -230,3 +249,23 @@ handleKeys { esc, i, j, k } model =
model
else
model
extractQuery : Navigation.Location -> String
extractQuery location =
let
pathname =
String.dropLeft 1 location.pathname
hash =
String.dropLeft 1 location.hash
in
if String.isEmpty pathname then
hash
else
pathname
newUrl : Model -> Cmd Msg
newUrl model =
Navigation.newUrl <| "/#" ++ model.query
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment