;
public constructor(props: any) {
super(props);
this.state = {
hasPassword: null,
shouldLockSettings: true,
};
this.settingsViewRef = React.createRef();
autoBind(this);
void Data.getPasswordHash().then(hash => {
this.setState({
hasPassword: !!hash,
});
});
}
public componentDidUpdate(_: SettingsViewProps, _prevState: State) {
const oldShouldRenderPasswordLock = _prevState.shouldLockSettings && _prevState.hasPassword;
const newShouldRenderPasswordLock = this.state.shouldLockSettings && this.state.hasPassword;
if (
newShouldRenderPasswordLock &&
newShouldRenderPasswordLock !== oldShouldRenderPasswordLock
) {
displayPasswordModal('enter', action => {
if (action === 'enter') {
// Unlocked settings
this.setState({
shouldLockSettings: false,
});
}
});
}
}
public render() {
const { category } = this.props;
const shouldRenderPasswordLock = this.state.shouldLockSettings && this.state.hasPassword;
return (
{shouldRenderPasswordLock ? (
<>>
) : (
<>
>
)}
);
}
public onPasswordUpdated(action: string) {
if (action === 'set' || action === 'change') {
this.setState({
hasPassword: true,
shouldLockSettings: true,
});
}
if (action === 'remove') {
this.setState({
hasPassword: false,
});
}
}
}