Skip to content

Commit

Permalink
Add endpoint to read firmware capabilities emsesp#1218
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Jul 11, 2023
1 parent 362d837 commit d92cd4e
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 164 deletions.
8 changes: 4 additions & 4 deletions interface/.typesafe-i18n.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"adapter": "react",
"baseLocale": "pl",
"$schema": "https://unpkg.com/[email protected].3/schema/typesafe-i18n.json"
}
"adapter": "react",
"baseLocale": "pl",
"$schema": "https://unpkg.com/[email protected].4/schema/typesafe-i18n.json"
}
6 changes: 3 additions & 3 deletions interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
"react-router-dom": "^6.14.1",
"react-toastify": "^9.1.3",
"sockette": "^2.0.6",
"typesafe-i18n": "^5.24.3",
"typesafe-i18n": "^5.24.4",
"typescript": "^5.1.6"
},
"devDependencies": {
"@types/mime-types": "^2",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-react-swc": "^3.3.2",
"eslint": "^8.44.0",
"eslint-config-airbnb": "^19.0.4",
Expand Down
5 changes: 4 additions & 1 deletion interface/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ToastContainer, Slide } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.min.css';

import { localStorageDetector } from 'typesafe-i18n/detectors';
import { FeaturesLoader } from './contexts/features';
import type { FC } from 'react';
import AppRouting from 'AppRouting';
import CustomTheme from 'CustomTheme';
Expand All @@ -26,7 +27,9 @@ const App: FC = () => {
return (
<TypesafeI18n locale={detectedLocale}>
<CustomTheme>
<AppRouting />
<FeaturesLoader>
<AppRouting />
</FeaturesLoader>
<ToastContainer
position="bottom-left"
autoClose={3000}
Expand Down
29 changes: 10 additions & 19 deletions interface/src/contexts/features/FeaturesLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,19 @@ import type { FC } from 'react';

import type { RequiredChildrenProps } from 'utils';
import * as FeaturesApi from 'api/features';
import { ApplicationError, LoadingSpinner } from 'components';

const FeaturesLoader: FC<RequiredChildrenProps> = (props) => {
const { data: features, error } = useRequest(FeaturesApi.readFeatures);
const { data: features } = useRequest(FeaturesApi.readFeatures);

if (features) {
return (
<FeaturesContext.Provider
value={{
features
}}
>
{props.children}
</FeaturesContext.Provider>
);
}

if (error) {
return <ApplicationError message={error?.message} />;
}

return <LoadingSpinner height="100vh" />;
return (
<FeaturesContext.Provider
value={{
features
}}
>
{props.children}
</FeaturesContext.Provider>
);
};

export default FeaturesLoader;
8 changes: 7 additions & 1 deletion interface/src/framework/mqtt/MqttSettingsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import CancelIcon from '@mui/icons-material/Cancel';
import WarningIcon from '@mui/icons-material/Warning';
import { Button, Checkbox, MenuItem, Grid, Typography, InputAdornment, TextField } from '@mui/material';
import { useState } from 'react';
import { useContext, useState } from 'react';
import { FeaturesContext } from '../../contexts/features';
import type { ValidateFieldsError } from 'async-validator';
import type { FC } from 'react';

Expand Down Expand Up @@ -39,6 +40,7 @@ const MqttSettingsForm: FC = () => {
});

const { LL } = useI18nContext();
const { features } = useContext(FeaturesContext);

const [fieldErrors, setFieldErrors] = useState<ValidateFieldsError>();

Expand Down Expand Up @@ -169,6 +171,10 @@ const MqttSettingsForm: FC = () => {
</TextField>
</Grid>
</Grid>

{/* TODO here */}
<div>{JSON.stringify(features, null, 2)}</div>

<BlockFormControlLabel
control={<Checkbox name="clean_session" checked={data.clean_session} onChange={updateFormValue} />}
label={LL.MQTT_CLEAN_SESSION()}
Expand Down
8 changes: 2 additions & 6 deletions interface/src/types/features.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
export interface Features {
project: boolean;
security: boolean;
mqtt: boolean;
ntp: boolean;
ota: boolean;
upload_firmware: boolean;
version: string;
platform: string; // "ESP32-C3" "ESP32-S2" "ESP32-S3" "ESP32"
}
Loading

0 comments on commit d92cd4e

Please sign in to comment.