-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
196 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
module Pages.MyDecks exposing (Model, Msg, page) | ||
|
||
import API.Decklist | ||
import Deck exposing (DeckPostSave) | ||
import Effect exposing (Effect) | ||
import Gen.Params.MyDecks exposing (Params) | ||
import Html exposing (div, text) | ||
import Page | ||
import Request | ||
import Shared | ||
import UI.DecklistsIndex | ||
import UI.Layout.Template | ||
import UI.Text | ||
import View exposing (View) | ||
|
||
|
||
page : Shared.Model -> Request.With Params -> Page.With Model Msg | ||
page shared _ = | ||
Page.protected.advanced | ||
(\user -> | ||
{ init = init shared user.id | ||
, update = update | ||
, view = view shared | ||
, subscriptions = always Sub.none | ||
} | ||
) | ||
|
||
|
||
|
||
-- INIT | ||
|
||
|
||
type Model | ||
= Loading | ||
| Viewing (List DeckPostSave) | ||
|
||
|
||
init : Shared.Model -> String -> ( Model, Effect Msg ) | ||
init shared userId = | ||
( Loading | ||
, API.Decklist.indexForUser shared.collection FetchedDecklists userId | ||
|> Effect.fromCmd | ||
) | ||
|
||
|
||
|
||
-- UPDATE | ||
|
||
|
||
type Msg | ||
= FromShared Shared.Msg | ||
| FetchedDecklists API.Decklist.ResultIndex | ||
|
||
|
||
update : Msg -> Model -> ( Model, Effect Msg ) | ||
update msg model = | ||
case msg of | ||
FromShared subMsg -> | ||
( model, Effect.fromShared subMsg ) | ||
|
||
FetchedDecklists (Ok decks) -> | ||
( Viewing decks, Effect.none ) | ||
|
||
FetchedDecklists (Err _) -> | ||
( model, Effect.none ) | ||
|
||
|
||
|
||
---------- | ||
-- VIEW | ||
---------- | ||
|
||
|
||
view : Shared.Model -> Model -> View Msg | ||
view shared model = | ||
case model of | ||
Loading -> | ||
UI.Layout.Template.view FromShared shared [ text "Loading" ] | ||
|
||
Viewing ddd -> | ||
viewDecklists shared ddd | ||
|
||
|
||
viewDecklists : Shared.Model -> List DeckPostSave -> View Msg | ||
viewDecklists shared model = | ||
UI.Layout.Template.view FromShared | ||
shared | ||
[ div [] | ||
[ UI.Text.header [ text "My Decklists" ] | ||
, UI.DecklistsIndex.view model | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module UI.DecklistsIndex exposing (view) | ||
|
||
import Cards | ||
import Deck exposing (DeckPostSave) | ||
import Gen.Route as Route | ||
import Html exposing (Html, a, div, li, p, span, text, ul) | ||
import Html.Attributes exposing (class, href) | ||
import UI.Card | ||
import UI.Icon | ||
|
||
|
||
view : List DeckPostSave -> Html unknown | ||
view model = | ||
ul [ class "deckindex" ] | ||
(model |> List.map viewDecklistEntry) | ||
|
||
|
||
viewDecklistEntry : DeckPostSave -> Html msg | ||
viewDecklistEntry deck = | ||
li [ class "deckindexitem" ] | ||
[ a [ class "deckindexcard", href <| Route.toHref (Route.Deck__View__Id_ { id = deck.meta.id }) ] | ||
[ div [ class "deckindexcard__illustration" ] [ illustrationImage deck.decklist ] | ||
, div [ class "deckindexcard__illustration-overlay" ] [] | ||
, div [ class "deckindexcard__content" ] | ||
[ p [ class "deckindexcard__name" ] [ text <| Deck.displayName deck.meta.name ] | ||
, p [ class "deckindexcard__byline" ] [ text "by: ", text <| Deck.ownerDisplayName deck.meta ] | ||
, p [ class "deckindexcard__clans" ] | ||
(Deck.clansInFaction deck.decklist.faction | ||
|> List.map | ||
(\( clan, _ ) -> | ||
span [ class "deckindexcard__clan" ] [ UI.Icon.clan UI.Icon.Negative clan ] | ||
) | ||
) | ||
, p [ class "deckindexcard__summary" ] | ||
[ Deck.leader deck.decklist |> Maybe.map (.name >> text) |> Maybe.withDefault (text "Unknown Leader") | ||
, text " • " | ||
, deck.decklist.haven |> Maybe.map (.name >> text) |> Maybe.withDefault (text "Unknown Haven") | ||
, text " • " | ||
, deck.decklist.agenda |> Maybe.map (.name >> text) |> Maybe.withDefault (text "Unknown Agenda") | ||
] | ||
] | ||
] | ||
] | ||
|
||
|
||
illustrationImage : Deck.Decklist -> Html msg | ||
illustrationImage decklist = | ||
case Deck.leader decklist of | ||
Just leader -> | ||
UI.Card.lazy (Cards.FactionCard leader) | ||
|
||
Nothing -> | ||
case Deck.fallbackLeader decklist of | ||
Just fallbackLeader -> | ||
UI.Card.lazy (Cards.FactionCard fallbackLeader) | ||
|
||
Nothing -> | ||
span [] [] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters