Something went wrong. Try again.
A music player that connects to your cloud/distributed storage. forked from tokono.ma/diffuse
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537module Themes.Sunrise.Sources.Form exposing (..)
import Chunky exposing (..)import Common exposing (boolFromString, boolToString)import Conditional exposing (..)import Dict.Ext as Dictimport Html exposing (Html, text)import Html.Attributes as A exposing (attribute, for, name, placeholder, required, selected, type_, value)import Html.Events exposing (onInput, onSubmit)import List.Extra as Listimport Material.Icons.Round as Iconsimport Material.Icons.Types exposing (Coloring(..))import Sources exposing (..)import Sources.Services as Servicesimport Themes.Sunrise.Kit as Kit exposing (ButtonType(..), select)import Themes.Sunrise.Navigation as Navigationimport UI.Navigation exposing (..)import UI.Page as Pageimport UI.Sources.Page as Sourcesimport UI.Sources.Types exposing (..)
-- NEW
type alias Arguments = { onboarding : Bool }
new : Arguments -> Form -> List (Html Msg)new args model = case model.step of Where -> newWhere args model
How -> newHow model
By -> newBy model
newWhere : Arguments -> Form -> List (Html Msg)newWhere { onboarding } { context } = [ ----------------------------------------- -- Navigation ----------------------------------------- Navigation.local [ ( Icon Icons.arrow_back , Label "Back to list" Hidden -- , if onboarding then NavigateToPage Page.Index
else NavigateToPage (Page.Sources Sources.Index) ) ]
----------------------------------------- -- Content ----------------------------------------- , (\h -> form TakeStep [ Kit.canisterForm h ] ) [ Kit.h2 "Where is your music stored?"
-- Dropdown ----------- , let contextServiceKey = Services.typeToKey context.service in Services.labels |> List.map (\( k, l ) -> Html.option [ value k, selected (contextServiceKey == k) ] [ text l ] ) |> select SelectService
-- Button --------- , chunk [ "mt-10" ] [ Kit.button IconOnly Bypass (Icons.arrow_forward 17 Inherit) ] ] ]
newHow : Form -> List (Html Msg)newHow { context } = [ ----------------------------------------- -- Navigation ----------------------------------------- Navigation.local [ ( Icon Icons.arrow_back , Label "Take a step back" Shown , PerformMsg TakeStepBackwards ) ]
----------------------------------------- -- Content ----------------------------------------- , (\h -> form TakeStep [ chunk [ "text-left", "w-full" ] [ Kit.canister h ] ] ) [ Kit.h3 "Where exactly?"
-- Note ------- , note context.service
-- Fields --------- , let properties = Services.properties context.service
dividingPoint = toFloat (List.length properties) / 2
( listA, listB ) = List.splitAt (ceiling dividingPoint) properties in chunk [ "flex", "pt-3" ] [ chunk [ "flex-grow", "pr-4" ] (List.map (renderProperty context) listA) , chunk [ "flex-grow", "pl-4" ] (List.map (renderProperty context) listB) ]
-- Button --------- , chunk [ "mt-3", "text-center" ] [ Kit.button IconOnly Bypass (Icons.arrow_forward 17 Inherit) ] ] ]
howNote : List (Html Msg) -> Html MsghowNote = chunk [ "text-sm" , "italic" , "leading-normal" , "max-w-lg" , "mb-8" ]
newBy : Form -> List (Html Msg)newBy { context } = [ ----------------------------------------- -- Navigation ----------------------------------------- Navigation.local [ ( Icon Icons.arrow_back , Label "Take a step back" Shown , PerformMsg TakeStepBackwards ) ]
----------------------------------------- -- Content ----------------------------------------- , (\h -> form AddSourceUsingForm [ Kit.canisterForm h ] ) [ Kit.h2 "One last thing" , Kit.label [] "What are we going to call this source?"
-- Input -------- , let nameValue = Dict.fetch "name" "" context.data in chunk [ "flex" , "max-w-md" , "mt-8" , "mx-auto" , "justify-center" , "w-full" ] [ Kit.textField [ name "name" , onInput (SetFormData "name") , value nameValue ] ]
-- Note ------- , chunk [ "mt-16" ] (case context.service of AmazonS3 -> corsWarning "CORS__S3"
AzureBlob -> corsWarning "CORS__Azure"
AzureFile -> corsWarning "CORS__Azure"
Dropbox -> []
Google -> []
Ipfs -> corsWarning "CORS__IPFS"
WebDav -> corsWarning "CORS__WebDAV" )
-- Button --------- , Kit.button Normal Bypass (text "Add source") ] ]
corsWarning : String -> List (Html Msg)corsWarning id = [ chunk [ "text-sm", "flex", "items-center", "justify-center", "leading-snug", "opacity-50" ] [ Kit.inlineIcon Icons.warning , inline [ "font-semibold" ] [ text "Make sure CORS is enabled" ] ] , chunk [ "text-sm", "leading-snug", "mb-8", "mt-1", "opacity-50" ] [ text "You can find the instructions over " , Kit.link { label = "here", url = "about/cors/#" ++ id } ] ]
-- EDIT
edit : Form -> List (Html Msg)edit { context } = [ ----------------------------------------- -- Navigation ----------------------------------------- Navigation.local [ ( Icon Icons.arrow_back , Label "Go Back" Shown , PerformMsg ReturnToIndex ) ]
----------------------------------------- -- Content ----------------------------------------- , (\h -> form EditSourceUsingForm [ chunk [ "text-left", "w-full" ] [ Kit.canister h ] ] ) [ Kit.h3 "Edit source"
-- Note ------- , note context.service
-- Fields --------- , let properties = Services.properties context.service
dividingPoint = toFloat (List.length properties) / 2
( listA, listB ) = List.splitAt (ceiling dividingPoint) properties in chunk [ "flex", "pt-3" ] [ chunk [ "flex-grow", "pr-4" ] (List.map (renderProperty context) listA) , chunk [ "flex-grow", "pl-4" ] (List.map (renderProperty context) listB) ]
-- Button --------- , chunk [ "mt-3", "text-center" ] [ Kit.button Normal Bypass (text "Save") ] ] ]
-- PROPERTIES
renderProperty : Source -> Property -> Html MsgrenderProperty context property = chunk [ "mb-8" ] [ Kit.label [ for property.key ] property.label
-- , if (property.placeholder == boolToString True) || (property.placeholder == boolToString False) then let bool = context.data |> Dict.fetch property.key property.placeholder |> boolFromString in chunk [ "mt-2", "pt-1" ] [ Kit.checkbox { checked = bool , toggleMsg = bool |> not |> boolToString |> SetFormData property.key } ]
else Kit.textField [ name property.key , onInput (SetFormData property.key) , placeholder property.placeholder , required (property.label |> String.toLower |> String.contains "optional" |> not) , type_ (ifThenElse property.password "password" "text") , value (Dict.fetch property.key "" context.data)
-- , attribute "spellcheck" "false" ] ]
-- ⚗️
form : Msg -> List (Html Msg) -> Html Msgform msg html = slab Html.form [ onSubmit msg ] [ "flex" , "flex-grow" , "flex-shrink-0" , "text-center" ] [ Kit.centeredContent html ]
note : Service -> Html Msgnote service = case service of AmazonS3 -> nothing
AzureBlob -> nothing
AzureFile -> nothing
Dropbox -> howNote [ inline [ "font-semibold" ] [ text "If you don't know what any of this is, " , text "continue to the next screen." ] , text " Changing the app key allows you to use your own Dropbox app." , text " Also, make sure you verified your email address on Dropbox," , text " or this might not work." ]
Google -> howNote [ inline [ "font-semibold" ] [ text "If you don't know what any of this is, " , text "continue to the next screen." ] , text " Changing the client stuff allows you to use your own Google OAuth client." , text " Disclaimer: " , text "The Google Drive API is fairly slow and limited, " , text "consider using a different service." ]
Ipfs -> howNote [ inline [ "font-semibold" ] [ text "Diffuse will use the ipfs.io gateway by default" ] , text "." , lineBreak , inline [] [ text "There are also " , Html.a [ A.href "https://ipfs.github.io/public-gateway-checker/" , A.class "underline" , A.target "_blank" ] [ text "other public gateways" ] , text " you can choose from." ] , lineBreak , text "If you would like to use another gateway, please provide it below." ]
WebDav -> howNote [ inline [ "font-semibold" ] [ Kit.inlineIcon Icons.warning , text "This app requires a proper implementation of " , Kit.link { label = "CORS" , url = "https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS" } , text " on the server side." ] , lineBreak , text " WebDAV servers usually don't implement" , text " CORS properly, if at all." , lineBreak , text " Some servers, like " , Kit.link { label = "this one" , url = "https://github.com/hacdias/webdav" } , text ", do. You can find the configuration for that server " , Kit.link { label = "here" , url = "about/cors/#CORS__WebDAV" } , text "." ]
-- RENAME
rename : Form -> List (Html Msg)rename { context } = [ ----------------------------------------- -- Navigation ----------------------------------------- Navigation.local [ ( Icon Icons.arrow_back , Label "Go Back" Shown , PerformMsg ReturnToIndex ) ]
----------------------------------------- -- Content ----------------------------------------- , (\h -> form RenameSourceUsingForm [ Kit.canisterForm h ] ) [ Kit.h2 "Name your source"
-- Input -------- , [ name "name" , onInput (SetFormData "name") , value (Dict.fetch "name" "" context.data) ] |> Kit.textField |> chunky [ "max-w-md", "mx-auto" ]
-- Button --------- , chunk [ "mt-10" ] [ Kit.button Normal Bypass (text "Save") ] ] ]