Skip to content

Commit

Permalink
Adde welcome dialog: #208
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Dec 12, 2024
1 parent 0128f62 commit 295f972
Show file tree
Hide file tree
Showing 16 changed files with 681 additions and 180 deletions.
355 changes: 179 additions & 176 deletions io-package.json

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions src-admin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import BridgesTab from './Tabs/Bridges';
import ControllerTab from './Tabs/Controller';
import DevicesTab from './Tabs/Devices';
import OptionsTab from './Tabs/Options';
import WelcomeDialog from './components/WelcomeDialog';

import type {
CommissioningInfo,
Expand Down Expand Up @@ -94,12 +95,14 @@ interface AppState extends GenericAppState {
/** Undefined if no detection ran yet */
detectedDevices?: DetectedRoom[];
ready: boolean;
showWelcomeDialog: boolean;
progress: {
title?: ioBroker.StringOrTranslated;
text?: ioBroker.StringOrTranslated;
indeterminate?: boolean;
value?: number;
} | null;
welcomeDialogShowed: boolean;
}

class App extends GenericApp<GenericAppProps, AppState> {
Expand Down Expand Up @@ -156,6 +159,8 @@ class App extends GenericApp<GenericAppProps, AppState> {
},
ready: false,
progress: null,
showWelcomeDialog: false,
welcomeDialogShowed: false,
});

this.alert = window.alert;
Expand Down Expand Up @@ -254,6 +259,8 @@ class App extends GenericApp<GenericAppProps, AppState> {

const alive = await this.socket.getState(`system.adapter.matter.${this.instance}.alive`);

const welcomeDialog = await this.socket.getState(`matter.${this.instance}.welcomeDialog`);

if (alive?.val) {
this.refreshBackendSubscription(true);
}
Expand All @@ -263,6 +270,8 @@ class App extends GenericApp<GenericAppProps, AppState> {
commissioning,
ready: true,
alive: !!alive?.val,
showWelcomeDialog: !welcomeDialog?.val,
welcomeDialogShowed: !!welcomeDialog?.val,
});
}

Expand All @@ -279,6 +288,28 @@ class App extends GenericApp<GenericAppProps, AppState> {
}
};

renderWelcomeDialog(): React.JSX.Element | null {
if (!this.state.showWelcomeDialog) {
return null;
}

return (
<WelcomeDialog
common={this.common}
instance={this.instance}
socket={this.socket}
onClose={async () => {
if (!this.state.welcomeDialogShowed) {
await this.socket.setState(`matter.${this.instance}.welcomeDialog`, true, true);
}
this.setState({ showWelcomeDialog: false, welcomeDialogShowed: true });
}}
login={this.state.native.login}
pass={this.state.native.pass}
/>
);
}

