prefs: use sync.pike to discern if OTAs enabled

Also, remove the conditional rendering logic for AppPrefs. With the new logic (and before this change) if the User disables OTAs, the toggle would disappear, which feels like an antipattern.
This commit is contained in:
tomholford 2022-11-07 17:52:13 -08:00
parent d99dc3e3ab
commit 2887008487
2 changed files with 10 additions and 15 deletions

View File

@ -10,8 +10,7 @@ export const AppPrefs = ({ match }: RouteComponentProps<{ desk: string }>) => {
const { desk } = match.params; const { desk } = match.params;
const charge = useCharge(desk); const charge = useCharge(desk);
const pike = usePike(desk); const pike = usePike(desk);
const tracking = !!pike?.sync; const otasEnabled = !!pike?.sync;
const otasEnabled = pike?.zest === 'live';
const otaSource = pike?.sync?.ship; const otaSource = pike?.sync?.ship;
const toggleOTAs = useKilnState((s) => s.toggleOTAs); const toggleOTAs = useKilnState((s) => s.toggleOTAs);
@ -21,18 +20,14 @@ export const AppPrefs = ({ match }: RouteComponentProps<{ desk: string }>) => {
<> <>
<h2 className="h3 mb-7">{getAppName(charge)} Settings</h2> <h2 className="h3 mb-7">{getAppName(charge)} Settings</h2>
<div className="space-y-3"> <div className="space-y-3">
{tracking ? ( <Setting on={otasEnabled} toggle={toggleUpdates} name="Automatic Updates">
<Setting on={otasEnabled} toggle={toggleUpdates} name="Automatic Updates"> <p>Automatically download and apply updates to keep {getAppName(charge)} up to date.</p>
<p>Automatically download and apply updates to keep {getAppName(charge)} up to date.</p> {otaSource && (
{otaSource && ( <p>
<p> OTA Source: <ShipName name={otaSource} className="font-semibold font-mono" />
OTA Source: <ShipName name={otaSource} className="font-semibold font-mono" /> </p>
</p> )}
)} </Setting>
</Setting>
) : (
<h4 className="text-gray-500">No settings</h4>
)}
</div> </div>
</> </>
); );

View File

@ -12,7 +12,7 @@ export const SystemUpdatePrefs = () => {
_.pick(s, ['toggleOTAs', 'changeOTASource']) _.pick(s, ['toggleOTAs', 'changeOTASource'])
); );
const pike = usePike('base'); const pike = usePike('base');
const otasEnabled = pike?.zest === 'live'; const otasEnabled = !!pike?.sync;
const otaSource = pike?.sync?.ship; const otaSource = pike?.sync?.ship;
const toggleBase = useCallback((on: boolean) => toggleOTAs('base', on), [toggleOTAs]); const toggleBase = useCallback((on: boolean) => toggleOTAs('base', on), [toggleOTAs]);