dashboard/src/Main.elm

76 lines
1.7 KiB
Elm
Raw Normal View History

2020-11-23 11:07:07 +03:00
module Main exposing (..)
{-| Copyright 2020 Fluence Labs Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-}
import Browser
2020-11-23 15:44:45 +03:00
import Browser.Navigation as Navigation
import Cache
import MainPage exposing (..)
2020-11-23 16:31:31 +03:00
import Route
import RoutePage
2020-11-23 14:27:33 +03:00
import Url
type alias Config =
{ peerId : String
, relayId : String
, knownPeers : List String
}
type alias Flags =
Config
2020-11-23 15:44:45 +03:00
2020-11-23 11:07:07 +03:00
main =
2020-11-23 14:27:33 +03:00
Browser.application
2020-11-23 11:07:07 +03:00
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
2020-11-23 15:44:45 +03:00
, onUrlChange = UrlChanged
, onUrlRequest = LinkClicked
2020-11-23 11:07:07 +03:00
}
2020-11-23 14:27:33 +03:00
init : Flags -> Url.Url -> Navigation.Key -> ( Model, Cmd Msg )
2020-11-23 15:44:45 +03:00
init flags url key =
2020-11-23 11:07:07 +03:00
let
2020-11-23 16:31:31 +03:00
r =
Route.parse url
c =
Cache.init
page =
RoutePage.fromCache r c
2020-11-23 15:44:45 +03:00
emptyModel =
{ peerId = flags.peerId
, relayId = flags.relayId
, url = url
, key = key
, route = r
, page = page
, cache = c
2020-12-01 17:47:52 +03:00
, toggledInterface = Nothing
2020-12-04 12:21:09 +03:00
, knownPeers = flags.knownPeers
2020-12-09 14:28:54 +03:00
, isInitialized = False
2020-11-23 15:44:45 +03:00
}
2020-11-23 11:07:07 +03:00
in
( emptyModel, routeCommand emptyModel r )