Add some documentation for DomainListInterface.

This commit is contained in:
Philippe Pittoli 2023-07-08 23:44:01 +02:00
parent 572dfc88a4
commit 507330120e
2 changed files with 48 additions and 18 deletions

View File

@ -26,7 +26,7 @@ data Page = Home | LoginRegister | DomainList | Zone | AuthAdmin
data Action
= AuthenticationComponentEvent AF.Output
| AuthenticationDaemonAdminComponentEvent AAI.Output -- Admin interface for authd.
| DomainListComponentEvent DomainListInterface.Output
| DomainListComponentEvent DomainListInterface.Output
| AuthenticationDaemonEvent WS.Output
| DNSManagerDaemonEvent WS.Output
| AuthenticateToDNSManager
@ -35,6 +35,7 @@ data Action
type State = { token :: Maybe String
, uid :: Maybe Int
, current_page :: Page
, store_DomainListInterface_state :: Maybe DomainListInterface.State
}
type ChildSlots =
@ -65,6 +66,7 @@ initialState :: forall i. i -> State
initialState _ = { token: Nothing
, uid: Nothing
, current_page: Home
, store_DomainListInterface_state: Nothing
}
render :: forall m. MonadAff m => State -> H.ComponentHTML Action ChildSlots m
@ -128,8 +130,8 @@ render state
render_newdomain_interface :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad
render_newdomain_interface = case state.token of
Just token -> Bulma.box $
[ HH.slot _dli unit DomainListInterface.component token DomainListComponentEvent
Just _ -> Bulma.box $
[ HH.slot _dli unit DomainListInterface.component unit DomainListComponentEvent
]
Nothing -> render_nothing

View File

@ -1,16 +1,15 @@
module App.DomainListInterface where
{- Simple component with the list of own domains and a form to add a new domain.
This interface allows to:
- display the list of own domains
- show and select accepted domains (TLDs)
- create new domains
- delete a domain
- TODO: ask for confirmation
- TODO: show and modify the content of a Zone
Authentication is automatic with the token.
-}
-- | `App.DomainListInterface` is a simple component with the list of own domains
-- | and a form to add a new domain.
-- |
-- | This interface allows to:
-- | - display the list of own domains
-- | - show and select accepted domains (TLDs)
-- | - create new domains
-- | - delete a domain
-- | - TODO: ask for confirmation
-- | - TODO: switch to the interface to show and modify the content of a Zone
import Prelude (Unit, bind, discard, map, otherwise, pure, ($), (/=), (<<<), (<>))
@ -33,11 +32,21 @@ import Bulma as Bulma
import App.LogMessage
import App.Messages.DNSManagerDaemon as DNSManager
-- | `App.DomainListInterface` can send messages through websocket interface
-- | connected to dnsmanagerd. See `App.WS`.
-- |
-- | Also, this component can log messages and ask its parent (`App.Container`) to
-- | reconnect the websocket to `dnsmanagerd`.
data Output
= MessageToSend ArrayBuffer
| Log LogMessage
| DNSManagerReconnect
-- | `App.DomainListInterface` can receive messages from `dnsmanagerd`.
-- |
-- | The component is also informed when the connection is lost or up again.
data Query a
= MessageReceived ArrayBuffer a
| ConnectionIsDown a
@ -45,12 +54,25 @@ data Query a
type Slot = H.Slot Query Output
type Input = String
-- | `App.DomainListInterface` has no input.
type Input = Unit
-- | `App.DomainListInterface` has a single form to add a new domain.
-- | Only two possible inputs: the (sub)domain name and the selection of the TLD.
data NewDomainFormAction
= INP_newdomain String
| UpdateSelectedDomain String
-- | Possible component's actions are:
-- | - update the accepted domains (examples: netlib.re, codelib.re and example.com)
-- | - update the list of own domains
-- | - handle user inputs
-- | - add a new domain
-- | - remove a domain
-- | - TODO: show the zone content (in another component)
data Action
= UpdateAcceptedDomains (Array String)
| UpdateMyDomains (Array String)
@ -61,18 +83,23 @@ data Action
| RemoveDomain String
| EnterDomain String
-- | The form only has two elements:
-- | the subdomain name input and the selected TLD.
type NewDomainFormState
= { new_domain :: String
, selected_domain :: String
}
-- | The entire component's state contains the form, accepted domains,
-- | the list of own domains and a boolean to know if the connection is up.
type State =
{ newDomainForm :: NewDomainFormState
, accepted_domains :: Array String
, my_domains :: Array String
, wsUp :: Boolean
, token :: String
}
component :: forall m. MonadAff m => H.Component Query Input Output m
@ -86,18 +113,19 @@ component =
}
}
-- | Default available domain: netlib.re.
default_domain :: String
default_domain = "netlib.re"
initialState :: Input -> State
initialState token =
initialState _ =
{ newDomainForm: { new_domain: ""
, selected_domain: default_domain
}
, accepted_domains: [ default_domain ]
, my_domains: [ ]
, wsUp: true
, token: token
}
render :: forall m. State -> H.ComponentHTML Action () m