Minor cleanup

This commit is contained in:
Ozzie Gooen 2020-02-10 21:16:17 +00:00
parent 7a1145f409
commit fc3108c289
2 changed files with 37 additions and 37 deletions

View File

@ -155,6 +155,13 @@ module Combo = {
let update = (t: t, key: string, onUpdate: option(Value.t)) => let update = (t: t, key: string, onUpdate: option(Value.t)) =>
ValueMap.update(t.inputValues, key, onUpdate); ValueMap.update(t.inputValues, key, onUpdate);
let toValueArray = (t: t) => {
t.model.inputTypes
|> E.A.fmap((r: TypeWithMetadata.t) =>
ValueMap.get(t.inputValues, r.id)
);
};
}; };
let updateInputValue = (t: t, k, u) => { let updateInputValue = (t: t, k, u) => {

View File

@ -115,42 +115,36 @@ module Model = {
module Interface = { module Interface = {
open Data; open Data;
let convertChoice = (s: string) =>
switch (s) {
| "animal" => Fund(ANIMAL_WELFARE)
| "globalHealth" => Fund(GLOBAL_HEALTH)
| "longTerm" => Fund(LONG_TERM_FUTURE)
| "meta" => Fund(META)
| _ => All
};
let convertOutput = (s: string) => let fundKey = "Fund";
let dayKey = "Day";
let outputKey = "Output";
let choiceFromString = (s: string) =>
funds |> E.A.getBy(_, r => r.name == s);
let outputFromString = (s: string) =>
switch (s) { switch (s) {
| "donations" => DONATIONS | "donations" => DONATIONS
| _ => PAYOUTS | _ => PAYOUTS
}; };
let run = (p: Prop.Combo.t) => { let run = (p: Prop.Combo.t) => {
let get = Prop.ValueMap.get(p.inputValues); switch (Prop.Combo.InputValues.toValueArray(p)) {
switch ( | [|
get("Fund"),
get("Day"),
get(Prop.TypeWithMetadata.currentYear.id),
get("Output"),
) {
| (
Some(SelectSingle(fund)), Some(SelectSingle(fund)),
Some(DateTime(intendedYear)), Some(DateTime(intendedYear)),
Some(DateTime(currentYear)), Some(DateTime(currentYear)),
Some(SelectSingle(output)), Some(SelectSingle(output)),
) => |] =>
Some( choiceFromString(fund)
|> E.O.fmap(fund =>
Model.make( Model.make(
convertChoice(fund), fund.group,
intendedYear, intendedYear,
currentYear, currentYear,
convertOutput(output), outputFromString(output),
), )
) )
| _ => None | _ => None
}; };
@ -164,22 +158,21 @@ module Interface = {
author: "Ozzie Gooen", author: "Ozzie Gooen",
inputTypes: [| inputTypes: [|
TypeWithMetadata.make( TypeWithMetadata.make(
~name="Fund", ~name=fundKey,
~type_= ~type_=
SelectSingle({ SelectSingle({
default: Some("total"), default: Some(Array.unsafe_get(Data.funds, 0).name),
options: [ options:
{name: "Animal Welfare Fund", id: "animal"}, Data.funds
{name: "Global Health Fund", id: "globalHealth"}, |> E.A.fmap((r) =>
{name: "Long Term Future Fund", id: "longTerm"}, ({name: r.name, id: r.name}: Prop.Type.selectOption)
{name: "Meta Fund", id: "longterm"}, )
{name: "All", id: "all"}, |> Array.to_list,
],
}), }),
(), (),
), ),
TypeWithMetadata.make( TypeWithMetadata.make(
~name="Day", ~name=dayKey,
~type_= ~type_=
DateTime({ DateTime({
default: default:
@ -208,7 +201,7 @@ module Interface = {
), ),
TypeWithMetadata.currentYear, TypeWithMetadata.currentYear,
TypeWithMetadata.make( TypeWithMetadata.make(
~name="Output", ~name=outputKey,
~type_= ~type_=
SelectSingle({ SelectSingle({
default: Some("Output"), default: Some("Output"),