onBackendUpdates = (update: GUIMessage | null): void => {
if (!update) {
return;
Expand Down Expand Up @@ -441,6 +472,7 @@ class App extends GenericApp<GenericAppProps, AppState> {
this.updateNativeValue(id, value, resolve);
});
}}
onShowWelcomeDialog={() => this.setState({ showWelcomeDialog: true })}
onLoad={(native: Record<string, any>) => this.onLoadConfig(native)}
socket={this.socket}
common={this.common}
Expand Down Expand Up @@ -626,6 +658,7 @@ class App extends GenericApp<GenericAppProps, AppState> {
<ThemeProvider theme={this.state.theme}>
{this.renderToast()}
{this.renderProgressDialog()}
{this.renderWelcomeDialog()}
<div
className="App"
style={{
Expand Down
57 changes: 54 additions & 3 deletions src-admin/src/Tabs/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ import {
DialogActions,
DialogContent,
DialogTitle,
Fab,
FormControl,
FormControlLabel,
FormControlLabel, IconButton,

Check failure on line 13 in src-admin/src/Tabs/Options.tsx

View workflow job for this annotation

GitHub Actions / check-and-lint

Insert `⏎···`

Check failure on line 13 in src-admin/src/Tabs/Options.tsx

View workflow job for this annotation

GitHub Actions / check-and-lint

Insert `⏎···`
InputLabel,
MenuItem,
Select,
TextField,
Tooltip,
Typography,
} from '@mui/material';

import { Check, Close, LayersClear } from '@mui/icons-material';
import {Check, Close, LayersClear, AutoAwesome, Clear, VisibilityOff, Visibility} from '@mui/icons-material';

Check failure on line 22 in src-admin/src/Tabs/Options.tsx

View workflow job for this annotation

GitHub Actions / check-and-lint

Replace `Check,·Close,·LayersClear,·AutoAwesome,·Clear,·VisibilityOff,·Visibility` with `·Check,·Close,·LayersClear,·AutoAwesome,·Clear,·VisibilityOff,·Visibility·`

Check failure on line 22 in src-admin/src/Tabs/Options.tsx

View workflow job for this annotation

GitHub Actions / check-and-lint

Replace `Check,·Close,·LayersClear,·AutoAwesome,·Clear,·VisibilityOff,·Visibility` with `·Check,·Close,·LayersClear,·AutoAwesome,·Clear,·VisibilityOff,·Visibility·`

import { type AdminConnection, I18n, Logo } from '@iobroker/adapter-react-v5';

Expand All @@ -34,6 +36,7 @@ const styles: Record<string, React.CSSProperties> = {
width: '100%',
display: 'flex',
flexDirection: 'column',
position: 'relative',
},
input: {
marginTop: 2,
Expand Down Expand Up @@ -74,6 +77,7 @@ interface OptionsProps {
onLoad: (native: Record<string, any>) => void;
/** The current matter config */
matter: MatterConfig;
onShowWelcomeDialog: () => void;
}

interface OptionsState {
Expand All @@ -83,6 +87,7 @@ interface OptionsState {
iotPassword: string;
iotInstance: string;
interfaces?: { value: string; address?: string; address6?: string }[];
passVisible?: boolean;
}

function cutIpV6(address: string, length?: number): string {
Expand Down Expand Up @@ -265,6 +270,22 @@ class Options extends Component<OptionsProps, OptionsState> {
return (
<div style={styles.panel}>
{this.renderConfirmDialog()}
<Tooltip
title={I18n.t('Show welcome dialog')}
slotProps={{ popper: { sx: { pointerEvents: 'none' } } }}
>
<Fab
size="small"
style={{
position: 'absolute',
top: 4,
left: 80,
}}
onClick={this.props.onShowWelcomeDialog}
>
<AutoAwesome />
</Fab>
</Tooltip>
<Logo
instance={this.props.instance}
common={this.props.common}
Expand Down Expand Up @@ -411,6 +432,21 @@ class Options extends Component<OptionsProps, OptionsState> {
type="text"
onChange={e => this.props.onChange('login', e.target.value)}
margin="normal"
slotProps={{
htmlInput: {
autocomplete: 'new-password',
},
input: {
endAdornment: this.props.native.login ? (
<IconButton
size="small"
onClick={() => this.props.onChange('login', '')}
>
<Clear />
</IconButton>
) : null,
},
}}
style={{ ...styles.input, marginRight: 16 }}
/>
<TextField
Expand All @@ -419,8 +455,23 @@ class Options extends Component<OptionsProps, OptionsState> {
error={!!passwordError}
autoComplete="current-password"
style={styles.input}
slotProps={{
htmlInput: {
autocomplete: 'new-password',
},
input: {
endAdornment: this.props.native.pass ? (
<IconButton
size="small"
onClick={() => this.setState({ passVisible: !this.state.passVisible })}
>
{this.state.passVisible ? <VisibilityOff /> : <Visibility />}
</IconButton>
) : null,
},
}}
value={this.props.native.pass}
type="password"
type={this.state.passVisible ? 'text' : 'password'}
helperText={passwordError || ''}
onChange={e => this.props.onChange('pass', e.target.value)}
margin="normal"
Expand Down
2 changes: 1 addition & 1 deletion src-admin/src/components/InfoBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Info, Warning, Close, Visibility, type SvgIconComponent } from '@mui/ic

interface InfoBoxProps {
/** Text to display in the info box */
children: string | string[] | React.JSX.Element | React.JSX.Element[];
children: string | (string | React.JSX.Element | null)[] | React.JSX.Element;
/** The type determines the color and symbol */
type: 'warning' | 'info' | 'error';
/** If the Box is closeable */
Expand Down
Loading

0 comments on commit 295f972

Please sign in to comment.