Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
icidasset committed Dec 26, 2018
1 parent 7cefa22 commit d10f445
Show file tree
Hide file tree
Showing 15 changed files with 238 additions and 36 deletions.
3 changes: 3 additions & 0 deletions src/Applications/Brain.elm
Expand Up @@ -117,6 +117,9 @@ translateAlienEvent event =
Just Alien.AuthMethod ->
AuthenticationMsg (Brain.Authentication.MethodRetrieved event.data)

Just Alien.SaveUserData ->
AuthenticationMsg (Brain.Authentication.SaveUserData event.data)

Just Alien.SignIn ->
AuthenticationMsg (Brain.Authentication.PerformSignIn event.data)

Expand Down
43 changes: 32 additions & 11 deletions src/Applications/Brain/Authentication.elm
Expand Up @@ -4,8 +4,8 @@ module Brain.Authentication exposing (Model, Msg(..), initialCommand, initialMod
Involves:
1. Local UserData (enable shuffle, EQ settings, etc.)
2. Remote UserData (sources, tracks, favourites, etc.)
1. Enclosed UserData (enable shuffle, EQ settings, ... ~> device)
2. Hypaethral UserData (sources, tracks, favourites, ... ~> account)
Methods:
Expand All @@ -16,7 +16,7 @@ Methods:
Steps:
1. Get active method (if none, we're signed out)
2. Get data
2. Get unrestricted data
-}

Expand Down Expand Up @@ -46,7 +46,10 @@ initialModel =

initialCommand : Cmd Msg
initialCommand =
do RetrieveMethod
Cmd.batch
[ do RetrieveMethod
, do RetrieveEnclosedData
]



Expand All @@ -60,8 +63,11 @@ type Msg
| RetrieveMethod
| MethodRetrieved J.Value
-- 2. Data
| RetrieveData
| DataRetrieved J.Value
| RetrieveHypaethralData
| HypaethralDataRetrieved J.Value
-- x. Data
| RetrieveEnclosedData
| EnclosedDataRetrieved J.Value


update : Msg -> Model -> R3D3 Model Msg Reply
Expand All @@ -75,7 +81,7 @@ update msg model =
Just method ->
( { model | method = Just method }
, Cmd.batch
[ do RetrieveData
[ do RetrieveHypaethralData
, json
|> Alien.broadcast Alien.AuthMethod
|> Ports.toCache
Expand Down Expand Up @@ -115,7 +121,7 @@ update msg model =
-- 🚀
Just method ->
( { model | method = Just method }
, do RetrieveData
, do RetrieveHypaethralData
, Nothing
)

Expand All @@ -129,7 +135,7 @@ update msg model =
-----------------------------------------
-- # 2
-----------------------------------------
RetrieveData ->
RetrieveHypaethralData ->
( model
, case model.method of
-- 🚀
Expand All @@ -142,12 +148,27 @@ update msg model =
, Nothing
)

DataRetrieved json ->
HypaethralDataRetrieved json ->
( model
, noCmd
, terminate (Authenticated json)
)

-----------------------------------------
-- DATA
-----------------------------------------
RetrieveEnclosedData ->
( model
, Ports.requestCache (Alien.trigger Alien.AuthEnclosedData)
, Nothing
)

EnclosedDataRetrieved json ->
( model
, noCmd
, Just [ LoadEnclosedUserData json ]
)


noCmd : Cmd msg
noCmd =
Expand Down Expand Up @@ -179,7 +200,7 @@ terminate : Termination -> Maybe (List Reply)
terminate t =
case t of
Authenticated json ->
Just [ LoadUserData json ]
Just [ LoadHypaethralUserData json ]

NotAuthenticated ->
Just [ HideLoadingScreen ]
3 changes: 2 additions & 1 deletion src/Applications/Brain/Reply.elm
Expand Up @@ -11,4 +11,5 @@ type Reply
= Chill
-- UI
| HideLoadingScreen
| LoadUserData Json.Value
| LoadEnclosedUserData Json.Value
| LoadHypaethralUserData Json.Value
17 changes: 15 additions & 2 deletions src/Applications/UI.elm
Expand Up @@ -7,7 +7,7 @@ import Browser.Navigation as Nav
import Chunky exposing (..)
import Color
import Html exposing (Html, div, section, text)
import Html.Attributes exposing (style)
import Html.Attributes exposing (id, style)
import Html.Lazy
import Json.Encode
import Replying exposing (return)
Expand Down Expand Up @@ -143,6 +143,11 @@ update msg model =
-----------------------------------------
-- URL
-----------------------------------------
ChangeUrlUsingPage page ->
( model
, Nav.pushUrl model.navKey (Page.toString page)
)

LinkClicked urlRequest ->
case urlRequest of
Browser.Internal url ->
Expand Down Expand Up @@ -171,9 +176,15 @@ update msg model =
translateReply : Reply -> Msg
translateReply reply =
case reply of
AddSourceToCollection source ->
SourcesMsg (UI.Sources.AddToCollection source)

Chill ->
Bypass

GoToPage page ->
ChangeUrlUsingPage page


updateChild =
Replying.updateChild update translateReply
Expand Down Expand Up @@ -286,7 +297,9 @@ defaultScreen model =
root : List (Html msg) -> Html msg
root =
section
[ style "color" (Color.toCssString UI.Kit.colors.text) ]
[ id "diffuse"
, style "color" (Color.toCssString UI.Kit.colors.text)
]


content : List (Html msg) -> Html msg
Expand Down
1 change: 1 addition & 0 deletions src/Applications/UI/Core.elm
Expand Up @@ -59,6 +59,7 @@ type Msg
-----------------------------------------
-- URL
-----------------------------------------
| ChangeUrlUsingPage Page
| LinkClicked Browser.UrlRequest
| UrlChanged Url

Expand Down
2 changes: 1 addition & 1 deletion src/Applications/UI/Kit.elm
Expand Up @@ -205,7 +205,7 @@ h3 text =
[ T.f4
, T.fw7
, T.lh_title
, T.mb5
, T.mb4
]
[ Html.text text ]

Expand Down
39 changes: 39 additions & 0 deletions src/Applications/UI/List.elm
@@ -0,0 +1,39 @@
module UI.List exposing (view)

import Chunky exposing (..)
import Color
import Html exposing (Html)
import Html.Attributes exposing (style)
import Tachyons.Classes as T
import UI.Kit



-- 🌳


type alias Item msg =
{ label : String
, actions : List (Html msg)
}



--


view : List (Item msg) -> Html msg
view =
List.map item >> chunk [ T.f6, T.lh_copy ]



-- 🚯


item : Item msg -> Html msg
item { label } =
block
[ style "border-bottom" ("1px solid " ++ Color.toCssString UI.Kit.colors.subtleBorder) ]
[]
[ Html.text label ]
5 changes: 4 additions & 1 deletion src/Applications/UI/Ports.elm
@@ -1,4 +1,4 @@
port module UI.Ports exposing (fromBrain, toBrain)
port module UI.Ports exposing (fromBrain, removeFocus, toBrain)

import Alien

Expand All @@ -7,6 +7,9 @@ import Alien
-- 📣


port removeFocus : () -> Cmd msg


port toBrain : Alien.Event -> Cmd msg


Expand Down
9 changes: 8 additions & 1 deletion src/Applications/UI/Reply.elm
@@ -1,7 +1,14 @@
module UI.Reply exposing (Reply(..))

import Sources exposing (Source)
import UI.Page exposing (Page)



-- 🌳


type Reply
= Chill
= AddSourceToCollection Source
| Chill
| GoToPage Page
40 changes: 33 additions & 7 deletions src/Applications/UI/Sources.elm
@@ -1,20 +1,21 @@
module UI.Sources exposing (Model, Msg(..), initialModel, update, view)

import Chunky exposing (..)
import Dict.Ext as Dict
import Html exposing (Html, text)
import Material.Icons.Content as Icons
import Material.Icons.Navigation as Icons
import Material.Icons.Notification as Icons
import Replying exposing (R3D3)
import Return2
import Return3
import Sources exposing (..)
import Sources.Services as Services
import Tachyons.Classes as T
import UI.Kit exposing (ButtonType(..), select)
import UI.List
import UI.Navigation exposing (..)
import UI.Page as Page
import UI.Reply exposing (Reply(..))
import UI.Reply exposing (Reply)
import UI.Sources.Form as Form


Expand All @@ -23,12 +24,15 @@ import UI.Sources.Form as Form


type alias Model =
{ form : Form.Model }
{ collection : List Source
, form : Form.Model
}


initialModel : Model
initialModel =
{ form = Form.initialModel
{ collection = []
, form = Form.initialModel
}


Expand All @@ -38,6 +42,10 @@ initialModel =

type Msg
= Bypass
-----------------------------------------
-- Collection
-----------------------------------------
| AddToCollection Source
-----------------------------------------
-- Children
-----------------------------------------
Expand All @@ -51,15 +59,24 @@ update msg model =
model
|> Return3.withNothing

-----------------------------------------
-- Collection
-----------------------------------------
AddToCollection source ->
source
|> List.singleton
|> List.append model.collection
|> (\c -> { model | collection = c })
|> Return3.withNothing

-----------------------------------------
-- Children
-----------------------------------------
FormMsg sub ->
model.form
|> Form.update sub
|> Return2.mapModel (\f -> { model | form = f })
|> Return2.mapCmd FormMsg
|> Return3.withNoReply
|> Return3.mapModel (\f -> { model | form = f })
|> Return3.mapCmd FormMsg



Expand Down Expand Up @@ -103,6 +120,9 @@ index model =
-----------------------------------------
, UI.Kit.canister
[ UI.Kit.h1 "Sources"

-- Intro
--------
, [ text "A source is a place where your music is stored."
, lineBreak
, text "By connecting a source, the application will scan it and keep a list of all the music in it."
Expand All @@ -111,5 +131,11 @@ index model =
]
|> Html.span []
|> UI.Kit.intro

-- List
-------
, model.collection
|> List.map (\s -> { label = Dict.fetch "name" "" s.data, actions = [] })
|> UI.List.view
]
]

0 comments on commit d10f445

Please sign in to comment.