|
@@ -10,9 +10,10 @@ import Database
|
|
|
import Deck
|
|
import Deck
|
|
|
import Dict exposing (Dict)
|
|
import Dict exposing (Dict)
|
|
|
import Draft exposing (Draft)
|
|
import Draft exposing (Draft)
|
|
|
-import Html exposing (Html, a, button, div, img, li, p, span, text, ul)
|
|
|
|
|
-import Html.Attributes exposing (alt, class, classList, disabled, src)
|
|
|
|
|
-import Html.Events as Events exposing (onClick, onMouseEnter)
|
|
|
|
|
|
|
+import DraftMeta exposing (DraftMeta)
|
|
|
|
|
+import Html exposing (Html, a, button, div, h1, img, input, label, li, p, span, text, ul)
|
|
|
|
|
+import Html.Attributes exposing (alt, class, classList, disabled, href, src, type_, value)
|
|
|
|
|
+import Html.Events as Events exposing (onClick, onInput, onMouseEnter)
|
|
|
import Html.Keyed as Keyed
|
|
import Html.Keyed as Keyed
|
|
|
import Icon exposing (chevronDown, chevronUp)
|
|
import Icon exposing (chevronDown, chevronUp)
|
|
|
import Json.Decode exposing (decodeString)
|
|
import Json.Decode exposing (decodeString)
|
|
@@ -72,9 +73,18 @@ type SetLoadStatus
|
|
|
| DeletingLocalData
|
|
| DeletingLocalData
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+type AvailableDrafts
|
|
|
|
|
+ = DraftsNotChecked
|
|
|
|
|
+ | DraftsLoading
|
|
|
|
|
+ | AvailableDrafts (List DraftMeta)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
type alias ChooseSetModel =
|
|
type alias ChooseSetModel =
|
|
|
{ draftData : String
|
|
{ draftData : String
|
|
|
, sets : Dict String SetLoadStatus
|
|
, sets : Dict String SetLoadStatus
|
|
|
|
|
+ , eventHistoryUrl : Maybe String -- Resolved event history URL
|
|
|
|
|
+ , eventHistoryUrlField : String -- Working state of input
|
|
|
|
|
+ , drafts : AvailableDrafts
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -105,7 +115,7 @@ type alias ErrorModel =
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-init : { sets : List String, draftData : String } -> ( Model, Cmd Msg )
|
|
|
|
|
|
|
+init : { sets : List String, draftData : String, eventHistoryUrl : Maybe String } -> ( Model, Cmd Msg )
|
|
|
init flags =
|
|
init flags =
|
|
|
let
|
|
let
|
|
|
setStatus : Dict String SetLoadStatus
|
|
setStatus : Dict String SetLoadStatus
|
|
@@ -119,12 +129,24 @@ init flags =
|
|
|
List.map
|
|
List.map
|
|
|
(\s -> sendDoesSetHaveLocalData s)
|
|
(\s -> sendDoesSetHaveLocalData s)
|
|
|
flags.sets
|
|
flags.sets
|
|
|
|
|
+
|
|
|
|
|
+ draftCmds : List (Cmd Msg)
|
|
|
|
|
+ draftCmds =
|
|
|
|
|
+ case flags.eventHistoryUrl of
|
|
|
|
|
+ Nothing ->
|
|
|
|
|
+ []
|
|
|
|
|
+
|
|
|
|
|
+ Just url ->
|
|
|
|
|
+ [ API.getDrafts url IOGotDrafts ]
|
|
|
in
|
|
in
|
|
|
( ChooseSet
|
|
( ChooseSet
|
|
|
{ draftData = flags.draftData
|
|
{ draftData = flags.draftData
|
|
|
, sets = setStatus
|
|
, sets = setStatus
|
|
|
|
|
+ , eventHistoryUrl = flags.eventHistoryUrl
|
|
|
|
|
+ , eventHistoryUrlField = ""
|
|
|
|
|
+ , drafts = DraftsNotChecked
|
|
|
}
|
|
}
|
|
|
- , Cmd.batch (API.getSets IOGotSets :: setCmds)
|
|
|
|
|
|
|
+ , Cmd.batch (API.getSets IOGotSets :: setCmds ++ draftCmds)
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -132,6 +154,8 @@ type Msg
|
|
|
= Increment
|
|
= Increment
|
|
|
| Decrement
|
|
| Decrement
|
|
|
| Highlight String
|
|
| Highlight String
|
|
|
|
|
+ | SetEventHistoryUrlField String
|
|
|
|
|
+ | SubmitEventHistoryUrlField
|
|
|
| FlipHighlightedCard
|
|
| FlipHighlightedCard
|
|
|
| SetFocusStat FocusStat
|
|
| SetFocusStat FocusStat
|
|
|
| SetSortOrder SortOrder
|
|
| SetSortOrder SortOrder
|
|
@@ -142,6 +166,7 @@ type Msg
|
|
|
| ToggleDeckList
|
|
| ToggleDeckList
|
|
|
| SetDeckSortMethod Deck.DeckSortMethod
|
|
| SetDeckSortMethod Deck.DeckSortMethod
|
|
|
| IOGotSets (Result String (List String))
|
|
| IOGotSets (Result String (List String))
|
|
|
|
|
+ | IOGotDrafts (Result String (List DraftMeta))
|
|
|
| IOFetchSetData String
|
|
| IOFetchSetData String
|
|
|
| IOGotSetData (Result String ( String, Maybe Database.Database ))
|
|
| IOGotSetData (Result String ( String, Maybe Database.Database ))
|
|
|
| IODeleteSetData String -- Delete by set code
|
|
| IODeleteSetData String -- Delete by set code
|
|
@@ -281,6 +306,24 @@ update msg model =
|
|
|
IOGotSetData (Err e) ->
|
|
IOGotSetData (Err e) ->
|
|
|
( Error { error = "Error fetching remote set data (" ++ e ++ ")" }, Cmd.none )
|
|
( Error { error = "Error fetching remote set data (" ++ e ++ ")" }, Cmd.none )
|
|
|
|
|
|
|
|
|
|
+ SetEventHistoryUrlField v ->
|
|
|
|
|
+ ( ChooseSet { mdl | eventHistoryUrlField = v }, Cmd.none )
|
|
|
|
|
+
|
|
|
|
|
+ SubmitEventHistoryUrlField ->
|
|
|
|
|
+ ( ChooseSet
|
|
|
|
|
+ { mdl
|
|
|
|
|
+ | eventHistoryUrl = Just mdl.eventHistoryUrlField
|
|
|
|
|
+ , drafts = DraftsLoading
|
|
|
|
|
+ }
|
|
|
|
|
+ , API.getDrafts mdl.eventHistoryUrlField IOGotDrafts
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ IOGotDrafts (Ok drafts) ->
|
|
|
|
|
+ ( ChooseSet { mdl | drafts = AvailableDrafts drafts }, Cmd.none )
|
|
|
|
|
+
|
|
|
|
|
+ IOGotDrafts (Err e) ->
|
|
|
|
|
+ ( Error { error = "Error fetching drafts (" ++ e ++ ")" }, Cmd.none )
|
|
|
|
|
+
|
|
|
_ ->
|
|
_ ->
|
|
|
( ChooseSet mdl, Cmd.none )
|
|
( ChooseSet mdl, Cmd.none )
|
|
|
|
|
|
|
@@ -359,6 +402,9 @@ update msg model =
|
|
|
IOGotDeleteSetData setCode ->
|
|
IOGotDeleteSetData setCode ->
|
|
|
( Ready mdl, Cmd.none )
|
|
( Ready mdl, Cmd.none )
|
|
|
|
|
|
|
|
|
|
+ IOGotDrafts _ ->
|
|
|
|
|
+ ( Ready mdl, Cmd.none )
|
|
|
|
|
+
|
|
|
PortReceiveDoesSetHaveLocalData _ ->
|
|
PortReceiveDoesSetHaveLocalData _ ->
|
|
|
( Ready mdl, Cmd.none )
|
|
( Ready mdl, Cmd.none )
|
|
|
|
|
|
|
@@ -368,6 +414,12 @@ update msg model =
|
|
|
OpenCardExplorer _ _ ->
|
|
OpenCardExplorer _ _ ->
|
|
|
( Ready mdl, Cmd.none )
|
|
( Ready mdl, Cmd.none )
|
|
|
|
|
|
|
|
|
|
+ SetEventHistoryUrlField _ ->
|
|
|
|
|
+ ( Ready mdl, Cmd.none )
|
|
|
|
|
+
|
|
|
|
|
+ SubmitEventHistoryUrlField ->
|
|
|
|
|
+ ( Ready mdl, Cmd.none )
|
|
|
|
|
+
|
|
|
CardExplorer mdl ->
|
|
CardExplorer mdl ->
|
|
|
case msg of
|
|
case msg of
|
|
|
Highlight card ->
|
|
Highlight card ->
|
|
@@ -434,8 +486,13 @@ viewChooseSet model =
|
|
|
, Button.make "Delete" (IODeleteSetData setCode) |> Button.view
|
|
, Button.make "Delete" (IODeleteSetData setCode) |> Button.view
|
|
|
]
|
|
]
|
|
|
in
|
|
in
|
|
|
- div [ class "w-full h-full bg-slate-100 flex justify-center items-center" ]
|
|
|
|
|
- [ div [ class "max-w-2xl max-h-2xl bg-slate-500 rounded-lg p-6 shadow-xl" ]
|
|
|
|
|
|
|
+ div [ class "w-full h-full bg-slate-100 flex flex-col gap-4 justify-center items-center" ]
|
|
|
|
|
+ [ div [ class "max-w-4xl max-h-2xl bg-slate-500 rounded-lg p-6 shadow-xl" ]
|
|
|
|
|
+ [ h1 [ class "text-3xl text-white font-medium" ] [ text "Drafter" ]
|
|
|
|
|
+ , p [ class "text-white font-medium" ] [ text "Explore sets and analyse your draft events." ]
|
|
|
|
|
+ , viewEventHistoryURL model
|
|
|
|
|
+ ]
|
|
|
|
|
+ , div [ class "max-w-4xl max-h-2xl bg-slate-500 rounded-lg p-6 shadow-xl" ]
|
|
|
[ ul [ class "divide-y divide-slate-600" ]
|
|
[ ul [ class "divide-y divide-slate-600" ]
|
|
|
(List.map
|
|
(List.map
|
|
|
(\s ->
|
|
(\s ->
|
|
@@ -455,6 +512,28 @@ viewChooseSet model =
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+viewEventHistoryURL : ChooseSetModel -> Html Msg
|
|
|
|
|
+viewEventHistoryURL model =
|
|
|
|
|
+ case model.eventHistoryUrl of
|
|
|
|
|
+ Just url ->
|
|
|
|
|
+ div []
|
|
|
|
|
+ [ p [] [ text "17Lands public event history:" ]
|
|
|
|
|
+ , a [ href url ] [ text url ]
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ Nothing ->
|
|
|
|
|
+ div [ class "mt-4" ]
|
|
|
|
|
+ [ label [ class "block text-sm font-medium text-white" ] [ text "Enter your 17Lands public event history URL:" ]
|
|
|
|
|
+ , input
|
|
|
|
|
+ [ type_ "text"
|
|
|
|
|
+ , onInput SetEventHistoryUrlField
|
|
|
|
|
+ , value model.eventHistoryUrlField
|
|
|
|
|
+ ]
|
|
|
|
|
+ []
|
|
|
|
|
+ , Button.make "Save" SubmitEventHistoryUrlField |> Button.view
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
viewReady : ReadyModel -> Html Msg
|
|
viewReady : ReadyModel -> Html Msg
|
|
|
viewReady model =
|
|
viewReady model =
|
|
|
div [ class "grid grid-cols-12 gap-6 h-full bg-slate-100" ]
|
|
div [ class "grid grid-cols-12 gap-6 h-full bg-slate-100" ]
|
|
@@ -1066,3 +1145,6 @@ port sendDeleteLocalData : Encode.Value -> Cmd msg
|
|
|
|
|
|
|
|
|
|
|
|
|
port receiveDidDeleteLocalData : (String -> msg) -> Sub msg
|
|
port receiveDidDeleteLocalData : (String -> msg) -> Sub msg
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+port sendSaveEventHistoryUrl : String -> Cmd msg
|