Skip to content

Commit

Permalink
Decklist index filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
lsocrate committed Dec 22, 2021
1 parent 1e72475 commit 9d6bf87
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 29 deletions.
7 changes: 4 additions & 3 deletions client/src/API/Decklist.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module API.Decklist exposing
)

import API.Auth exposing (auth)
import Data.Collection exposing (Collection)
import Deck exposing (DeckPostSave)
import Http
import Json.Decode as Decode
Expand Down Expand Up @@ -75,7 +76,7 @@ type alias ResultRead =
Result Http.Error DeckPostSave


read : Shared.Collection -> (ResultRead -> msg) -> String -> Cmd msg
read : Collection -> (ResultRead -> msg) -> String -> Cmd msg
read collection msg deckId =
Http.get
{ url = "/api/v1/decklist/" ++ deckId
Expand All @@ -87,15 +88,15 @@ type alias ResultIndex =
Result Http.Error (List DeckPostSave)


index : Shared.Collection -> (ResultIndex -> msg) -> Cmd msg
index : Collection -> (ResultIndex -> msg) -> Cmd msg
index collection msg =
Http.get
{ url = "/api/v1/decklist"
, expect = Http.expectJson msg (Decode.list <| Deck.decoder collection)
}


indexForUser : Shared.Collection -> (ResultIndex -> msg) -> String -> Cmd msg
indexForUser : Collection -> (ResultIndex -> msg) -> String -> Cmd msg
indexForUser collection msg userId =
Http.get
{ url = "/api/v1/decklist?userId=" ++ userId
Expand Down
40 changes: 39 additions & 1 deletion client/src/Data/Clan.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Data.Clan exposing (Clan(..), all, comparable, decoder)
module Data.Clan exposing (Clan(..), all, comparable, decoder, fromString, name, toString)

import Enum exposing (Enum)
import Json.Decode exposing (Decoder)
Expand Down Expand Up @@ -29,6 +29,16 @@ enum =
]


toString : Clan -> String
toString =
enum.toString


fromString : String -> Maybe Clan
fromString =
enum.fromString


all : List Clan
all =
List.map Tuple.second enum.list
Expand Down Expand Up @@ -65,3 +75,31 @@ comparable c =

Ventrue ->
8


name : Clan -> String
name c =
case c of
Brujah ->
"Brujah"

Gangrel ->
"Gangrel"

Malkavian ->
"Malkavian"

Nosferatu ->
"Nosferatu"

ThinBlood ->
"Thin-blood"

Toreador ->
"Toreador"

Tremere ->
"Tremere"

Ventrue ->
"Ventrue"
41 changes: 41 additions & 0 deletions client/src/Data/Collection.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Data.Collection exposing (Collection, groupByStack)

import Cards
import Dict


type alias Collection =
Dict.Dict Cards.Id Cards.Card


type alias GroupedByStacks =
{ agendaStack : List Cards.Agenda
, factionStack : List Cards.Faction
, havenStack : List Cards.Haven
, libraryStack : List Cards.Library
}


groupByStack : Collection -> GroupedByStacks
groupByStack =
Dict.values
>> List.foldl
(\card grouped ->
case card of
Cards.AgendaCard c ->
{ grouped | agendaStack = c :: grouped.agendaStack }

Cards.FactionCard c ->
{ grouped | factionStack = c :: grouped.factionStack }

Cards.HavenCard c ->
{ grouped | havenStack = c :: grouped.havenStack }

Cards.LibraryCard c ->
{ grouped | libraryStack = c :: grouped.libraryStack }
)
{ agendaStack = []
, factionStack = []
, havenStack = []
, libraryStack = []
}
2 changes: 1 addition & 1 deletion client/src/Data/GameMode.elm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ shortName mode =

allows : GameMode -> GameMode -> Bool
allows target current =
current == Both || current == target
current == Both || target == Both || current == target


decode : Decoder GameMode
Expand Down
2 changes: 1 addition & 1 deletion client/src/Deck.elm
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ module Deck exposing

import Cards
import Data.Clan exposing (Clan)
import Data.Collection exposing (Collection)
import Data.GameMode as GameMode exposing (GameMode)
import Dict exposing (Dict)
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode
import Shared exposing (Collection)



Expand Down
3 changes: 2 additions & 1 deletion client/src/Pages/Deck/Edit/Id_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import API.Decklist
import Auth
import Browser.Navigation as Navigation exposing (Key)
import Cards
import Data.Collection exposing (Collection)
import Data.GameMode exposing (GameMode)
import Deck exposing (DeckPostSave, Name(..))
import Effect exposing (Effect)
Expand Down Expand Up @@ -49,7 +50,7 @@ type alias Data =
}


init : Shared.Collection -> Key -> String -> ( Model, Effect Msg )
init : Collection -> Key -> String -> ( Model, Effect Msg )
init collection key deckId =
( Loading key
, Effect.fromCmd <| API.Decklist.read collection FetchedDecklist deckId
Expand Down
Loading

0 comments on commit 9d6bf87

Please sign in to comment.