From a04204b3d52048f77d3457be2af9ac672325f69e Mon Sep 17 00:00:00 2001 From: Pavel Mineev Date: Sun, 8 Aug 2021 12:29:56 +0300 Subject: [PATCH] move sort picker below comment form --- .../auth-panel__select-label-value.css | 9 -- .../auth-panel__select-label.css | 10 -- .../__select/auth-panel__select.css | 10 -- .../app/components/auth-panel/auth-panel.tsx | 138 +----------------- frontend/app/components/auth-panel/index.ts | 3 - frontend/app/components/auth/auth.tsx | 20 +-- .../app/components/auth/components/button.tsx | 2 +- frontend/app/components/icons/arrow.tsx | 15 ++ .../root/__threads/root__threads.css | 2 +- frontend/app/components/root/root.module.css | 7 + frontend/app/components/root/root.tsx | 18 +-- frontend/app/components/select/index.ts | 1 + .../app/components/select/select.module.css | 30 ++++ frontend/app/components/select/select.tsx | 39 +++++ frontend/app/components/sort-picker/index.ts | 1 + .../sort-picker/sort-picker.module.css | 0 .../components/sort-picker/sort-picker.tsx | 90 ++++++++++++ frontend/app/store/comments/utils.ts | 8 +- 18 files changed, 199 insertions(+), 204 deletions(-) delete mode 100644 frontend/app/components/auth-panel/__select-label-value/auth-panel__select-label-value.css delete mode 100644 frontend/app/components/auth-panel/__select-label/auth-panel__select-label.css delete mode 100644 frontend/app/components/auth-panel/__select/auth-panel__select.css create mode 100644 frontend/app/components/icons/arrow.tsx create mode 100644 frontend/app/components/select/index.ts create mode 100644 frontend/app/components/select/select.module.css create mode 100644 frontend/app/components/select/select.tsx create mode 100644 frontend/app/components/sort-picker/index.ts create mode 100644 frontend/app/components/sort-picker/sort-picker.module.css create mode 100644 frontend/app/components/sort-picker/sort-picker.tsx diff --git a/frontend/app/components/auth-panel/__select-label-value/auth-panel__select-label-value.css b/frontend/app/components/auth-panel/__select-label-value/auth-panel__select-label-value.css deleted file mode 100644 index 1aa311c7..00000000 --- a/frontend/app/components/auth-panel/__select-label-value/auth-panel__select-label-value.css +++ /dev/null @@ -1,9 +0,0 @@ -.auth-panel__select-label-value_focused { - outline: 1px dotted; - outline-color: inherit; - - @supports (outline-color: -webkit-focus-ring-color) { - outline-color: -webkit-focus-ring-color; - outline-style: auto; - } -} diff --git a/frontend/app/components/auth-panel/__select-label/auth-panel__select-label.css b/frontend/app/components/auth-panel/__select-label/auth-panel__select-label.css deleted file mode 100644 index 429e39c5..00000000 --- a/frontend/app/components/auth-panel/__select-label/auth-panel__select-label.css +++ /dev/null @@ -1,10 +0,0 @@ -.auth-panel__select-label { - position: relative; - white-space: nowrap; - font-weight: 700; - - &::after { - content: '▾'; - margin-left: 2px; - } -} diff --git a/frontend/app/components/auth-panel/__select/auth-panel__select.css b/frontend/app/components/auth-panel/__select/auth-panel__select.css deleted file mode 100644 index cbc3e84d..00000000 --- a/frontend/app/components/auth-panel/__select/auth-panel__select.css +++ /dev/null @@ -1,10 +0,0 @@ -.auth-panel__select { - position: absolute; - left: 0; - top: 0; - right: 0; - bottom: 0; - opacity: 0; - cursor: pointer; - width: 100%; -} diff --git a/frontend/app/components/auth-panel/auth-panel.tsx b/frontend/app/components/auth-panel/auth-panel.tsx index 1cbd7718..205275e0 100644 --- a/frontend/app/components/auth-panel/auth-panel.tsx +++ b/frontend/app/components/auth-panel/auth-panel.tsx @@ -26,7 +26,6 @@ interface OwnProps { postInfo: PostInfo; signout(): Promise; - onSortChange(s: Sorting): Promise; onCommentsChangeReadOnlyMode(readOnly: boolean): Promise; onBlockedUsersShow(): void; onBlockedUsersHide(): void; @@ -35,34 +34,17 @@ interface OwnProps { export interface Props extends OwnProps { intl: IntlShape; theme: Theme; - sort: Sorting; } interface State { isBlockedVisible: boolean; anonymousUsernameInputValue: string; - sortSelectFocused: boolean; } class AuthPanelComponent extends Component { state = { isBlockedVisible: false, anonymousUsernameInputValue: 'anon', - sortSelectFocused: false, - }; - - onSortChange = (e: Event) => { - const { value } = e.target as HTMLOptionElement; - this.props.onSortChange(value as Sorting); - }; - - onSortFocus = () => { - this.setState({ sortSelectFocused: true }); - }; - - onSortBlur = (e: Event) => { - this.setState({ sortSelectFocused: false }); - this.onSortChange(e); }; toggleBlockedVisibility = () => { @@ -165,35 +147,6 @@ class AuthPanelComponent extends Component { ); }; - renderSort = () => { - const { sort } = this.props; - const { sortSelectFocused } = this.state; - const sortArray = getSortArray(sort, this.props.intl); - - return ( - - {' '} - - - {sortArray.find((x) => 'selected' in x && x.selected!)!.label} - - - - - ); - }; - render({ user, postInfo, theme }: Props, { isBlockedVisible }: State) { const { read_only } = postInfo; const isAdmin = user && user.admin; @@ -208,108 +161,21 @@ class AuthPanelComponent extends Component { {isSettingsLabelVisible && this.renderSettingsLabel()} {isSettingsLabelVisible && ' • '} {isAdmin && this.renderReadOnlySwitch()} - {isAdmin && ' • '} + {isAdmin && read_only && ' • '} {!isAdmin && read_only && ( )} - - {this.renderSort()} ); } } -const sortMessages = defineMessages({ - best: { - id: 'commentsSort.best', - defaultMessage: 'Best', - }, - worst: { - id: 'commentsSort.worst', - defaultMessage: 'Worst', - }, - newest: { - id: 'commentsSort.newest', - defaultMessage: 'Newest', - }, - oldest: { - id: 'commentsSort.oldest', - defaultMessage: 'Oldest', - }, - recentlyUpdated: { - id: 'commentsSort.recently-updated', - defaultMessage: 'Recently updated', - }, - leastRecentlyUpdated: { - id: 'commentsSort.least-recently-updated', - defaultMessage: 'Least recently updated', - }, - mostControversial: { - id: 'commentsSort.most-controversial', - defaultMessage: 'Most controversial', - }, - leastControversial: { - id: 'commentsSort.least-controversial', - defaultMessage: 'Least controversial', - }, -}); - -function getSortArray(currentSort: Sorting, intl: IntlShape) { - const sortArray: { - value: Sorting; - label: string; - selected?: boolean; - }[] = [ - { - value: '-score', - label: intl.formatMessage(sortMessages.best), - }, - { - value: '+score', - label: intl.formatMessage(sortMessages.worst), - }, - { - value: '-time', - label: intl.formatMessage(sortMessages.newest), - }, - { - value: '+time', - label: intl.formatMessage(sortMessages.oldest), - }, - { - value: '-active', - label: intl.formatMessage(sortMessages.recentlyUpdated), - }, - { - value: '+active', - label: intl.formatMessage(sortMessages.leastRecentlyUpdated), - }, - { - value: '-controversy', - label: intl.formatMessage(sortMessages.mostControversial), - }, - { - value: '+controversy', - label: intl.formatMessage(sortMessages.leastControversial), - }, - ]; - - return sortArray.map((sort) => { - if (sort.value === currentSort) { - sort.selected = true; - } - - return sort; - }); -} - export function AuthPanel(props: OwnProps) { const intl = useIntl(); const theme = useTheme(); - const sort = useSelector((state) => state.comments.sort); - return ; + return ; } diff --git a/frontend/app/components/auth-panel/index.ts b/frontend/app/components/auth-panel/index.ts index 30189cea..1d71a79c 100644 --- a/frontend/app/components/auth-panel/index.ts +++ b/frontend/app/components/auth-panel/index.ts @@ -2,9 +2,6 @@ import './auth-panel.css'; import './__readonly-label/auth-panel__readonly-label.css'; import './__column/auth-panel__column.css'; -import './__select/auth-panel__select.css'; -import './__select-label/auth-panel__select-label.css'; -import './__select-label-value/auth-panel__select-label-value.css'; import './__sort/auth-panel__sort.css'; export * from './auth-panel'; diff --git a/frontend/app/components/auth/auth.tsx b/frontend/app/components/auth/auth.tsx index 578aba52..fe1e3dad 100644 --- a/frontend/app/components/auth/auth.tsx +++ b/frontend/app/components/auth/auth.tsx @@ -8,6 +8,8 @@ import { setUser } from 'store/user/actions'; import { Input } from 'components/input'; import { CrossIcon } from 'components/icons/cross'; import { TextareaAutosize } from 'components/textarea-autosize'; +import { Spinner } from 'components/spinner/spinner'; +import { Arrow } from 'components/icons/arrow'; import { Button } from './components/button'; import { OAuth } from './components/oauth'; @@ -17,7 +19,6 @@ import { getProviders, getTokenInvalidReason } from './auth.utils'; import { emailSignin, verifyEmailSignin, anonymousSignin } from './auth.api'; import styles from './auth.module.css'; -import { Spinner } from 'components/spinner/spinner'; export function Auth() { const intl = useIntl(); @@ -115,22 +116,7 @@ export function Auth() { ); return (
- {isDropdownShowed && ( diff --git a/frontend/app/components/auth/components/button.tsx b/frontend/app/components/auth/components/button.tsx index d6fc36b3..b108319c 100644 --- a/frontend/app/components/auth/components/button.tsx +++ b/frontend/app/components/auth/components/button.tsx @@ -11,7 +11,7 @@ type Props = Omit, 'size'> & { selected?: boolean; }; -export function Button({ children, size, kind, suffix, selected, className, ...props }: Props) { +export function Button({ children, size, kind, suffix, selected, className, onChange, ...props }: Props) { return (