Skip to content

Commit

Permalink
chill; tweaks; data
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-whitaker committed Dec 15, 2024
1 parent 7e89192 commit e313e20
Show file tree
Hide file tree
Showing 36 changed files with 377 additions and 94 deletions.
1 change: 0 additions & 1 deletion packages/app/src/model/yeast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ export default interface Yeast {
name: string;
avg_attn: Scalar;
temp: Scalar;
starter: boolean;
}
12 changes: 8 additions & 4 deletions packages/app/src/screen/planning/grains.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kbGrainsState, {useKbGrains} from "@/state/kbGrains";
import DataGridInput from "@/component/data-grid/input";
import AddRow from "@/component/data-grid/add-row";
import useIndexBy from "@/hooks/useIndexBy";
import sessionState, {useSession} from "@/state/session";
import sessionState, {Session, useSession} from "@/state/session";
import Collapse from "@/component/collapse";

export type PlanningGrainsProps = {
Expand All @@ -21,11 +21,15 @@ export type PlanningGrainsProps = {
remove: RemoveFn;
update: UpdateFn;
updateScalar: UpdateScalarFn;
session: Session;
}
export default function PlanningGrains({ grains, add, remove, update, updateScalar }: PlanningGrainsProps) {
export default function PlanningGrains({ grains, add, remove, update, updateScalar, session }: PlanningGrainsProps) {
const kbGrains = useKbGrains();
const kbGrainsIndex = useIndexBy(kbGrains, "name");
const session = useSession();

if (!kbGrains || !kbGrainsIndex) {
return null;
}

return (
<>
Expand All @@ -42,7 +46,7 @@ export default function PlanningGrains({ grains, add, remove, update, updateScal
<DataGridLabel className="ml-6">
<DataGridRemoveButton onClick={() => remove("grains", i)} />
<DataGridSelect
data={grains.map((({ name }) => ({ value: name, name })))}
data={kbGrains.map((({ name }) => ({ value: name, name })))}
value={grain.name}
onChange={(value: string) => update(`grains[${i}]`, kbGrainsState.kbToState(kbGrainsIndex!.get(value)!))}
/>
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/screen/planning/hops.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import DataGridInput from "@/component/data-grid/input";
import AddRow from "@/component/data-grid/add-row";
import useIndexBy from "@/hooks/useIndexBy";
import {AddFn, RemoveFn, UpdateFn, UpdateScalarFn} from "@/hooks/useJsonEdit";
import sessionState, {useSession} from "@/state/session";
import sessionState, {Session, useSession} from "@/state/session";
import Collapse from "@/component/collapse";

export type PlanningHopsProps = {
Expand All @@ -21,11 +21,11 @@ export type PlanningHopsProps = {
remove: RemoveFn;
update: UpdateFn;
updateScalar: UpdateScalarFn;
session: Session;
}
export default function PlanningHops({ hops, add, remove, update, updateScalar }: PlanningHopsProps) {
export default function PlanningHops({ hops, add, remove, update, updateScalar, session }: PlanningHopsProps) {
const kbHops = useKbHops();
const kbHopsIndex = useIndexBy(kbHops, "name");
const session = useSession();

if (!kbHops || !kbHopsIndex) {
return null;
Expand Down
40 changes: 26 additions & 14 deletions packages/app/src/screen/planning/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import {ScreenH1, ScreenH2, ScreenH3, ScreenP, InputDate} from "@brewdocs.beer/design";
import Batch from "@/model/batch";
import Recipe from "@/model/recipe";
import {Fragment} from "react";

import useJsonEdit from "@/hooks/useJsonEdit";
import ScreenTwoCol from "@/component/screen/two-col";
Expand All @@ -15,26 +14,18 @@ import useIndexBy from "@/hooks/useIndexBy";
import PlanningHops from "@/screen/planning/hops";
import PlanningYeast from "@/screen/planning/yeast";
import PlanningGrains from "@/screen/planning/grains";
import {useSession} from "@/state/session";

export type PlanningProps = {
batch: Batch;
recipe: Recipe;
onChange: (batch: Batch) => void
}
export default function Planning({ batch, recipe, onChange }: PlanningProps) {
const hops = useKbHops();
const hopsIndex = useIndexBy(hops, "name");
const yeasts = useKbYeasts();
const yeastsIndex = useIndexBy(yeasts, "name");
const grains = useKbGrains();
const grainsIndex = useIndexBy(grains, "name");
const session = useSession();

const [data, update, updateScalar,, add, remove] = useJsonEdit<Batch>(batch, onChange);

if (!hops || !hopsIndex || !yeasts || !yeastsIndex || !grains || !grainsIndex) {
return null;
}

return (
<>
<Screen>
Expand All @@ -56,11 +47,32 @@ export default function Planning({ batch, recipe, onChange }: PlanningProps) {
</Screen>
<ScreenTwoCol>
<div>
<PlanningGrains grains={data.grains} add={add} remove={remove} update={update} updateScalar={updateScalar} />
<PlanningHops hops={data.hops} add={add} remove={remove} update={update} updateScalar={updateScalar} />
<PlanningGrains
grains={data.grains}
add={add}
remove={remove}
update={update}
updateScalar={updateScalar}
session={session}
/>
<PlanningHops
hops={data.hops}
add={add}
remove={remove}
update={update}
updateScalar={updateScalar}
session={session}
/>
</div>
<div>
<PlanningYeast yeast={data.yeast} add={add} remove={remove} update={update} updateScalar={updateScalar} />
<PlanningYeast
yeast={data.yeast}
add={add}
remove={remove}
update={update}
updateScalar={updateScalar}
session={session}
/>
</div>
</ScreenTwoCol>
</>
Expand Down
8 changes: 4 additions & 4 deletions packages/app/src/screen/planning/yeast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kbYeastsState, {useKbYeasts} from "@/state/kbYeasts";
import DataGridInput from "@/component/data-grid/input";
import AddRow from "@/component/data-grid/add-row";
import useIndexBy from "@/hooks/useIndexBy";
import sessionState, {useSession} from "@/state/session";
import sessionState, {Session, useSession} from "@/state/session";
import Collapse from "@/component/collapse";

export type PlanningYeastProps = {
Expand All @@ -21,11 +21,11 @@ export type PlanningYeastProps = {
remove: RemoveFn;
update: UpdateFn;
updateScalar: UpdateScalarFn;
session: Session;
}
export default function PlanningYeast({ yeast, add, remove, update, updateScalar }: PlanningYeastProps) {
export default function PlanningYeast({ yeast, add, remove, update, updateScalar, session }: PlanningYeastProps) {
const kbYeasts = useKbYeasts();
const kbYeastsIndex = useIndexBy(kbYeasts, "name");
const session = useSession();

if (!kbYeasts || !kbYeastsIndex) {
return null;
Expand All @@ -48,7 +48,7 @@ export default function PlanningYeast({ yeast, add, remove, update, updateScalar
<DataGridSelect
data={kbYeasts.map((({ name }) => ({ value: name, name })))}
value={yeast.name}
onChange={(value: string) => update(`yeasts[${i}]`, kbYeastsState.kbToState(kbYeastsIndex!.get(value)!))}
onChange={(value: string) => update(`yeast[${i}]`, kbYeastsState.kbToState(kbYeastsIndex!.get(value)!))}
/>
</DataGridLabel>
<DataGridInput
Expand Down
73 changes: 73 additions & 0 deletions packages/app/src/screen/schedule/boil.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {ScreenH3, ScreenH4} from "@brewdocs.beer/design";
import {Fragment} from "react";
import DataGrid from "@/component/data-grid";
import Hop from "@/model/hop";
import DataGridRow from "@/component/data-grid/row";
import DataGridLabel from "@/component/data-grid/label";
import DataGridLabelNote from "@/component/data-grid/label-note";
import DataGridInput from "@/component/data-grid/input";
import Additive from "@/model/additive";
import Boil from "@/model/boil";
import {UpdateFn, UpdateScalarFn} from "@/hooks/useJsonEdit";
import sessionState, {useSession} from "@/state/session";
import Collapse from "@/component/collapse";

export type ScheduleBoilTypes = {
boil: Boil[];
hops: Hop[];
additives: Additive[];
update: UpdateFn;
updateScalar: UpdateScalarFn;
}
export default function ScheduleBoil({ boil, hops, additives, update, updateScalar }: ScheduleBoilTypes) {
const session = useSession();

return (
<>
<Collapse
toggle={(open: boolean) => sessionState.set(`schedule.boil`, open)}
key={"boil"}
title={"2. Boil"}
className="lg:collapse-open"
openInitial={session[`schedule.boil`] ?? true}>
{boil.map((m, i) => (
<Fragment key={`boil-${m.name}-${i}`}>
<ScreenH4 className="cozy">{m.name} - {m.time.value}</ScreenH4>
<DataGrid>
{hops.map((hop: Hop, i) => (
<DataGridRow key={`hop-${hop.name}-${i}`}>
<DataGridLabel>{hop.name} <DataGridLabelNote>({hop.alpha.value})</DataGridLabelNote></DataGridLabel>
<DataGridInput readonly value={hop.weight.value} col={2} />
<DataGridInput
col={3}
value={hop.boil.value}
onChange={(value: string) => update(`hops[${i}].boil`, value)}
onBlur={(value: string) => updateScalar(`hops[${i}].boil`, value)}
/>
</DataGridRow>
))}
</DataGrid>
</Fragment>
))}
{additives.length ? (
<Fragment>
<ScreenH4>Additives</ScreenH4>
<DataGrid>
{additives.map((additive: Additive, i) => (
<DataGridRow key={`additive-${additive.name}-${i}`}>
<DataGridLabel>{additive.name}</DataGridLabel>
<DataGridInput
col={3}
value={additive.boil.value}
onChange={(value: string) => update(`additives[${i}].scalar`, value)}
onBlur={(value: string) => updateScalar(`additives[${i}].scalar`, value)}
/>
</DataGridRow>
))}
</DataGrid>
</Fragment>
) : <></>}
</Collapse>
</>
);
}
18 changes: 18 additions & 0 deletions packages/app/src/screen/schedule/chill.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sessionState, {useSession} from "@/state/session";
import Collapse from "@/component/collapse";

export default function ScheduleChill() {
const session = useSession();
return (
<Collapse
toggle={(open: boolean) => sessionState.set(`schedule.chill`, open)}
key={"chill"}
title={"3. Chill"}
className="lg:collapse-open"
openInitial={session[`schedule.chill`] ?? true}>
<p>
It is critical you chill your wort as quickly as possible. Cool you wort to 60°F to 72°F, depending on what your beer style calls for.
</p>
</Collapse>
)
}
77 changes: 9 additions & 68 deletions packages/app/src/screen/schedule/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import {Fragment} from "react";
import Additive from "@/model/additive";
import ScreenTwoCol from "@/component/screen/two-col";
import DataGridLabelNote from "@/component/data-grid/label-note";
import ScheduleMash from "@/screen/schedule/mash";
import ScheduleBoil from "@/screen/schedule/boil";
import SchedulePitch from "@/screen/schedule/pitch";
import ScheduleChill from "@/screen/schedule/chill";

export type BrewDayProps = { batch: Batch, onChange: (batch: Batch) => void; };
export default function BrewDay({ batch, onChange }: BrewDayProps) {
Expand All @@ -25,75 +29,12 @@ export default function BrewDay({ batch, onChange }: BrewDayProps) {
<ScreenTwoCol>
<ScreenH1 className="col-start-1 lg:col-span-2 col-span-1 mb-2">Brew Schedule</ScreenH1>
<div>
<ScreenH3 className="cozy">1. Mash</ScreenH3>
{data.mash.map((m, i) => (
<Fragment key={`mash-${m.name}-${i}`}>
<ScreenH4>{m.name} - {m.time.value}</ScreenH4>
<DataGrid>
{data.grains.map((grain: Grain, i) => (
<DataGridRow key={`grain-${grain.name}-${i}`}>
<DataGridLabel>{grain.name} <DataGridLabelNote>({grain.weight.value})</DataGridLabelNote></DataGridLabel>
<DataGridInput readonly value={m.temp.value} col={3} />
</DataGridRow>
))}
</DataGrid>
</Fragment>
))}

<ScreenH3>2. Boil</ScreenH3>
{data.boil.map((m, i) => (
<Fragment key={`boil-${m.name}-${i}`}>
<ScreenH4>{m.name} - {m.time.value}</ScreenH4>
<DataGrid>
{data.hops.map((hop: Hop, i) => (
<DataGridRow key={`hop-${hop.name}-${i}`}>
<DataGridLabel>{hop.name} <DataGridLabelNote>({hop.alpha.value})</DataGridLabelNote></DataGridLabel>
<DataGridInput readonly value={hop.weight.value} col={2} />
<DataGridInput
col={3}
value={hop.boil.value}
onChange={(value: string) => update(`hops[${i}].boil`, value)}
onBlur={(value: string) => updateScalar(`hops[${i}].boil`, value)}
/>
</DataGridRow>
))}
</DataGrid>
</Fragment>
))}
{data.additives.length ? (
<Fragment>
<ScreenH4>Additives</ScreenH4>
<DataGrid>
{data.additives.map((additive: Additive, i) => (
<DataGridRow key={`additive-${additive.name}-${i}`}>
<DataGridLabel>{additive.name}</DataGridLabel>
<DataGridInput
col={3}
value={additive.boil.value}
onChange={(value: string) => update(`additives[${i}].scalar`, value)}
onBlur={(value: string) => updateScalar(`additives[${i}].scalar`, value)}
/>
</DataGridRow>
))}
</DataGrid>
</Fragment>
) : <></>}
<ScheduleMash grains={data.grains} mash={data.mash} />
<ScheduleBoil boil={data.boil} hops={data.hops} additives={data.additives} update={update} updateScalar={updateScalar} />
</div>
<div>
<ScreenH3 className="lg:mt-0">3. Yeast</ScreenH3>
<DataGrid>
{data.yeast.map((yeast: Yeast, i) => (
<DataGridRow key={`yeast-${yeast.name}-${i}`}>
<DataGridLabel>{yeast.name}</DataGridLabel>
<DataGridInput
col={3}
value={yeast.temp.value}
onChange={(value: string) => update(`yeast[${i}].temp.value`, value)}
onBlur={(value: string) => updateScalar(`yeast[${i}].temp`, value)}
/>
</DataGridRow>
))}
</DataGrid>
<ScheduleChill />
<SchedulePitch yeast={data.yeast} update={update} updateScalar={updateScalar} />
</div>
</ScreenTwoCol>
<ScreenTwoCol>
Expand Down Expand Up @@ -121,7 +62,7 @@ export default function BrewDay({ batch, onChange }: BrewDayProps) {
))}
</DataGrid>
</div>
<div>dlkf</div>
<div></div>
</ScreenTwoCol>
</>
)
Expand Down
Loading

0 comments on commit e313e20

Please sign in to comment.