chore: make SessionSettingsView a functional component

pull/3059/head
Audric Ackermann 1 year ago
parent 452d48b36e
commit f5deb69df9

@ -1,8 +1,9 @@
import autoBind from 'auto-bind';
import { shell } from 'electron'; import { shell } from 'electron';
import React from 'react'; import React, { useState } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { useDispatch } from 'react-redux';
import useMount from 'react-use/lib/useMount';
import { SettingsHeader } from './SessionSettingsHeader'; import { SettingsHeader } from './SessionSettingsHeader';
import { SessionIconButton } from '../icon'; import { SessionIconButton } from '../icon';
@ -151,59 +152,48 @@ const StyledSettingsList = styled.div`
flex-direction: column; flex-direction: column;
`; `;
export class SessionSettingsView extends React.Component< export const SessionSettingsView = (props: SettingsViewProps) => {
SettingsViewProps, const { category } = props;
{ hasPassword: boolean } const dispatch = useDispatch();
> {
public settingsViewRef: React.RefObject<HTMLDivElement>;
public constructor(props: any) {
super(props);
this.settingsViewRef = React.createRef();
autoBind(this);
this.state = { hasPassword: true };
const [hasPassword, setHasPassword] = useState(true);
useMount(() => {
let isMounted = true;
// eslint-disable-next-line more/no-then // eslint-disable-next-line more/no-then
void Data.getPasswordHash().then(hash => { void Data.getPasswordHash().then(hash => {
this.setState({ if (isMounted) {
hasPassword: !!hash, setHasPassword(!!hash);
}); }
}); });
} return () => {
isMounted = false;
public render() { };
const { category } = this.props; });
return (
<div className="session-settings">
<SettingsHeader category={category} />
<StyledSettingsView>
<StyledSettingsList ref={this.settingsViewRef}>
<SettingInCategory
category={category}
onPasswordUpdated={this.onPasswordUpdated}
hasPassword={this.state.hasPassword}
/>
</StyledSettingsList>
<SessionInfo />
</StyledSettingsView>
</div>
);
}
public onPasswordUpdated(action: string) { function onPasswordUpdated(action: string) {
if (action === 'set' || action === 'change') { if (action === 'set' || action === 'change') {
this.setState({ setHasPassword(true);
hasPassword: true, dispatch(showLeftPaneSection(SectionType.Message));
});
window.inboxStore?.dispatch(showLeftPaneSection(SectionType.Message));
} }
if (action === 'remove') { if (action === 'remove') {
this.setState({ setHasPassword(false);
hasPassword: false,
});
} }
} }
}
return (
<div className="session-settings">
<SettingsHeader category={category} />
<StyledSettingsView>
<StyledSettingsList>
<SettingInCategory
category={category}
onPasswordUpdated={onPasswordUpdated}
hasPassword={hasPassword}
/>
</StyledSettingsList>
<SessionInfo />
</StyledSettingsView>
</div>
);
};

Loading…
Cancel
Save