Skip to content

Commit

Permalink
fix(ui): Only check for provisioning once
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Nov 20, 2021
1 parent a6f6ded commit 6bd0480
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions frontend/src/RouterChoice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import AppRouter from "./AppRouter";
import ProvisioningPage from "./ProvisioningPage";

//This is either just an artifact of how React works or I'm doing something wrong
const RouterChoiceStageTwo: React.FunctionComponent<{ paletteMode: PaletteMode, setPaletteMode: (newMode: PaletteMode) => void }> = ({
const RouterChoiceStageTwo: React.FunctionComponent<{
paletteMode: PaletteMode,
setPaletteMode: (newMode: PaletteMode) => void,
setBypassProvisioning: (bypassProvisioning: boolean) => void
}> = ({
paletteMode,
setPaletteMode
setPaletteMode,
setBypassProvisioning
}): JSX.Element => {
const {
data: wifiConfiguration,
Expand All @@ -19,32 +24,41 @@ const RouterChoiceStageTwo: React.FunctionComponent<{ paletteMode: PaletteMode,
return <CircularProgress/>;
}

if (wifiConfiguration && wifiConfiguration.details?.state === "not_connected") {
return <ProvisioningPage/>;
if (wifiConfiguration) {
if (wifiConfiguration.details?.state === "not_connected") {
return <ProvisioningPage/>;
} else if (wifiConfiguration.details?.state === "connected") {
//This skips rendering any of this next time the wifiConfiguration is refreshed
setBypassProvisioning(true);
}
}

return (
<AppRouter paletteMode={paletteMode} setPaletteMode={setPaletteMode}/>
);
};

const RouterChoice: React.FunctionComponent<{ paletteMode: PaletteMode, setPaletteMode: (newMode: PaletteMode) => void }> = ({
const RouterChoice: React.FunctionComponent<{
paletteMode: PaletteMode,
setPaletteMode: (newMode: PaletteMode) => void
}> = ({
paletteMode,
setPaletteMode
}): JSX.Element => {
const [bypassProvisioning, setBypassProvisioning] = React.useState(false);
const [wifiConfigSupported] = useCapabilitiesSupported(Capability.WifiConfiguration);
const {
data: valetudoInformation,
isLoading: valetudoInformationLoading
} = useValetudoInformationQuery();

if (wifiConfigSupported) {
if (!bypassProvisioning && wifiConfigSupported) {
if (valetudoInformationLoading) {
return <CircularProgress/>;
}

if (valetudoInformation && valetudoInformation.embedded) {
return <RouterChoiceStageTwo paletteMode={paletteMode} setPaletteMode={setPaletteMode}/>;
return <RouterChoiceStageTwo paletteMode={paletteMode} setPaletteMode={setPaletteMode} setBypassProvisioning={setBypassProvisioning}/>;
}
}

Expand Down

0 comments on commit 6bd0480

Please sign in to comment.