module Types exposing ( Editing(..) , ListFilter(..) , LogSheet , Model , Msg(..) , Screen(..) , SheetTarget(..) , Transfer , TransferNote(..) , TransferScope(..) , activeConvention , conventionsInScope , draftText , filterLabel , withDraft ) {-| Application state: what is on screen, what is half-typed, what is open This is separate from Data on purpose, Data is the stuff worth saving. Everything here is throwaway UI state that should not survive a reload, with the single exception of which convention is active. It also lives in its own module so that Main and the `View.*` modules can both see Msg without importing each other -} import Data exposing (Condition, Convention, ConventionId, ItemId, Priority) import Date exposing (Date) import File exposing (File) type alias Model = { conventions : List Convention , active : Maybe ConventionId , screen : Screen , sheet : Maybe LogSheet , editing : Editing , loadError : Maybe String , today : Date , nextConventionId : Int -- Which convention the shelf is asking you to confirm removing -- Armed by one tap, fired by a second, cleared by doing anything else , confirmDelete : Maybe ConventionId -- Section and page you were last looking at in the binder -- Keep things speedy and fresh , binderSpot : ( Int, Int ) -- The move-data-between-devices panel, when it is open , transfer : Maybe Transfer } type Screen = Shelf | Binder Int Int | ListView ListFilter String | Lookup String type ListFilter = AllItems | MustFindOnly | OpenOnly | FoundOnly filterLabel : ListFilter -> String filterLabel filter = case filter of AllItems -> "All" MustFindOnly -> "Must find" OpenOnly -> "Open" FoundOnly -> "Found" -- MOVING DATA BETWEEN DEVICES {-| The open transfer panel Lives here rather than in Data because none of it is worth saving! Close the panel and there is nothing left to remember, bye bye! -} type alias Transfer = { scope : TransferScope , paste : String , note : Maybe TransferNote , copied : Maybe Bool } {-| What you are sending out Are we sending out a single convention, or all of them? -} type TransferScope = WholeShelf | JustConvention ConventionId {-| How the last import went. Shown in the panel and nowhere else -} type TransferNote = Imported Int | ImportFailed String -- LOG SHEET {-| The bottom sheet for recording a find -} type alias LogSheet = { target : SheetTarget , name : String , priority : Priority , lowText : String , highText : String , paidText : String , quantity : Int , condition : Condition , booth : String , note : String } type SheetTarget = NewItem Int | ExistingItem ItemId -- INLINE EDITING type Editing = NotEditing | EditingName String | EditingBudget String | EditingVenue String | EditingDate String | EditingSection Int String {-| The half-typed text inside whichever editor is open -} draftText : Editing -> String draftText editing = case editing of NotEditing -> "" EditingName text -> text EditingBudget text -> text EditingVenue text -> text EditingDate text -> text EditingSection _ text -> text {-| Replace the draft text, keeping whichever editor is open -} withDraft : String -> Editing -> Editing withDraft text editing = case editing of NotEditing -> NotEditing EditingName _ -> EditingName text EditingBudget _ -> EditingBudget text EditingVenue _ -> EditingVenue text EditingDate _ -> EditingDate text EditingSection index _ -> EditingSection index text -- HELPERS activeConvention : Model -> Maybe Convention activeConvention model = model.active |> Maybe.andThen (\id -> model.conventions |> List.filter (\convention -> convention.id == id) |> List.head ) {-| The conventions a transfer would send -} conventionsInScope : Model -> TransferScope -> List Convention conventionsInScope model scope = case scope of WholeShelf -> model.conventions JustConvention id -> List.filter (\convention -> convention.id == id) model.conventions -- MESSAGES type Msg = NoOp -- Navigation | GoToShelf | OpenConvention ConventionId | SetScreen Screen | SelectSection Int | SelectPage Int | SetListFilter ListFilter | SetListSearch String | SetLookupQuery String -- The convention itself | StartEditing Editing | EditDraft String | CommitEditing | CancelEditing | CycleStatus | CreateConvention | ConfirmDelete ConventionId | DeleteConvention ConventionId | AddSection -- The log sheet | OpenNewItem Int | OpenItem ItemId | CloseSheet | SheetName String | SheetPriority Priority | SheetLow String | SheetHigh String | SheetPaid String | SheetQuantity Int | SheetCondition Condition | SheetBooth String | SheetNote String | CommitSheet | PassItem | ResumeHunting | DeleteItem -- Moving data between devices | OpenTransfer TransferScope | CloseTransfer | SaveTransferFile | PickImportFile | ImportFileSelected File | EditImportPaste String | ImportNow String | CopyText String | CopyFinished Bool