From c79b95e1d7d3487f4a9c4ea7954413adb6953685 Mon Sep 17 00:00:00 2001 From: Artus Date: Sun, 3 Nov 2019 22:01:45 +0100 Subject: [PATCH] refactors rowControls --- main.js | 625 ++++++++++++++++++++++++++++++--------------------- src/Main.elm | 150 ++++++++----- 2 files changed, 456 insertions(+), 319 deletions(-) diff --git a/main.js b/main.js index 1280781..3a837b2 100644 --- a/main.js +++ b/main.js @@ -6472,6 +6472,15 @@ var $elm$core$Set$Set_elm_builtin = function (a) { return {$: 'Set_elm_builtin', a: a}; }; var $elm$core$Set$empty = $elm$core$Set$Set_elm_builtin($elm$core$Dict$empty); +var $elm$core$Set$insert = F2( + function (key, _v0) { + var dict = _v0.a; + return $elm$core$Set$Set_elm_builtin( + A3($elm$core$Dict$insert, key, _Utils_Tuple0, dict)); + }); +var $elm$core$Set$fromList = function (list) { + return A3($elm$core$List$foldl, $elm$core$Set$insert, $elm$core$Set$empty, list); +}; var $elm$core$Debug$log = _Debug_log; var $elm$core$Platform$Cmd$none = $elm$core$Platform$Cmd$batch(_List_Nil); var $author$project$Main$printError = function (error) { @@ -6493,12 +6502,6 @@ var $author$project$Main$setError = F2( {error: error}) }); }); -var $elm$core$Set$insert = F2( - function (key, _v0) { - var dict = _v0.a; - return $elm$core$Set$Set_elm_builtin( - A3($elm$core$Dict$insert, key, _Utils_Tuple0, dict)); - }); var $elm$core$Dict$member = F2( function (key, dict) { var _v0 = A2($elm$core$Dict$get, key, dict); @@ -6739,7 +6742,16 @@ var $author$project$Main$update = F2( if (nextMode.$ === 'Nothing') { return $elm$core$Maybe$Nothing; } else { - return $elm$core$Maybe$Just($elm$core$Set$empty); + if (nextMode.a.$ === 'Grab') { + var _v12 = nextMode.a; + return $elm$core$Maybe$Just( + $elm$core$Set$fromList( + _List_fromArray( + [34, 38]))); + } else { + var others = nextMode.a; + return $elm$core$Maybe$Just($elm$core$Set$empty); + } } }() }) @@ -6780,14 +6792,17 @@ var $elm$html$Html$Events$onClick = function (msg) { 'click', $elm$json$Json$Decode$succeed(msg)); }; +var $elm$html$Html$p = _VirtualDom_node('p'); var $elm$html$Html$span = _VirtualDom_node('span'); +var $elm$virtual_dom$VirtualDom$text = _VirtualDom_text; +var $elm$html$Html$text = $elm$virtual_dom$VirtualDom$text; var $author$project$Main$actionButton = F4( function (mode, t, icon, color) { return A2( $elm$html$Html$button, _List_fromArray( [ - $elm$html$Html$Attributes$class('button is-rounded is-' + color), + $elm$html$Html$Attributes$class('button is-' + color), $elm$html$Html$Events$onClick( $author$project$Main$ModeSwitched(mode)) ]), @@ -6808,16 +6823,296 @@ var $author$project$Main$actionButton = F4( $elm$svg$Svg$Attributes$class('fas fa-' + icon) ]), _List_Nil) + ])), + A2( + $elm$html$Html$p, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text(t) ])) ])); }); var $elm$html$Html$article = _VirtualDom_node('article'); var $elm$html$Html$div = _VirtualDom_node('div'); var $elm$html$Html$hr = _VirtualDom_node('hr'); -var $elm$html$Html$p = _VirtualDom_node('p'); var $elm$html$Html$section = _VirtualDom_node('section'); -var $elm$virtual_dom$VirtualDom$text = _VirtualDom_text; -var $elm$html$Html$text = $elm$virtual_dom$VirtualDom$text; +var $author$project$Main$isSelected = F2( + function (selection, item) { + if (selection.$ === 'Just') { + var s = selection.a; + return A2($elm$core$Set$member, item.id, s); + } else { + return false; + } + }); +var $author$project$Main$renderName = function (item) { + return A2( + $elm$html$Html$p, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text(item.name) + ])); +}; +var $author$project$Main$LootViewItemSwitched = function (a) { + return {$: 'LootViewItemSwitched', a: a}; +}; +var $elm$core$String$fromFloat = _String_fromNumber; +var $elm$html$Html$input = _VirtualDom_node('input'); +var $elm$json$Json$Decode$at = F2( + function (fields, decoder) { + return A3($elm$core$List$foldr, $elm$json$Json$Decode$field, decoder, fields); + }); +var $elm$json$Json$Decode$bool = _Json_decodeBool; +var $elm$html$Html$Events$targetChecked = A2( + $elm$json$Json$Decode$at, + _List_fromArray( + ['target', 'checked']), + $elm$json$Json$Decode$bool); +var $elm$html$Html$Events$onCheck = function (tagger) { + return A2( + $elm$html$Html$Events$on, + 'change', + A2($elm$json$Json$Decode$map, tagger, $elm$html$Html$Events$targetChecked)); +}; +var $elm$html$Html$Attributes$type_ = $elm$html$Html$Attributes$stringProperty('type'); +var $author$project$Main$rowModeControlsRenderer = F2( + function (mode, item) { + var _v0 = function () { + switch (mode.$) { + case 'Buy': + return _Utils_Tuple2( + A2( + $elm$html$Html$p, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('level-item') + ]), + _List_fromArray( + [ + $elm$html$Html$text( + $elm$core$String$fromInt(item.base_price) + 'po') + ])), + true); + case 'Sell': + return _Utils_Tuple2( + A2( + $elm$html$Html$p, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('level-item') + ]), + _List_fromArray( + [ + $elm$html$Html$text( + $elm$core$String$fromFloat(item.base_price / 2) + 'po') + ])), + true); + case 'Grab': + return _Utils_Tuple2( + A2( + $elm$html$Html$p, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('level-item') + ]), + _List_fromArray( + [ + $elm$html$Html$text('Grab') + ])), + true); + case 'Add': + return _Utils_Tuple2( + A2( + $elm$html$Html$p, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('level-item') + ]), + _List_fromArray( + [ + $elm$html$Html$text('New !') + ])), + false); + default: + return _Utils_Tuple2( + $elm$html$Html$text(''), + false); + } + }(); + var itemInfo = _v0.a; + var canSelect = _v0.b; + return A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('level-right') + ]), + A2( + $elm$core$List$cons, + itemInfo, + canSelect ? _List_fromArray( + [ + A2( + $elm$html$Html$input, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('checkbox level-item'), + $elm$html$Html$Attributes$type_('checkbox'), + $elm$html$Html$Events$onCheck( + function (v) { + return $author$project$Main$LootViewItemSwitched(item.id); + }) + ]), + _List_Nil) + ]) : _List_Nil)); + }); +var $elm$html$Html$table = _VirtualDom_node('table'); +var $elm$html$Html$th = _VirtualDom_node('th'); +var $elm$html$Html$thead = _VirtualDom_node('thead'); +var $elm$core$List$filter = F2( + function (isGood, list) { + return A3( + $elm$core$List$foldr, + F2( + function (x, xs) { + return isGood(x) ? A2($elm$core$List$cons, x, xs) : xs; + }), + _List_Nil, + list); + }); +var $elm$core$Tuple$second = function (_v0) { + var y = _v0.b; + return y; +}; +var $elm$html$Html$Attributes$classList = function (classes) { + return $elm$html$Html$Attributes$class( + A2( + $elm$core$String$join, + ' ', + A2( + $elm$core$List$map, + $elm$core$Tuple$first, + A2($elm$core$List$filter, $elm$core$Tuple$second, classes)))); +}; +var $elm$html$Html$label = _VirtualDom_node('label'); +var $elm$core$List$singleton = function (value) { + return _List_fromArray( + [value]); +}; +var $elm$html$Html$td = _VirtualDom_node('td'); +var $elm$html$Html$tr = _VirtualDom_node('tr'); +var $author$project$Main$viewItemTableRow = F3( + function (selected, rowControls, item) { + return A2( + $elm$html$Html$tr, + _List_fromArray( + [ + $elm$html$Html$Attributes$classList( + _List_fromArray( + [ + _Utils_Tuple2( + 'is-selected', + selected(item)) + ])) + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$td, + _List_Nil, + _List_fromArray( + [ + A2( + $elm$html$Html$label, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('level checkbox') + ]), + A2( + $elm$core$List$cons, + A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('level-left') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$p, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('level-item') + ]), + _List_fromArray( + [ + $elm$html$Html$text(item.name) + ])) + ])), + function () { + if (rowControls.$ === 'Just') { + var render = rowControls.a; + return $elm$core$List$singleton( + render(item)); + } else { + return _List_Nil; + } + }())) + ])) + ])); + }); +var $author$project$Main$viewChest = F2( + function (items, model) { + var rowControls = function () { + var _v0 = model.state.activeMode; + if (_v0.$ === 'Just') { + var mode = _v0.a; + return $elm$core$Maybe$Just( + $author$project$Main$rowModeControlsRenderer(mode)); + } else { + var _v1 = model.state.route; + if (_v1.$ === 'GroupLoot') { + return $elm$core$Maybe$Just($author$project$Main$renderName); + } else { + var others = _v1; + return $elm$core$Maybe$Nothing; + } + } + }(); + return A2( + $elm$html$Html$table, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('table is-fullwidth is-striped is-light') + ]), + A2( + $elm$core$List$cons, + A2( + $elm$html$Html$thead, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('table-header') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$th, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text('Nom') + ])) + ])), + A2( + $elm$core$List$map, + A2( + $author$project$Main$viewItemTableRow, + $author$project$Main$isSelected(model.state.selection), + rowControls), + items))); + }); var $author$project$Main$stackedIcon = function (name) { return A2( $elm$html$Html$span, @@ -6996,6 +7291,25 @@ var $elm$html$Html$Attributes$href = function (url) { _VirtualDom_noJavaScriptUri(url)); }; var $elm$html$Html$nav = _VirtualDom_node('nav'); +var $author$project$Main$renderIcon = F2( + function (name, size) { + return A2( + $elm$html$Html$span, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('icon is-medium') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$i, + _List_fromArray( + [ + $elm$html$Html$Attributes$class(name + (' fa-' + size)) + ]), + _List_Nil) + ])); + }); var $author$project$Main$viewHeaderBar = function (model) { return A2( $elm$html$Html$nav, @@ -7023,7 +7337,14 @@ var $author$project$Main$viewHeaderBar = function (model) { ]), _List_fromArray( [ - $elm$html$Html$text(model.player.name) + A2($author$project$Main$renderIcon, 'fab fa-d-and-d', '2x'), + A2( + $elm$html$Html$span, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text(model.player.name) + ])) ])), A2( $elm$html$Html$a, @@ -7081,7 +7402,14 @@ var $author$project$Main$viewHeaderBar = function (model) { ]), _List_fromArray( [ - $elm$html$Html$text('Marchand') + A2($author$project$Main$renderIcon, 'fas fa-store-alt', '1x'), + A2( + $elm$html$Html$span, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text('Marchand') + ])) ])), A2( $elm$html$Html$a, @@ -7093,253 +7421,20 @@ var $author$project$Main$viewHeaderBar = function (model) { ]), _List_fromArray( [ - $elm$html$Html$text( - (!model.player.id) ? 'Nouveau loot' : 'Coffre de groupe') + A2($author$project$Main$renderIcon, 'fas fa-gem', '1x'), + A2( + $elm$html$Html$span, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text( + (!model.player.id) ? 'Nouveau loot' : 'Coffre de groupe') + ])) ])) ])) ])) ])); }; -var $elm$html$Html$table = _VirtualDom_node('table'); -var $elm$html$Html$th = _VirtualDom_node('th'); -var $elm$html$Html$thead = _VirtualDom_node('thead'); -var $author$project$Main$LootViewItemSwitched = function (a) { - return {$: 'LootViewItemSwitched', a: a}; -}; -var $elm$core$List$filter = F2( - function (isGood, list) { - return A3( - $elm$core$List$foldr, - F2( - function (x, xs) { - return isGood(x) ? A2($elm$core$List$cons, x, xs) : xs; - }), - _List_Nil, - list); - }); -var $elm$core$Tuple$second = function (_v0) { - var y = _v0.b; - return y; -}; -var $elm$html$Html$Attributes$classList = function (classes) { - return $elm$html$Html$Attributes$class( - A2( - $elm$core$String$join, - ' ', - A2( - $elm$core$List$map, - $elm$core$Tuple$first, - A2($elm$core$List$filter, $elm$core$Tuple$second, classes)))); -}; -var $elm$core$String$fromFloat = _String_fromNumber; -var $author$project$Main$controlsRenderer = F2( - function (mode, item) { - switch (mode.$) { - case 'Buy': - return A2( - $elm$html$Html$p, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('level-item') - ]), - _List_fromArray( - [ - $elm$html$Html$text( - $elm$core$String$fromInt(item.base_price) + 'po') - ])); - case 'Sell': - return A2( - $elm$html$Html$p, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('level-item') - ]), - _List_fromArray( - [ - $elm$html$Html$text( - $elm$core$String$fromFloat(item.base_price / 2) + 'po') - ])); - case 'Grab': - return A2( - $elm$html$Html$p, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('level-item') - ]), - _List_fromArray( - [ - $elm$html$Html$text('Grab') - ])); - case 'Add': - return A2( - $elm$html$Html$p, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('level-item') - ]), - _List_fromArray( - [ - $elm$html$Html$text('New !') - ])); - default: - return $elm$html$Html$text(''); - } - }); -var $elm$html$Html$input = _VirtualDom_node('input'); -var $author$project$Main$isSelected = F2( - function (id, selection) { - return A2($elm$core$Set$member, id, selection); - }); -var $elm$html$Html$label = _VirtualDom_node('label'); -var $elm$json$Json$Decode$at = F2( - function (fields, decoder) { - return A3($elm$core$List$foldr, $elm$json$Json$Decode$field, decoder, fields); - }); -var $elm$json$Json$Decode$bool = _Json_decodeBool; -var $elm$html$Html$Events$targetChecked = A2( - $elm$json$Json$Decode$at, - _List_fromArray( - ['target', 'checked']), - $elm$json$Json$Decode$bool); -var $elm$html$Html$Events$onCheck = function (tagger) { - return A2( - $elm$html$Html$Events$on, - 'change', - A2($elm$json$Json$Decode$map, tagger, $elm$html$Html$Events$targetChecked)); -}; -var $elm$core$List$singleton = function (value) { - return _List_fromArray( - [value]); -}; -var $elm$html$Html$td = _VirtualDom_node('td'); -var $elm$html$Html$tr = _VirtualDom_node('tr'); -var $elm$html$Html$Attributes$type_ = $elm$html$Html$Attributes$stringProperty('type'); -var $author$project$Main$viewItemTableRow = F3( - function (selection, activeMode, item) { - var selected = function () { - if (selection.$ === 'Just') { - var s = selection.a; - return A2($author$project$Main$isSelected, item.id, s); - } else { - return false; - } - }(); - var levelRight = function () { - if (activeMode.$ === 'Nothing') { - return _List_Nil; - } else { - var mode = activeMode.a; - return $elm$core$List$singleton( - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('level-right') - ]), - _List_fromArray( - [ - A2($author$project$Main$controlsRenderer, mode, item), - A2( - $elm$html$Html$input, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('checkbox level-item'), - $elm$html$Html$Attributes$type_('checkbox'), - $elm$html$Html$Events$onCheck( - function (v) { - return $author$project$Main$LootViewItemSwitched(item.id); - }) - ]), - _List_Nil) - ]))); - } - }(); - return A2( - $elm$html$Html$tr, - _List_fromArray( - [ - $elm$html$Html$Attributes$classList( - _List_fromArray( - [ - _Utils_Tuple2('is-selected', selected) - ])) - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$td, - _List_Nil, - _List_fromArray( - [ - A2( - $elm$html$Html$label, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('level checkbox') - ]), - $elm$core$List$concat( - _List_fromArray( - [ - _List_fromArray( - [ - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('level-left') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$p, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('level-item') - ]), - _List_fromArray( - [ - $elm$html$Html$text(item.name) - ])) - ])) - ]), - levelRight - ]))) - ])) - ])); - }); -var $author$project$Main$viewLoot = F3( - function (items, selection, activeMode) { - return A2( - $elm$html$Html$table, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('table is-fullwidth is-striped is-light') - ]), - _Utils_ap( - _List_fromArray( - [ - A2( - $elm$html$Html$thead, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('table-header') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$th, - _List_Nil, - _List_fromArray( - [ - $elm$html$Html$text('Nom') - ])) - ])) - ]), - A2( - $elm$core$List$map, - A2($author$project$Main$viewItemTableRow, selection, activeMode), - items))); - }); var $author$project$Main$showWealthField = F2( function (name, value) { return A2( @@ -7488,7 +7583,7 @@ var $author$project$Main$view = function (model) { $elm$html$Html$div, _List_fromArray( [ - $elm$html$Html$Attributes$class('buttons') + $elm$html$Html$Attributes$class('buttons has-addons') ]), _List_fromArray( [ @@ -7498,7 +7593,7 @@ var $author$project$Main$view = function (model) { 'Valider', 'plus', 'primary'), - A4($author$project$Main$actionButton, $elm$core$Maybe$Nothing, 'Annuler', 'coins', 'danger') + A4($author$project$Main$actionButton, $elm$core$Maybe$Nothing, 'Annuler', 'times', 'danger') ])) ]); } else { @@ -7510,7 +7605,7 @@ var $author$project$Main$view = function (model) { A4( $author$project$Main$actionButton, $elm$core$Maybe$Just($author$project$Main$Sell), - '', + 'Vendre', 'coins', 'danger') ]); @@ -7530,12 +7625,20 @@ var $author$project$Main$view = function (model) { A4( $author$project$Main$actionButton, $elm$core$Maybe$Just($author$project$Main$Buy), - '', + 'Acheter', 'coins', 'success') ]); default: - return _List_Nil; + return _List_fromArray( + [ + A4( + $author$project$Main$actionButton, + $elm$core$Maybe$Just($author$project$Main$Add), + 'Nouveau loot', + 'plus', + 'primary') + ]); } } }(); @@ -7584,7 +7687,7 @@ var $author$project$Main$view = function (model) { $elm$html$Html$text(header) ])), $author$project$Main$viewSearchBar, - A3($author$project$Main$viewLoot, shownLoot, model.state.selection, model.state.activeMode) + A2($author$project$Main$viewChest, shownLoot, model) ])), A2($elm$html$Html$hr, _List_Nil, _List_Nil), A2( diff --git a/src/Main.elm b/src/Main.elm index 7127ec6..7cc30b1 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -252,7 +252,8 @@ update msg model = { state | activeMode = nextMode , selection = case nextMode of Nothing -> Nothing - Just _ -> Just Set.empty + Just Grab -> Just (Set.fromList [34, 38]) + Just others -> Just Set.empty }} , cmd) @@ -303,9 +304,10 @@ type ViewMode | Confirm -- Confirm action and exit mode actionButton mode t icon color = - button [ class <| "button is-rounded is-" ++ color + button [ class <| "button is-" ++ color , onClick (ModeSwitched mode) ] [ span [ class "icon" ] [ i [ Svg.Attributes.class <| "fas fa-" ++ icon ] [] ] + , p [] [text t] ] view : Model -> Browser.Document Msg @@ -324,16 +326,17 @@ view model = actionControls = case model.state.activeMode of Just mode -> -- When a mode is active - [ div [class "buttons"] - [actionButton (Just Confirm) "Valider" "plus" "primary" - , actionButton Nothing "Annuler" "coins" "danger"] + [ div [ class "buttons has-addons"] + [ actionButton (Just Confirm) "Valider" "plus" "primary" + , actionButton Nothing "Annuler" "times" "danger" + ] ] Nothing -> -- Buttons to enter mode case model.state.route of - PlayerChest -> [actionButton (Just Sell) "" "coins" "danger"] + PlayerChest -> [actionButton (Just Sell) "Vendre" "coins" "danger"] GroupLoot -> [actionButton (Just Grab) "Demander" "coins" "primary"] - Merchant -> [actionButton (Just Buy) "" "coins" "success"] - NewLoot -> [] + Merchant -> [actionButton (Just Buy) "Acheter" "coins" "success"] + NewLoot -> [actionButton (Just Add) "Nouveau loot" "plus" "primary"] in { title = "Loot-a-lot in ELM" @@ -343,7 +346,7 @@ view model = , article [class "section container"] [ p [class "heading"] [text header] , viewSearchBar - , viewLoot shownLoot model.state.selection model.state.activeMode + , viewChest shownLoot model ] , hr [] [] , section [class "container"] [viewDebugSection model] @@ -352,58 +355,76 @@ view model = -- LOOT Views -isSelected id selection = - Set.member id selection +isSelected : Maybe Selection -> Item -> Bool +isSelected selection item = + case selection of + Just s -> + Set.member item.id s + Nothing -> + False -viewLoot : Loot -> Maybe Selection -> Maybe ViewMode -> Html Msg -viewLoot items selection activeMode = - table [ class "table is-fullwidth is-striped is-light"] - ([ thead [class "table-header"] - [ th [] [text "Nom"] ] - ] - ++ List.map (viewItemTableRow selection activeMode) items - ) +renderName item = + p [] [text item.name] -controlsRenderer : ViewMode -> Item -> Html Msg -controlsRenderer mode item = - case mode of - Buy -> p [class "level-item"] [ text (String.fromInt item.base_price ++ "po")] - Sell -> p [class "level-item"] [ text (String.fromFloat (toFloat item.base_price / 2) ++ "po")] - Grab -> p [class "level-item"] [ text "Grab" ] - Add -> p [class "level-item"] [ text "New !" ] - Confirm -> text "" - -viewItemTableRow : Maybe Selection -> Maybe ViewMode -> Item -> Html Msg -viewItemTableRow selection activeMode item = +viewChest : Loot -> Model -> Html Msg +viewChest items model = let - selected = - case selection of - Just s -> - isSelected item.id s - Nothing -> - False - - levelRight = - case activeMode of - Nothing -> [] - Just mode -> List.singleton ( - div [ class "level-right" ] - [ controlsRenderer mode item - , input [ class "checkbox level-item" - , type_ "checkbox" - , onCheck (\v -> LootViewItemSwitched item.id) - ] [] - ]) + -- If a mode is active, render its controls + -- Otherwise, controls may be rendered depending on current route + rowControls = case model.state.activeMode of + Just mode -> Just (rowModeControlsRenderer mode) + Nothing -> + case model.state.route of + GroupLoot -> Just renderName + others -> Nothing in - tr [ classList [ ("is-selected", selected) ] ] + table [ class "table is-fullwidth is-striped is-light"] + <| thead [ class "table-header" ] + [ th [] [ text "Nom" ] ] + :: List.map (viewItemTableRow (isSelected model.state.selection) rowControls) items + +-- Renders controls for a specific mode +rowModeControlsRenderer : ViewMode -> Item -> Html Msg +rowModeControlsRenderer mode item = + let + (itemInfo, canSelect) = case mode of + Buy -> + ( p [class "level-item"] [ text (String.fromInt item.base_price ++ "po")] + , True ) + Sell -> + ( p [class "level-item"] [ text (String.fromFloat (toFloat item.base_price / 2) ++ "po")] + , True ) + Grab -> + ( p [class "level-item"] [ text "Grab" ] + , True ) + Add -> + ( p [class "level-item"] [ text "New !" ] + , False ) + Confirm -> + (text "" + , False ) + in + div [ class "level-right" ] + <| itemInfo + :: if canSelect then + [input [ class "checkbox level-item" + , type_ "checkbox" + , onCheck (\v -> LootViewItemSwitched item.id) + ] [] ] + else + [] + + +viewItemTableRow : (Item -> Bool) -> Maybe (Item -> Html Msg) -> Item -> Html Msg +viewItemTableRow selected rowControls item = + tr [ classList [ ("is-selected", selected item) ] ] [ td [] [ label [ class "level checkbox" ] - (List.concat [[ - div [ class "level-left" ] - [ p [class "level-item"] [ text item.name ]] - ] - , levelRight - ]) + <| div [ class "level-left" ] + [ p [class "level-item"] [ text item.name ]] + :: case rowControls of + Just render -> List.singleton (render item) + Nothing -> [] ] ] @@ -452,6 +473,12 @@ debugSwitchPlayers = , a [ onClick (PlayerChanged 2) ] [text "Fefi"] ] + +renderIcon name size = + span [ class <| "icon is-medium"] + [ i [ class <| name ++ " fa-" ++ size] [] ] + + -- HEADER SECTION viewHeaderBar : Model -> Html Msg @@ -459,7 +486,9 @@ viewHeaderBar model = nav [ class "navbar container", class "is-info" ] [ div [ class "navbar-brand" ] [ a [ class "navbar-item", href "/"] - [ text model.player.name ] + [ renderIcon "fab fa-d-and-d" "2x" + , span [] [ text model.player.name ] + ] , a [class "navbar-burger is-active"] [ span [attribute "aria-hidden" "true"] [] , span [attribute "aria-hidden" "true"] [] @@ -468,7 +497,10 @@ viewHeaderBar model = ] , div [ class "navbar-menu is-active" ] [ div [class "navbar-end"] - [ a [class "navbar-item", href "/marchand"] [text "Marchand"] + [ a [class "navbar-item", href "/marchand"] + [ renderIcon "fas fa-store-alt" "1x" + , span [] [text "Marchand"] + ] , a [ class "navbar-item" , href (if model.player.id == 0 @@ -477,7 +509,9 @@ viewHeaderBar model = else "/coffre") ] - [text (if model.player.id == 0 then "Nouveau loot" else "Coffre de groupe")] + [ renderIcon "fas fa-gem" "1x" + , span [] [text (if model.player.id == 0 then "Nouveau loot" else "Coffre de groupe")] + ] ] ]