From a04bc0d225e8aced0a26d9db9cf94dce192bdfcb Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 2 Mar 2021 15:25:38 +1100 Subject: [PATCH] center notification icon on settings and make label clickable --- stylesheets/_session.scss | 11 +-- ts/components/session/SessionRadio.tsx | 72 ++++++--------- ts/components/session/SessionRadioGroup.tsx | 89 ++++++++----------- .../settings/SessionSettingListItem.tsx | 6 +- .../session/settings/SessionSettings.tsx | 21 ++--- 5 files changed, 82 insertions(+), 117 deletions(-) diff --git a/stylesheets/_session.scss b/stylesheets/_session.scss index ba6ea5d30..d3946e819 100644 --- a/stylesheets/_session.scss +++ b/stylesheets/_session.scss @@ -1086,23 +1086,18 @@ label { border: none; margin-inline-start: $session-margin-sm; margin-top: $session-margin-sm; - - .session-radio { - padding: $session-margin-xs 0px; - } } -.session-radio { +.session-radio-group fieldset { input[type='radio'] { - border: 0; opacity: 0; - padding: 0; position: absolute; cursor: pointer; } label { margin-inline-end: 1em; + cursor: pointer; } label:before { @@ -1112,7 +1107,7 @@ label { height: 0.5em; margin-inline-end: 0.8em; border-radius: 100%; - vertical-align: -3px; + vertical-align: 0px; border: 2px solid rgba($session-color-white, 0.6); padding: 0.2em; @include themify($themes) { diff --git a/ts/components/session/SessionRadio.tsx b/ts/components/session/SessionRadio.tsx index 9e6c69814..0753833dd 100644 --- a/ts/components/session/SessionRadio.tsx +++ b/ts/components/session/SessionRadio.tsx @@ -1,58 +1,40 @@ import React from 'react'; +import { Flex } from './Flex'; +// tslint:disable: react-unused-props-and-state interface Props { label: string; value: string; active: boolean; group?: string; - onClick: any; + onClick: (value: string) => any; } -interface State { - active: boolean; -} - -export class SessionRadio extends React.PureComponent { - public static defaultProps = { - onClick: () => null, - }; +export const SessionRadio = (props: Props) => { + const { label, group, value, active, onClick } = props; - constructor(props: any) { - super(props); - this.clickHandler = this.clickHandler.bind(this); + function clickHandler(e: any) { + e.stopPropagation(); + console.warn(`SessionRadio clickHandler ${value}`); - this.state = { - active: this.props.active, - }; + onClick(value); } - public render() { - const active = this.state.active; - const { label, group, value } = this.props; - - return ( -
- - -
- ); - } - - private clickHandler(e: any) { - if (this.props.onClick) { - e.stopPropagation(); - this.props.onClick(); - - this.setState({ - active: !this.state.active, - }); - } - } -} + console.warn(`isactive ${value}: ${active}`); + + return ( + + + + + ); +}; diff --git a/ts/components/session/SessionRadioGroup.tsx b/ts/components/session/SessionRadioGroup.tsx index fba60a4f5..3708a491c 100644 --- a/ts/components/session/SessionRadioGroup.tsx +++ b/ts/components/session/SessionRadioGroup.tsx @@ -1,60 +1,45 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { SessionRadio } from './SessionRadio'; interface Props { - initalItem: string; + // tslint:disable: react-unused-props-and-state + initialItem: string; items: Array; group: string; - onClick?: any; + onClick: (selectedValue: string) => any; } -interface State { - activeItem: string; -} - -export class SessionRadioGroup extends React.PureComponent { - public static defaultProps = { - onClick: () => null, - }; - - constructor(props: any) { - super(props); - this.clickHandler = this.clickHandler.bind(this); - - this.state = { - activeItem: this.props.initalItem, - }; - } - - public render() { - const { items, group } = this.props; - - return ( -
-
- {items.map(item => { - const itemIsActive = item.value === this.state.activeItem; - - return ( - - ); - })} -
-
- ); - } - - private clickHandler() { - if (this.props.onClick) { - this.props.onClick(); - } - } -} +export const SessionRadioGroup = (props: Props) => { + const [activeItem, setActiveItem] = useState(''); + const { items, group, initialItem } = props; + + useEffect(() => { + console.warn('unMNount:', initialItem); + setActiveItem(initialItem); + }, []); + + return ( +
+
+ {items.map(item => { + const itemIsActive = item.value === activeItem; + + return ( + { + setActiveItem(value); + props.onClick(value); + }} + /> + ); + })} +
+
+ ); +}; diff --git a/ts/components/session/settings/SessionSettingListItem.tsx b/ts/components/session/settings/SessionSettingListItem.tsx index ceb8e1629..a5b3218ca 100644 --- a/ts/components/session/settings/SessionSettingListItem.tsx +++ b/ts/components/session/settings/SessionSettingListItem.tsx @@ -80,10 +80,12 @@ export class SessionSettingListItem extends React.Component { {type === SessionSettingType.Options && ( { + this.props.onClick(selectedRadioValue); + }} /> )} diff --git a/ts/components/session/settings/SessionSettings.tsx b/ts/components/session/settings/SessionSettings.tsx index 6a9cee972..59be7476e 100644 --- a/ts/components/session/settings/SessionSettings.tsx +++ b/ts/components/session/settings/SessionSettings.tsx @@ -139,8 +139,8 @@ class SettingsViewInner extends React.Component { const onClickFn = setting.onClick || - (() => { - this.updateSetting(setting); + ((value?: string) => { + this.updateSetting(setting, value); }); return ( @@ -263,10 +263,7 @@ class SettingsViewInner extends React.Component { ); } - public setOptionsSetting(settingID: string) { - const selectedValue = jQuery( - `#${settingID} .session-radio input:checked` - ).val(); + public setOptionsSetting(settingID: string, selectedValue: string) { window.setSettingValue(settingID, selectedValue); } @@ -278,12 +275,16 @@ class SettingsViewInner extends React.Component { }); } - public updateSetting(item: any) { + public updateSetting(item: any, value?: string) { // If there's a custom afterClick function, // execute it instead of automatically updating settings if (item.setFn) { - item.setFn(); + if (value) { + item.setFn(value); + } else { + item.setFn(); + } } else { if (item.type === SessionSettingType.Toggle) { // If no custom afterClick function given, alter values in storage here @@ -382,8 +383,8 @@ class SettingsViewInner extends React.Component { description: undefined, hidden: undefined, onClick: undefined, - setFn: () => { - this.setOptionsSetting('notification-setting'); + setFn: (selectedValue: string) => { + this.setOptionsSetting('notification-setting', selectedValue); }, content: { options: {