Commit 5297e3a0 authored by Cédric F.'s avatar Cédric F.

Update page title dynamically

parent fed352ee
Pipeline #13929910 passed with stage
in 2 minutes and 10 seconds
......@@ -28,6 +28,8 @@
// CONFIGURE ME:
const coin = 'BCH';
// TODO: use fuzzy search to guess coin based on hostname?
document.title = coin + " blockchain - Trappisto";
</script>
<style>
......@@ -64,6 +66,10 @@
background: orange;
box-shadow: 0 0 10px 5px orange;
}
.fetching {
opacity: 0.5;
}
</style>
</head>
<body class="bg-black text-white">
......@@ -98,16 +104,17 @@
<script src="https://cdn.jsdelivr.net/npm/particles.js@2.0.0/particles.min.js"></script>
<script>
//particlesJS.load('particles-js', 'assets/js/particles.json', function() {
// console.log('callback - particles.js config loaded');
//});
particlesJS.load('particles-js', 'assets/js/particles.json', function() {
console.log('callback - particles.js config loaded');
});
window.addEventListener('load', () => {
const elmAppDiv = document.querySelector('#elm-app');
const elmApp = Elm.Trappisto.embed(elmAppDiv, { coin: coin });
elmApp.ports.elmToJs.subscribe((command) => {
console.log('Received command: ' + command);
elmApp.ports.elmToJs.subscribe((params) => {
const command = params.shift();
console.log('Received command: ' + command, params);
switch (command) {
case 'focus':
......@@ -118,6 +125,10 @@
}
break;
case 'title':
document.title = params[0] + " - " + coin + " blockchain - Trappisto";
break;
default:
console.error('Unhandled command: ' + command);
}
......
......@@ -142,7 +142,22 @@ update msg model =
updatedModel =
{ model | fetching = True }
in
( updatedModel, searchRawTransactions updatedModel address )
case model.coin of
DCR ->
( updatedModel, searchRawTransactions updatedModel address )
_ ->
( { model
| error =
Just <|
"Trappisto does not support Bitcoin addresses "
++ "but you can explore this address on "
++ "<a target=\"_blank\" href=\"https://blockchair.com/search?q="
++ address
++ "\">blockchair.com</a>"
}
, Cmd.none
)
SearchRawTransactionsResult result ->
case result of
......
......@@ -39,8 +39,10 @@ type Msg
view : Model -> Html a
view model =
div [ class "col text-center" ]
[ span [] [ text "Last block: " ]
, a [ href (toString model.blocks) ] [ text <| toString model.blocks ]
[ h3 []
[ text "Last block: "
, a [ href (toString model.blocks) ] [ text <| toString model.blocks ]
]
]
......
--- FIXME: unused?
module Lib.HtmlAttributesExtra exposing (..)
import Html exposing (Attribute)
......
......@@ -13,7 +13,7 @@ import Components.Transaction as TransactionComponent
import Trappisto.Helpers as Coin exposing (Coin)
port elmToJs : String -> Cmd msg
port elmToJs : List String -> Cmd msg
port jsToElm : (String -> msg) -> Sub msg
......@@ -53,7 +53,7 @@ init flags location =
in
( updatedModel
, Cmd.batch
[ elmToJs "focus"
[ elmToJs [ "focus" ]
, msg
, Task.perform Resize Window.size
]
......@@ -100,7 +100,7 @@ update action model =
"298e5cc3d985bfe7f81dc135f360abe089edd4396b86d2de66b0cef42b21d980"
possibleAddress query =
String.length query /= 64
String.length query >= 26 && String.length query <= 34
-- XXX: Remove a few zeros in the future... 00000000
possibleBlockHash query =
......@@ -238,7 +238,7 @@ update action model =
-- don't append "i" when switching back to normal mode
| query = String.dropRight 1 updatedModel.query
}
, elmToJs "focus"
, elmToJs [ "focus" ]
)
else if updatedModel.query /= model.query then
update (Query updatedModel.query) updatedModel
......@@ -352,4 +352,15 @@ newUrl model =
updateUrl : ( Model, Cmd Msg ) -> ( Model, Cmd Msg )
updateUrl ( model, cmd ) =
( model, Cmd.batch [ newUrl model, cmd ] )
let
commands =
case model.query of
"" ->
[ newUrl model ]
_ ->
[ newUrl model
, elmToJs [ "title", (toString model.template) ++ " " ++ model.query ]
]
in
( model, Cmd.batch <| commands ++ [ cmd ] )
......@@ -3,6 +3,7 @@ module Trappisto.View exposing (view)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Lib.HtmlAttributesExtra as HtmlAttributesExtra
import Trappisto.Model exposing (..)
import Components.Status as StatusComponent exposing (view)
import Components.Address as AddressComponent exposing (view)
......@@ -12,7 +13,10 @@ import Components.Transaction as TransactionComponent exposing (view)
isFetching : Model -> Bool
isFetching model =
model.statusModel.fetching || model.blockModel.fetching
model.statusModel.fetching
|| model.addressModel.fetching
|| model.blockModel.fetching
|| model.transactionModel.fetching
isError : Model -> Bool
......@@ -48,8 +52,11 @@ errorView model =
Just error ->
div [ class "row" ]
[ div [ class "col-6 offset-3" ]
[ div [ class "text-center alert alert-danger" ]
[ text error ]
[ div
[ class "text-center alert alert-danger"
, HtmlAttributesExtra.innerHtml error
]
[]
]
]
......@@ -113,22 +120,16 @@ transactionView model =
view : Model -> Html Msg
view model =
let
glow =
if isFetching model then
"glow"
else
""
header =
[ div [ class "row" ]
[ div [ class "col" ]
[ pre [ id "logo", class glow ]
[ text <|
if model.query /= "" then
"Trappisto - " ++ (toString model.config.coin) ++ " Interactive Block Explorer"
else
[ if model.query /= "" then
span [] []
else
pre [ id "logo", class "text-white" ]
[ text
" ______ _______ _______ _______ _______ ______ \n( __ \\ ( ____ \\( ____ \\( ____ )( ____ \\( __ \\ \n| ( \\ )| ( \\/| ( \\/| ( )|| ( \\/| ( \\ )\n| | ) || (__ | | | (____)|| (__ | | ) |\n| | | || __) | | | __)| __) | | | |\n| | ) || ( | | | (\\ ( | ( | | ) |\n| (__/ )| (____/\\| (____/\\| ) \\ \\__| (____/\\| (__/ )\n(______/ (_______/(_______/|/ \\__/(_______/(______/ \n"
]
]
]
]
]
......@@ -184,15 +185,26 @@ view model =
]
]
headerAndContent =
headerAndContent model =
[ div [ class "row text-center" ] [ div [ class "col" ] header ]
, div [ class "row" ] [ div [ class "col" ] content ]
, div [ class "row" ]
[ div
[ class <|
"col"
++ (if isFetching model then
" fetching glow"
else
""
)
]
content
]
]
sections =
if model.debug then
List.concat [ headerAndContent, debug ]
List.concat [ headerAndContent model, debug ]
else
headerAndContent
headerAndContent model
in
div [ class "row text-white" ] [ div [ class "col" ] sections ]
......@@ -8,6 +8,7 @@ import Json.Decode as Decode
import Components.Address as Address
import Components.Block as Block
import Components.Transaction as Transaction
import Trappisto.Helpers as Coin exposing (Coin)
suite : Test
......@@ -27,7 +28,7 @@ suite =
model =
case result of
Ok jsonModel ->
jsonModel |> Address.modelFromJson
Address.modelFromJson jsonModel Coin.DCR
Err error ->
Debug.crash error
......@@ -54,7 +55,7 @@ suite =
model =
case result of
Ok jsonModel ->
jsonModel |> Transaction.modelFromJson
Transaction.modelFromJson jsonModel Coin.DCR
Err error ->
Debug.crash error
......
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