grid: SystemNotifications consumes pike

This commit is contained in:
tomholford 2022-11-03 23:21:04 -07:00
parent b23293228d
commit 5eaed93868
2 changed files with 8 additions and 12 deletions

View File

@ -1,27 +1,23 @@
import { kilnBump, Vat } from '@urbit/api';
import { kilnBump, Pike } from '@urbit/api';
import { partition, pick } from 'lodash';
import { useCallback } from 'react';
import { useHistory } from 'react-router-dom';
import api from '../state/api';
import { useCharges } from '../state/docket';
import useKilnState, { useVat } from '../state/kiln';
import useKilnState, { usePike } from '../../state/kiln';
export function vatIsBlocked(newKelvin: number | undefined, vat: Vat) {
if (!newKelvin) {
return false;
}
return !(vat.arak?.rail?.next || []).find(({ weft }) => weft.kelvin === newKelvin);
function pikeIsBlocked(newKelvin: number, pike: Pike) {
return !pike.wefts?.find(({ kelvin }) => kelvin === newKelvin);
}
export function useSystemUpdate() {
const { push } = useHistory();
const base = useVat('base');
const basePike = usePike('base');
const update = base?.arak?.rail?.next?.[0];
const newKelvin = update?.weft?.kelvin;
const newKelvin = basePike?.wefts[0]?.kelvin ?? 418;
const charges = useCharges();
const [blocked] = useKilnState((s) => {
const [b, u] = partition(Object.entries(s.vats), ([, vat]) => vatIsBlocked(newKelvin, vat));
const [b, u] = partition(Object.entries(s.pikes), ([, pike]) => pikeIsBlocked(newKelvin, pike));
return [b.map(([d]) => d), u.map(([d]) => d)] as const;
});

View File

@ -3,7 +3,7 @@ import { RouteComponentProps } from 'react-router-dom';
import { Setting } from '../components/Setting';
import { ShipName } from '../components/ShipName';
import { useCharge } from '../state/docket';
import useKilnState, { usePike, useVat } from '../../state/kiln';
import useKilnState, { usePike } from '../../state/kiln';
import { getAppName } from '../state/util';
export const AppPrefs = ({ match }: RouteComponentProps<{ desk: string }>) => {