makes selection work

This commit is contained in:
2019-11-02 21:55:55 +01:00
parent 68c8761c3d
commit eb2ee54add
2 changed files with 200 additions and 141 deletions

255
main.js
View File

@@ -6452,7 +6452,7 @@ var $author$project$Main$init = F3(
return _Utils_Tuple2(
A5(
$author$project$Main$Model,
A5($author$project$Main$State, key, route, '', false, _List_Nil),
A5($author$project$Main$State, key, route, '', false, $elm$core$Maybe$Nothing),
$author$project$Main$blankPlayer,
$elm$core$Maybe$Nothing,
$elm$core$Maybe$Nothing,
@@ -6464,6 +6464,11 @@ var $elm$core$Platform$Sub$none = $elm$core$Platform$Sub$batch(_List_Nil);
var $author$project$Main$subscriptions = function (_v0) {
return $elm$core$Platform$Sub$none;
};
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$Debug$log = _Debug_log;
var $elm$core$Platform$Cmd$none = $elm$core$Platform$Cmd$batch(_List_Nil);
var $author$project$Main$printError = function (error) {
if (error.$ === 'NetworkError') {
@@ -6484,29 +6489,48 @@ var $author$project$Main$setError = F2(
{error: error})
});
});
var $elm$core$Basics$not = _Basics_not;
var $author$project$Main$switchBooleanAt = function (idx) {
return F2(
function (i, value) {
return _Utils_eq(i, idx) ? (!value) : value;
});
};
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);
if (_v0.$ === 'Just') {
return true;
} else {
return false;
}
});
var $elm$core$Set$member = F2(
function (key, _v0) {
var dict = _v0.a;
return A2($elm$core$Dict$member, key, dict);
});
var $elm$core$Set$remove = F2(
function (key, _v0) {
var dict = _v0.a;
return $elm$core$Set$Set_elm_builtin(
A2($elm$core$Dict$remove, key, dict));
});
var $author$project$Main$switchSelectionState = F2(
function (idx, model) {
var state = model.state;
var selection = model.state.selectedItems;
return _Utils_update(
model,
{
state: _Utils_update(
state,
{
selectedItems: A2(
$elm$core$List$indexedMap,
$author$project$Main$switchBooleanAt(idx),
selection)
})
});
function (id, selection) {
if (selection.$ === 'Just') {
var s = selection.a;
return $elm$core$Maybe$Just(
function () {
var _v1 = A2($elm$core$Set$member, id, s);
if (_v1) {
return A2($elm$core$Set$remove, id, s);
} else {
return A2($elm$core$Set$insert, id, s);
}
}());
} else {
return A2($elm$core$Debug$log, 'ignore switchSelectionState', $elm$core$Maybe$Nothing);
}
});
var $elm$url$Url$addPort = F2(
function (maybePort, starter) {
@@ -6552,15 +6576,6 @@ var $elm$url$Url$toString = function (url) {
_Utils_ap(http, url.host)),
url.path)));
};
var $elm$core$Maybe$withDefault = F2(
function (_default, maybe) {
if (maybe.$ === 'Just') {
var value = maybe.a;
return value;
} else {
return _default;
}
});
var $author$project$Main$update = F2(
function (msg, model) {
switch (msg.$) {
@@ -6595,33 +6610,7 @@ var $author$project$Main$update = F2(
state,
{
route: page,
selectedItems: function () {
switch (page.$) {
case 'GroupLoot':
return A2(
$elm$core$List$map,
function (v) {
return false;
},
A2($elm$core$Maybe$withDefault, _List_Nil, model.groupLoot));
case 'PlayerChest':
return A2(
$elm$core$List$map,
function (v) {
return false;
},
A2($elm$core$Maybe$withDefault, _List_Nil, model.loot));
case 'Merchant':
return A2(
$elm$core$List$map,
function (v) {
return false;
},
A2($elm$core$Maybe$withDefault, _List_Nil, model.merchantItems));
default:
return _List_Nil;
}
}()
selectedItems: $elm$core$Maybe$Just($elm$core$Set$empty)
})
});
}(),
@@ -6702,9 +6691,21 @@ var $author$project$Main$update = F2(
$elm$core$Platform$Cmd$none);
}
default:
var idx = msg.a;
var id = msg.a;
var state = model.state;
return _Utils_Tuple2(
A2($author$project$Main$switchSelectionState, idx, model),
_Utils_update(
model,
{
state: _Utils_update(
state,
{
selectedItems: A2(
$elm$core$Debug$log,
'new selection',
A2($author$project$Main$switchSelectionState, id, state.selectedItems))
})
}),
$elm$core$Platform$Cmd$none);
}
});
@@ -6994,12 +6995,44 @@ var $elm$html$Html$Attributes$classList = function (classes) {
A2($elm$core$List$filter, $elm$core$Tuple$second, classes))));
};
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$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 (selected, idx, item) {
var $author$project$Main$viewItemTableRow = F2(
function (selection, item) {
var _v0 = function () {
if (selection.$ === 'Just') {
var s = selection.a;
return _Utils_Tuple2(
true,
A2($author$project$Main$isSelected, item.id, s));
} else {
return _Utils_Tuple2(false, false);
}
}();
var canSelect = _v0.a;
var selected = _v0.b;
return A2(
$elm$html$Html$tr,
_List_fromArray(
@@ -7021,9 +7054,7 @@ var $author$project$Main$viewItemTableRow = F3(
$elm$html$Html$label,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level checkbox'),
$elm$html$Html$Events$onClick(
$author$project$Main$LootViewItemSwitched(idx))
$elm$html$Html$Attributes$class('level checkbox')
]),
_List_fromArray(
[
@@ -7070,7 +7101,11 @@ var $author$project$Main$viewItemTableRow = F3(
_List_fromArray(
[
$elm$html$Html$Attributes$class('checkbox level-item'),
$elm$html$Html$Attributes$type_('checkbox')
$elm$html$Html$Attributes$type_('checkbox'),
$elm$html$Html$Events$onCheck(
function (v) {
return $author$project$Main$LootViewItemSwitched(item.id);
})
]),
_List_Nil)
]))
@@ -7078,38 +7113,39 @@ var $author$project$Main$viewItemTableRow = F3(
]))
]));
});
var $author$project$Main$viewLoot = function (items) {
return A2(
$elm$html$Html$table,
_List_fromArray(
[
$elm$html$Html$Attributes$class('table is-fullwidth is-striped')
]),
_Utils_ap(
var $author$project$Main$viewLoot = F2(
function (items, selection) {
return A2(
$elm$html$Html$table,
_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')
]))
]))
$elm$html$Html$Attributes$class('table is-fullwidth is-striped')
]),
A2(
$elm$core$List$indexedMap,
$author$project$Main$viewItemTableRow(false),
items)));
};
_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,
$author$project$Main$viewItemTableRow(selection),
items)));
});
var $elm$html$Html$i = _VirtualDom_node('i');
var $author$project$Main$showWealthField = F2(
function (name, value) {
@@ -7301,6 +7337,15 @@ var $author$project$Main$viewSearchBar = A2(
$elm$html$Html$Attributes$class('input')
]),
_List_Nil);
var $elm$core$Maybe$withDefault = F2(
function (_default, maybe) {
if (maybe.$ === 'Just') {
var value = maybe.a;
return value;
} else {
return _default;
}
});
var $author$project$Main$view = function (model) {
return {
body: _List_fromArray(
@@ -7330,8 +7375,10 @@ var $author$project$Main$view = function (model) {
$elm$html$Html$text('Mon Coffre')
])),
$author$project$Main$viewSearchBar,
$author$project$Main$viewLoot(
A2($elm$core$Maybe$withDefault, _List_Nil, model.loot))
A2(
$author$project$Main$viewLoot,
A2($elm$core$Maybe$withDefault, _List_Nil, model.loot),
model.state.selectedItems)
]);
case 'GroupLoot':
return _List_fromArray(
@@ -7343,8 +7390,10 @@ var $author$project$Main$view = function (model) {
[
$elm$html$Html$text('Coffre de groupe')
])),
$author$project$Main$viewLoot(
A2($elm$core$Maybe$withDefault, _List_Nil, model.groupLoot))
A2(
$author$project$Main$viewLoot,
A2($elm$core$Maybe$withDefault, _List_Nil, model.groupLoot),
model.state.selectedItems)
]);
case 'Merchant':
return _List_fromArray(
@@ -7356,8 +7405,10 @@ var $author$project$Main$view = function (model) {
[
$elm$html$Html$text('Acheter des objets')
])),
$author$project$Main$viewLoot(
A2($elm$core$Maybe$withDefault, _List_Nil, model.merchantItems))
A2(
$author$project$Main$viewLoot,
A2($elm$core$Maybe$withDefault, _List_Nil, model.merchantItems),
model.state.selectedItems)
]);
default:
return _List_fromArray(