Merge pull request #2569 from ClearlyClaire/glitch-soc/ports/column-changes
Port upstream's column refactor of column and column header codepull/2571/head
commit
3425b99a9a
|
@ -1,65 +0,0 @@
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { PureComponent } from 'react';
|
|
||||||
import { createPortal } from 'react-dom';
|
|
||||||
|
|
||||||
import { FormattedMessage } from 'react-intl';
|
|
||||||
|
|
||||||
import { withRouter } from 'react-router-dom';
|
|
||||||
|
|
||||||
import { ReactComponent as ArrowBackIcon } from '@material-symbols/svg-600/outlined/arrow_back.svg';
|
|
||||||
|
|
||||||
import { Icon } from 'flavours/glitch/components/icon';
|
|
||||||
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router';
|
|
||||||
|
|
||||||
export class ColumnBackButton extends PureComponent {
|
|
||||||
|
|
||||||
static propTypes = {
|
|
||||||
multiColumn: PropTypes.bool,
|
|
||||||
onClick: PropTypes.func,
|
|
||||||
...WithRouterPropTypes,
|
|
||||||
};
|
|
||||||
|
|
||||||
handleClick = () => {
|
|
||||||
const { onClick, history } = this.props;
|
|
||||||
|
|
||||||
if (onClick) {
|
|
||||||
onClick();
|
|
||||||
} else if (history.location?.state?.fromMastodon) {
|
|
||||||
history.goBack();
|
|
||||||
} else {
|
|
||||||
history.push('/');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
render () {
|
|
||||||
const { multiColumn } = this.props;
|
|
||||||
|
|
||||||
const component = (
|
|
||||||
<button onClick={this.handleClick} className='column-back-button'>
|
|
||||||
<Icon id='chevron-left' icon={ArrowBackIcon} className='column-back-button__icon' />
|
|
||||||
<FormattedMessage id='column_back_button.label' defaultMessage='Back' />
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
|
|
||||||
if (multiColumn) {
|
|
||||||
return component;
|
|
||||||
} else {
|
|
||||||
// The portal container and the component may be rendered to the DOM in
|
|
||||||
// the same React render pass, so the container might not be available at
|
|
||||||
// the time `render()` is called.
|
|
||||||
const container = document.getElementById('tabs-bar__portal');
|
|
||||||
if (container === null) {
|
|
||||||
// The container wasn't available, force a re-render so that the
|
|
||||||
// component can eventually be inserted in the container and not scroll
|
|
||||||
// with the rest of the area.
|
|
||||||
this.forceUpdate();
|
|
||||||
return component;
|
|
||||||
} else {
|
|
||||||
return createPortal(component, container);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export default withRouter(ColumnBackButton);
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
|
||||||
|
import { ReactComponent as ArrowBackIcon } from '@material-symbols/svg-600/outlined/arrow_back.svg';
|
||||||
|
|
||||||
|
import { Icon } from 'flavours/glitch/components/icon';
|
||||||
|
import { ButtonInTabsBar } from 'flavours/glitch/features/ui/util/columns_context';
|
||||||
|
|
||||||
|
import { useAppHistory } from './router';
|
||||||
|
|
||||||
|
type OnClickCallback = () => void;
|
||||||
|
|
||||||
|
function useHandleClick(onClick?: OnClickCallback) {
|
||||||
|
const history = useAppHistory();
|
||||||
|
|
||||||
|
return useCallback(() => {
|
||||||
|
if (onClick) {
|
||||||
|
onClick();
|
||||||
|
} else if (history.location.state?.fromMastodon) {
|
||||||
|
history.goBack();
|
||||||
|
} else {
|
||||||
|
history.push('/');
|
||||||
|
}
|
||||||
|
}, [history, onClick]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ColumnBackButton: React.FC<{ onClick: OnClickCallback }> = ({
|
||||||
|
onClick,
|
||||||
|
}) => {
|
||||||
|
const handleClick = useHandleClick(onClick);
|
||||||
|
|
||||||
|
const component = (
|
||||||
|
<button onClick={handleClick} className='column-back-button'>
|
||||||
|
<Icon
|
||||||
|
id='chevron-left'
|
||||||
|
icon={ArrowBackIcon}
|
||||||
|
className='column-back-button__icon'
|
||||||
|
/>
|
||||||
|
<FormattedMessage id='column_back_button.label' defaultMessage='Back' />
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
|
||||||
|
return <ButtonInTabsBar>{component}</ButtonInTabsBar>;
|
||||||
|
};
|
|
@ -1,42 +0,0 @@
|
||||||
import { PureComponent } from 'react';
|
|
||||||
|
|
||||||
import { FormattedMessage } from 'react-intl';
|
|
||||||
|
|
||||||
import { withRouter } from 'react-router-dom';
|
|
||||||
|
|
||||||
import { ReactComponent as ArrowBackIcon } from '@material-symbols/svg-600/outlined/arrow_back.svg';
|
|
||||||
|
|
||||||
import { Icon } from 'flavours/glitch/components/icon';
|
|
||||||
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router';
|
|
||||||
|
|
||||||
class ColumnBackButtonSlim extends PureComponent {
|
|
||||||
|
|
||||||
static propTypes = {
|
|
||||||
...WithRouterPropTypes,
|
|
||||||
};
|
|
||||||
|
|
||||||
handleClick = () => {
|
|
||||||
const { location, history } = this.props;
|
|
||||||
|
|
||||||
// Check if there is a previous page in the app to go back to per https://stackoverflow.com/a/70532858/9703201
|
|
||||||
// When upgrading to V6, check `location.key !== 'default'` instead per https://github.com/remix-run/history/blob/main/docs/api-reference.md#location
|
|
||||||
if (location.key) {
|
|
||||||
history.goBack();
|
|
||||||
} else {
|
|
||||||
history.push('/');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
render () {
|
|
||||||
return (
|
|
||||||
<div className='column-back-button--slim'>
|
|
||||||
<div role='button' tabIndex={0} onClick={this.handleClick} className='column-back-button column-back-button--slim-button'>
|
|
||||||
<Icon id='chevron-left' icon={ArrowBackIcon} className='column-back-button__icon' />
|
|
||||||
<FormattedMessage id='column_back_button.label' defaultMessage='Back' />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default withRouter(ColumnBackButtonSlim);
|
|
|
@ -1,6 +1,5 @@
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { PureComponent } from 'react';
|
import { PureComponent, useCallback } from 'react';
|
||||||
import { createPortal } from 'react-dom';
|
|
||||||
|
|
||||||
import { FormattedMessage, injectIntl, defineMessages } from 'react-intl';
|
import { FormattedMessage, injectIntl, defineMessages } from 'react-intl';
|
||||||
|
|
||||||
|
@ -15,8 +14,11 @@ import { ReactComponent as CloseIcon } from '@material-symbols/svg-600/outlined/
|
||||||
import { ReactComponent as TuneIcon } from '@material-symbols/svg-600/outlined/tune.svg';
|
import { ReactComponent as TuneIcon } from '@material-symbols/svg-600/outlined/tune.svg';
|
||||||
|
|
||||||
import { Icon } from 'flavours/glitch/components/icon';
|
import { Icon } from 'flavours/glitch/components/icon';
|
||||||
|
import { ButtonInTabsBar, useColumnsContext } from 'flavours/glitch/features/ui/util/columns_context';
|
||||||
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router';
|
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router';
|
||||||
|
|
||||||
|
import { useAppHistory } from './router';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
show: { id: 'column_header.show_settings', defaultMessage: 'Show settings' },
|
show: { id: 'column_header.show_settings', defaultMessage: 'Show settings' },
|
||||||
hide: { id: 'column_header.hide_settings', defaultMessage: 'Hide settings' },
|
hide: { id: 'column_header.hide_settings', defaultMessage: 'Hide settings' },
|
||||||
|
@ -24,6 +26,34 @@ const messages = defineMessages({
|
||||||
moveRight: { id: 'column_header.moveRight_settings', defaultMessage: 'Move column to the right' },
|
moveRight: { id: 'column_header.moveRight_settings', defaultMessage: 'Move column to the right' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const BackButton = ({ pinned, show }) => {
|
||||||
|
const history = useAppHistory();
|
||||||
|
const { multiColumn } = useColumnsContext();
|
||||||
|
|
||||||
|
const handleBackClick = useCallback(() => {
|
||||||
|
if (history.location?.state?.fromMastodon) {
|
||||||
|
history.goBack();
|
||||||
|
} else {
|
||||||
|
history.push('/');
|
||||||
|
}
|
||||||
|
}, [history]);
|
||||||
|
|
||||||
|
const showButton = history && !pinned && ((multiColumn && history.location?.state?.fromMastodon) || show);
|
||||||
|
|
||||||
|
if(!showButton) return null;
|
||||||
|
|
||||||
|
return (<button onClick={handleBackClick} className='column-header__back-button'>
|
||||||
|
<Icon id='chevron-left' icon={ArrowBackIcon} className='column-back-button__icon' />
|
||||||
|
<FormattedMessage id='column_back_button.label' defaultMessage='Back' />
|
||||||
|
</button>);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
BackButton.propTypes = {
|
||||||
|
pinned: PropTypes.bool,
|
||||||
|
show: PropTypes.bool,
|
||||||
|
};
|
||||||
|
|
||||||
class ColumnHeader extends PureComponent {
|
class ColumnHeader extends PureComponent {
|
||||||
|
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
|
@ -72,16 +102,6 @@ class ColumnHeader extends PureComponent {
|
||||||
this.props.onMove(1);
|
this.props.onMove(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
handleBackClick = () => {
|
|
||||||
const { history } = this.props;
|
|
||||||
|
|
||||||
if (history.location?.state?.fromMastodon) {
|
|
||||||
history.goBack();
|
|
||||||
} else {
|
|
||||||
history.push('/');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
handleTransitionEnd = () => {
|
handleTransitionEnd = () => {
|
||||||
this.setState({ animating: false });
|
this.setState({ animating: false });
|
||||||
};
|
};
|
||||||
|
@ -95,7 +115,7 @@ class ColumnHeader extends PureComponent {
|
||||||
};
|
};
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { title, icon, iconComponent, active, children, pinned, multiColumn, extraButton, showBackButton, intl: { formatMessage }, placeholder, appendContent, collapseIssues, history } = this.props;
|
const { title, icon, iconComponent, active, children, pinned, multiColumn, extraButton, showBackButton, intl: { formatMessage }, placeholder, appendContent, collapseIssues } = this.props;
|
||||||
const { collapsed, animating } = this.state;
|
const { collapsed, animating } = this.state;
|
||||||
|
|
||||||
const wrapperClassName = classNames('column-header__wrapper', {
|
const wrapperClassName = classNames('column-header__wrapper', {
|
||||||
|
@ -138,14 +158,7 @@ class ColumnHeader extends PureComponent {
|
||||||
pinButton = <button key='pin-button' className='text-btn column-header__setting-btn' onClick={this.handlePin}><Icon id='plus' icon={AddIcon} /> <FormattedMessage id='column_header.pin' defaultMessage='Pin' /></button>;
|
pinButton = <button key='pin-button' className='text-btn column-header__setting-btn' onClick={this.handlePin}><Icon id='plus' icon={AddIcon} /> <FormattedMessage id='column_header.pin' defaultMessage='Pin' /></button>;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pinned && ((multiColumn && history.location?.state?.fromMastodon) || showBackButton)) {
|
backButton = <BackButton pinned={pinned} show={showBackButton} />;
|
||||||
backButton = (
|
|
||||||
<button onClick={this.handleBackClick} className='column-header__back-button'>
|
|
||||||
<Icon id='chevron-left' icon={ArrowBackIcon} className='column-back-button__icon' />
|
|
||||||
<FormattedMessage id='column_back_button.label' defaultMessage='Back' />
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const collapsedContent = [
|
const collapsedContent = [
|
||||||
extraContent,
|
extraContent,
|
||||||
|
@ -203,22 +216,12 @@ class ColumnHeader extends PureComponent {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (multiColumn || placeholder) {
|
if (placeholder) {
|
||||||
return component;
|
return component;
|
||||||
} else {
|
} else {
|
||||||
// The portal container and the component may be rendered to the DOM in
|
return (<ButtonInTabsBar>
|
||||||
// the same React render pass, so the container might not be available at
|
{component}
|
||||||
// the time `render()` is called.
|
</ButtonInTabsBar>);
|
||||||
const container = document.getElementById('tabs-bar__portal');
|
|
||||||
if (container === null) {
|
|
||||||
// The container wasn't available, force a re-render so that the
|
|
||||||
// component can eventually be inserted in the container and not scroll
|
|
||||||
// with the rest of the area.
|
|
||||||
this.forceUpdate();
|
|
||||||
return component;
|
|
||||||
} else {
|
|
||||||
return createPortal(component, container);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import type { PropsWithChildren } from 'react';
|
import type { PropsWithChildren } from 'react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { Router as OriginalRouter } from 'react-router';
|
import { Router as OriginalRouter, useHistory } from 'react-router';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
LocationDescriptor,
|
LocationDescriptor,
|
||||||
|
@ -16,18 +16,23 @@ interface MastodonLocationState {
|
||||||
fromMastodon?: boolean;
|
fromMastodon?: boolean;
|
||||||
mastodonModalKey?: string;
|
mastodonModalKey?: string;
|
||||||
}
|
}
|
||||||
type HistoryPath = Path | LocationDescriptor<MastodonLocationState>;
|
|
||||||
|
|
||||||
const browserHistory = createBrowserHistory<
|
type LocationState = MastodonLocationState | null | undefined;
|
||||||
MastodonLocationState | undefined
|
|
||||||
>();
|
type HistoryPath = Path | LocationDescriptor<LocationState>;
|
||||||
|
|
||||||
|
const browserHistory = createBrowserHistory<LocationState>();
|
||||||
const originalPush = browserHistory.push.bind(browserHistory);
|
const originalPush = browserHistory.push.bind(browserHistory);
|
||||||
const originalReplace = browserHistory.replace.bind(browserHistory);
|
const originalReplace = browserHistory.replace.bind(browserHistory);
|
||||||
|
|
||||||
|
export function useAppHistory() {
|
||||||
|
return useHistory<LocationState>();
|
||||||
|
}
|
||||||
|
|
||||||
function normalizePath(
|
function normalizePath(
|
||||||
path: HistoryPath,
|
path: HistoryPath,
|
||||||
state?: MastodonLocationState,
|
state?: LocationState,
|
||||||
): LocationDescriptorObject<MastodonLocationState> {
|
): LocationDescriptorObject<LocationState> {
|
||||||
const location = typeof path === 'string' ? { pathname: path } : { ...path };
|
const location = typeof path === 'string' ? { pathname: path } : { ...path };
|
||||||
|
|
||||||
if (location.state === undefined && state !== undefined) {
|
if (location.state === undefined && state !== undefined) {
|
||||||
|
|
|
@ -10,7 +10,6 @@ import { ReactComponent as BlockIcon } from '@material-symbols/svg-600/outlined/
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
|
|
||||||
import { fetchBlocks, expandBlocks } from '../../actions/blocks';
|
import { fetchBlocks, expandBlocks } from '../../actions/blocks';
|
||||||
import ColumnBackButtonSlim from '../../components/column_back_button_slim';
|
|
||||||
import { LoadingIndicator } from '../../components/loading_indicator';
|
import { LoadingIndicator } from '../../components/loading_indicator';
|
||||||
import ScrollableList from '../../components/scrollable_list';
|
import ScrollableList from '../../components/scrollable_list';
|
||||||
import AccountContainer from '../../containers/account_container';
|
import AccountContainer from '../../containers/account_container';
|
||||||
|
@ -60,8 +59,7 @@ class Blocks extends ImmutablePureComponent {
|
||||||
const emptyMessage = <FormattedMessage id='empty_column.blocks' defaultMessage="You haven't blocked any users yet." />;
|
const emptyMessage = <FormattedMessage id='empty_column.blocks' defaultMessage="You haven't blocked any users yet." />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column bindToDocument={!multiColumn} icon='ban' iconComponent={BlockIcon} heading={intl.formatMessage(messages.heading)}>
|
<Column bindToDocument={!multiColumn} icon='ban' iconComponent={BlockIcon} heading={intl.formatMessage(messages.heading)} alwaysShowBackButton>
|
||||||
<ColumnBackButtonSlim />
|
|
||||||
<ScrollableList
|
<ScrollableList
|
||||||
scrollKey='blocks'
|
scrollKey='blocks'
|
||||||
onLoadMore={this.handleLoadMore}
|
onLoadMore={this.handleLoadMore}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import { ReactComponent as BlockIcon } from '@material-symbols/svg-600/outlined/
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
|
|
||||||
import { fetchDomainBlocks, expandDomainBlocks } from '../../actions/domain_blocks';
|
import { fetchDomainBlocks, expandDomainBlocks } from '../../actions/domain_blocks';
|
||||||
import ColumnBackButtonSlim from '../../components/column_back_button_slim';
|
|
||||||
import { LoadingIndicator } from '../../components/loading_indicator';
|
import { LoadingIndicator } from '../../components/loading_indicator';
|
||||||
import ScrollableList from '../../components/scrollable_list';
|
import ScrollableList from '../../components/scrollable_list';
|
||||||
import DomainContainer from '../../containers/domain_container';
|
import DomainContainer from '../../containers/domain_container';
|
||||||
|
@ -61,9 +60,7 @@ class Blocks extends ImmutablePureComponent {
|
||||||
const emptyMessage = <FormattedMessage id='empty_column.domain_blocks' defaultMessage='There are no blocked domains yet.' />;
|
const emptyMessage = <FormattedMessage id='empty_column.domain_blocks' defaultMessage='There are no blocked domains yet.' />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column bindToDocument={!multiColumn} icon='ban' iconComponent={BlockIcon} heading={intl.formatMessage(messages.heading)}>
|
<Column bindToDocument={!multiColumn} icon='ban' iconComponent={BlockIcon} heading={intl.formatMessage(messages.heading)} alwaysShowBackButton>
|
||||||
<ColumnBackButtonSlim />
|
|
||||||
|
|
||||||
<ScrollableList
|
<ScrollableList
|
||||||
scrollKey='domain_blocks'
|
scrollKey='domain_blocks'
|
||||||
onLoadMore={this.handleLoadMore}
|
onLoadMore={this.handleLoadMore}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import { ReactComponent as PersonAddIcon } from '@material-symbols/svg-600/outli
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
|
|
||||||
import { fetchFollowRequests, expandFollowRequests } from '../../actions/accounts';
|
import { fetchFollowRequests, expandFollowRequests } from '../../actions/accounts';
|
||||||
import ColumnBackButtonSlim from '../../components/column_back_button_slim';
|
|
||||||
import ScrollableList from '../../components/scrollable_list';
|
import ScrollableList from '../../components/scrollable_list';
|
||||||
import { me } from '../../initial_state';
|
import { me } from '../../initial_state';
|
||||||
import Column from '../ui/components/column';
|
import Column from '../ui/components/column';
|
||||||
|
@ -68,8 +67,7 @@ class FollowRequests extends ImmutablePureComponent {
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column bindToDocument={!multiColumn} icon='user-plus' iconComponent={PersonAddIcon} heading={intl.formatMessage(messages.heading)}>
|
<Column bindToDocument={!multiColumn} icon='user-plus' iconComponent={PersonAddIcon} heading={intl.formatMessage(messages.heading)} alwaysShowBackButton>
|
||||||
<ColumnBackButtonSlim />
|
|
||||||
<ScrollableList
|
<ScrollableList
|
||||||
scrollKey='follow_requests'
|
scrollKey='follow_requests'
|
||||||
onLoadMore={this.handleLoadMore}
|
onLoadMore={this.handleLoadMore}
|
||||||
|
|
|
@ -13,12 +13,10 @@ import { ReactComponent as StarIcon } from '@material-symbols/svg-600/outlined/s
|
||||||
import { ReactComponent as VolumeOffIcon } from '@material-symbols/svg-600/outlined/volume_off.svg';
|
import { ReactComponent as VolumeOffIcon } from '@material-symbols/svg-600/outlined/volume_off.svg';
|
||||||
|
|
||||||
import { openModal } from 'flavours/glitch/actions/modal';
|
import { openModal } from 'flavours/glitch/actions/modal';
|
||||||
import ColumnBackButtonSlim from 'flavours/glitch/components/column_back_button_slim';
|
|
||||||
import Column from 'flavours/glitch/features/ui/components/column';
|
import Column from 'flavours/glitch/features/ui/components/column';
|
||||||
import ColumnLink from 'flavours/glitch/features/ui/components/column_link';
|
import ColumnLink from 'flavours/glitch/features/ui/components/column_link';
|
||||||
import ColumnSubheading from 'flavours/glitch/features/ui/components/column_subheading';
|
import ColumnSubheading from 'flavours/glitch/features/ui/components/column_subheading';
|
||||||
|
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
heading: { id: 'column.heading', defaultMessage: 'Misc' },
|
heading: { id: 'column.heading', defaultMessage: 'Misc' },
|
||||||
subheading: { id: 'column.subheading', defaultMessage: 'Miscellaneous options' },
|
subheading: { id: 'column.subheading', defaultMessage: 'Miscellaneous options' },
|
||||||
|
@ -53,9 +51,7 @@ class GettingStartedMisc extends ImmutablePureComponent {
|
||||||
const { signedIn } = this.context.identity;
|
const { signedIn } = this.context.identity;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column icon='ellipsis-h' heading={intl.formatMessage(messages.heading)}>
|
<Column icon='ellipsis-h' heading={intl.formatMessage(messages.heading)} alwaysShowBackButton>
|
||||||
<ColumnBackButtonSlim />
|
|
||||||
|
|
||||||
<div className='scrollable'>
|
<div className='scrollable'>
|
||||||
<ColumnSubheading text={intl.formatMessage(messages.subheading)} />
|
<ColumnSubheading text={intl.formatMessage(messages.subheading)} />
|
||||||
{signedIn && (<ColumnLink key='favourites' icon='star' iconComponent={StarIcon} text={intl.formatMessage(messages.favourites)} to='/favourites' />)}
|
{signedIn && (<ColumnLink key='favourites' icon='star' iconComponent={StarIcon} text={intl.formatMessage(messages.favourites)} to='/favourites' />)}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import { connect } from 'react-redux';
|
||||||
import { ReactComponent as ListAltIcon } from '@material-symbols/svg-600/outlined/list_alt.svg';
|
import { ReactComponent as ListAltIcon } from '@material-symbols/svg-600/outlined/list_alt.svg';
|
||||||
|
|
||||||
import { fetchLists } from 'flavours/glitch/actions/lists';
|
import { fetchLists } from 'flavours/glitch/actions/lists';
|
||||||
import ColumnBackButtonSlim from 'flavours/glitch/components/column_back_button_slim';
|
|
||||||
import { LoadingIndicator } from 'flavours/glitch/components/loading_indicator';
|
import { LoadingIndicator } from 'flavours/glitch/components/loading_indicator';
|
||||||
import ScrollableList from 'flavours/glitch/components/scrollable_list';
|
import ScrollableList from 'flavours/glitch/components/scrollable_list';
|
||||||
import Column from 'flavours/glitch/features/ui/components/column';
|
import Column from 'flavours/glitch/features/ui/components/column';
|
||||||
|
@ -66,9 +65,7 @@ class Lists extends ImmutablePureComponent {
|
||||||
const emptyMessage = <FormattedMessage id='empty_column.lists' defaultMessage="You don't have any lists yet. When you create one, it will show up here." />;
|
const emptyMessage = <FormattedMessage id='empty_column.lists' defaultMessage="You don't have any lists yet. When you create one, it will show up here." />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column bindToDocument={!multiColumn} icon='bars' iconComponent={ListAltIcon} heading={intl.formatMessage(messages.heading)}>
|
<Column bindToDocument={!multiColumn} icon='bars' iconComponent={ListAltIcon} heading={intl.formatMessage(messages.heading)} alwaysShowBackButton>
|
||||||
<ColumnBackButtonSlim />
|
|
||||||
|
|
||||||
<NewListForm />
|
<NewListForm />
|
||||||
|
|
||||||
<ColumnSubheading text={intl.formatMessage(messages.subheading)} />
|
<ColumnSubheading text={intl.formatMessage(messages.subheading)} />
|
||||||
|
|
|
@ -12,7 +12,6 @@ import { ReactComponent as VolumeOffIcon } from '@material-symbols/svg-600/outli
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
|
|
||||||
import { fetchMutes, expandMutes } from '../../actions/mutes';
|
import { fetchMutes, expandMutes } from '../../actions/mutes';
|
||||||
import ColumnBackButtonSlim from '../../components/column_back_button_slim';
|
|
||||||
import { LoadingIndicator } from '../../components/loading_indicator';
|
import { LoadingIndicator } from '../../components/loading_indicator';
|
||||||
import ScrollableList from '../../components/scrollable_list';
|
import ScrollableList from '../../components/scrollable_list';
|
||||||
import AccountContainer from '../../containers/account_container';
|
import AccountContainer from '../../containers/account_container';
|
||||||
|
@ -62,8 +61,7 @@ class Mutes extends ImmutablePureComponent {
|
||||||
const emptyMessage = <FormattedMessage id='empty_column.mutes' defaultMessage="You haven't muted any users yet." />;
|
const emptyMessage = <FormattedMessage id='empty_column.mutes' defaultMessage="You haven't muted any users yet." />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column bindToDocument={!multiColumn} icon='volume-off' iconComponent={VolumeOffIcon} heading={intl.formatMessage(messages.heading)}>
|
<Column bindToDocument={!multiColumn} icon='volume-off' iconComponent={VolumeOffIcon} heading={intl.formatMessage(messages.heading)} alwaysShowBackButton>
|
||||||
<ColumnBackButtonSlim />
|
|
||||||
<ScrollableList
|
<ScrollableList
|
||||||
scrollKey='mutes'
|
scrollKey='mutes'
|
||||||
onLoadMore={this.handleLoadMore}
|
onLoadMore={this.handleLoadMore}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { connect } from 'react-redux';
|
||||||
import { fetchSuggestions } from 'flavours/glitch/actions/suggestions';
|
import { fetchSuggestions } from 'flavours/glitch/actions/suggestions';
|
||||||
import { markAsPartial } from 'flavours/glitch/actions/timelines';
|
import { markAsPartial } from 'flavours/glitch/actions/timelines';
|
||||||
import Column from 'flavours/glitch/components/column';
|
import Column from 'flavours/glitch/components/column';
|
||||||
import ColumnBackButton from 'flavours/glitch/components/column_back_button';
|
import { ColumnBackButton } from 'flavours/glitch/components/column_back_button';
|
||||||
import { EmptyAccount } from 'flavours/glitch/components/empty_account';
|
import { EmptyAccount } from 'flavours/glitch/components/empty_account';
|
||||||
import Account from 'flavours/glitch/containers/account_container';
|
import Account from 'flavours/glitch/containers/account_container';
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ class Follows extends PureComponent {
|
||||||
dispatch: PropTypes.func.isRequired,
|
dispatch: PropTypes.func.isRequired,
|
||||||
suggestions: ImmutablePropTypes.list,
|
suggestions: ImmutablePropTypes.list,
|
||||||
isLoading: PropTypes.bool,
|
isLoading: PropTypes.bool,
|
||||||
multiColumn: PropTypes.bool,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
|
@ -39,7 +38,7 @@ class Follows extends PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { onBack, isLoading, suggestions, multiColumn } = this.props;
|
const { onBack, isLoading, suggestions } = this.props;
|
||||||
|
|
||||||
let loadedContent;
|
let loadedContent;
|
||||||
|
|
||||||
|
@ -53,7 +52,7 @@ class Follows extends PureComponent {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column>
|
<Column>
|
||||||
<ColumnBackButton multiColumn={multiColumn} onClick={onBack} />
|
<ColumnBackButton onClick={onBack} />
|
||||||
|
|
||||||
<div className='scrollable privacy-policy'>
|
<div className='scrollable privacy-policy'>
|
||||||
<div className='column-title'>
|
<div className='column-title'>
|
||||||
|
|
|
@ -48,7 +48,6 @@ class Onboarding extends ImmutablePureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
dispatch: PropTypes.func.isRequired,
|
dispatch: PropTypes.func.isRequired,
|
||||||
account: ImmutablePropTypes.record,
|
account: ImmutablePropTypes.record,
|
||||||
multiColumn: PropTypes.bool,
|
|
||||||
...WithRouterPropTypes,
|
...WithRouterPropTypes,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,14 +100,14 @@ class Onboarding extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { account, multiColumn } = this.props;
|
const { account } = this.props;
|
||||||
const { step, shareClicked } = this.state;
|
const { step, shareClicked } = this.state;
|
||||||
|
|
||||||
switch(step) {
|
switch(step) {
|
||||||
case 'follows':
|
case 'follows':
|
||||||
return <Follows onBack={this.handleBackClick} multiColumn={multiColumn} />;
|
return <Follows onBack={this.handleBackClick} />;
|
||||||
case 'share':
|
case 'share':
|
||||||
return <Share onBack={this.handleBackClick} multiColumn={multiColumn} />;
|
return <Share onBack={this.handleBackClick} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { ReactComponent as ContentCopyIcon } from '@material-symbols/svg-600/out
|
||||||
import SwipeableViews from 'react-swipeable-views';
|
import SwipeableViews from 'react-swipeable-views';
|
||||||
|
|
||||||
import Column from 'flavours/glitch/components/column';
|
import Column from 'flavours/glitch/components/column';
|
||||||
import ColumnBackButton from 'flavours/glitch/components/column_back_button';
|
import { ColumnBackButton } from 'flavours/glitch/components/column_back_button';
|
||||||
import { Icon } from 'flavours/glitch/components/icon';
|
import { Icon } from 'flavours/glitch/components/icon';
|
||||||
import { me, domain } from 'flavours/glitch/initial_state';
|
import { me, domain } from 'flavours/glitch/initial_state';
|
||||||
|
|
||||||
|
@ -146,18 +146,17 @@ class Share extends PureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
onBack: PropTypes.func,
|
onBack: PropTypes.func,
|
||||||
account: ImmutablePropTypes.record,
|
account: ImmutablePropTypes.record,
|
||||||
multiColumn: PropTypes.bool,
|
|
||||||
intl: PropTypes.object,
|
intl: PropTypes.object,
|
||||||
};
|
};
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { onBack, account, multiColumn, intl } = this.props;
|
const { onBack, account, intl } = this.props;
|
||||||
|
|
||||||
const url = (new URL(`/@${account.get('username')}`, document.baseURI)).href;
|
const url = (new URL(`/@${account.get('username')}`, document.baseURI)).href;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column>
|
<Column>
|
||||||
<ColumnBackButton multiColumn={multiColumn} onClick={onBack} />
|
<ColumnBackButton onClick={onBack} />
|
||||||
|
|
||||||
<div className='scrollable privacy-policy'>
|
<div className='scrollable privacy-policy'>
|
||||||
<div className='column-title'>
|
<div className='column-title'>
|
||||||
|
|
|
@ -13,7 +13,6 @@ import { ReactComponent as PushPinIcon } from '@material-symbols/svg-600/outline
|
||||||
import { getStatusList } from 'flavours/glitch/selectors';
|
import { getStatusList } from 'flavours/glitch/selectors';
|
||||||
|
|
||||||
import { fetchPinnedStatuses } from '../../actions/pin_statuses';
|
import { fetchPinnedStatuses } from '../../actions/pin_statuses';
|
||||||
import ColumnBackButtonSlim from '../../components/column_back_button_slim';
|
|
||||||
import StatusList from '../../components/status_list';
|
import StatusList from '../../components/status_list';
|
||||||
import Column from '../ui/components/column';
|
import Column from '../ui/components/column';
|
||||||
|
|
||||||
|
@ -52,8 +51,7 @@ class PinnedStatuses extends ImmutablePureComponent {
|
||||||
const { intl, statusIds, hasMore, multiColumn } = this.props;
|
const { intl, statusIds, hasMore, multiColumn } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column bindToDocument={!multiColumn} icon='thumb-tack' iconComponent={PushPinIcon} heading={intl.formatMessage(messages.heading)} ref={this.setRef}>
|
<Column bindToDocument={!multiColumn} icon='thumb-tack' iconComponent={PushPinIcon} heading={intl.formatMessage(messages.heading)} ref={this.setRef} alwaysShowBackButton>
|
||||||
<ColumnBackButtonSlim />
|
|
||||||
<StatusList
|
<StatusList
|
||||||
statusIds={statusIds}
|
statusIds={statusIds}
|
||||||
scrollKey='pinned_statuses'
|
scrollKey='pinned_statuses'
|
||||||
|
|
|
@ -3,15 +3,15 @@ import { PureComponent } from 'react';
|
||||||
|
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
|
|
||||||
|
import ColumnHeader from '../../../components/column_header';
|
||||||
import { isMobile } from '../../../is_mobile';
|
import { isMobile } from '../../../is_mobile';
|
||||||
import { scrollTop } from '../../../scroll';
|
import { scrollTop } from '../../../scroll';
|
||||||
|
|
||||||
import ColumnHeader from './column_header';
|
|
||||||
|
|
||||||
export default class Column extends PureComponent {
|
export default class Column extends PureComponent {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
heading: PropTypes.string,
|
heading: PropTypes.string,
|
||||||
|
alwaysShowBackButton: PropTypes.bool,
|
||||||
icon: PropTypes.string,
|
icon: PropTypes.string,
|
||||||
iconComponent: PropTypes.func,
|
iconComponent: PropTypes.func,
|
||||||
children: PropTypes.node,
|
children: PropTypes.node,
|
||||||
|
@ -53,13 +53,14 @@ export default class Column extends PureComponent {
|
||||||
};
|
};
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { heading, icon, iconComponent, children, active, hideHeadingOnMobile, name } = this.props;
|
const { heading, icon, iconComponent, children, active, hideHeadingOnMobile, alwaysShowBackButton, name } = this.props;
|
||||||
|
|
||||||
const showHeading = heading && (!hideHeadingOnMobile || (hideHeadingOnMobile && !isMobile(window.innerWidth)));
|
const showHeading = heading && (!hideHeadingOnMobile || (hideHeadingOnMobile && !isMobile(window.innerWidth)));
|
||||||
|
|
||||||
const columnHeaderId = showHeading && heading.replace(/ /g, '-');
|
const columnHeaderId = showHeading && heading.replace(/ /g, '-');
|
||||||
|
|
||||||
const header = showHeading && (
|
const header = showHeading && (
|
||||||
<ColumnHeader icon={icon} iconComponent={iconComponent} active={active} type={heading} onClick={this.handleHeaderClick} columnHeaderId={columnHeaderId} />
|
<ColumnHeader icon={icon} iconComponent={iconComponent} active={active} title={heading} onClick={this.handleHeaderClick} columnHeaderId={columnHeaderId} showBackButton={alwaysShowBackButton} />
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { PureComponent } from 'react';
|
|
||||||
|
|
||||||
import classNames from 'classnames';
|
|
||||||
|
|
||||||
import { Icon } from 'flavours/glitch/components/icon';
|
|
||||||
|
|
||||||
export default class ColumnHeader extends PureComponent {
|
|
||||||
|
|
||||||
static propTypes = {
|
|
||||||
icon: PropTypes.string,
|
|
||||||
iconComponent: PropTypes.func,
|
|
||||||
type: PropTypes.string,
|
|
||||||
active: PropTypes.bool,
|
|
||||||
onClick: PropTypes.func,
|
|
||||||
columnHeaderId: PropTypes.string,
|
|
||||||
};
|
|
||||||
|
|
||||||
handleClick = () => {
|
|
||||||
this.props.onClick();
|
|
||||||
};
|
|
||||||
|
|
||||||
render () {
|
|
||||||
const { icon, iconComponent, type, active, columnHeaderId } = this.props;
|
|
||||||
let iconElement = '';
|
|
||||||
|
|
||||||
if (icon) {
|
|
||||||
iconElement = <Icon id={icon} icon={iconComponent} className='column-header__icon' />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<h1 className={classNames('column-header', { active })} id={columnHeaderId || null}>
|
|
||||||
<button onClick={this.handleClick}>
|
|
||||||
{iconElement}
|
|
||||||
{type}
|
|
||||||
</button>
|
|
||||||
</h1>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Children, cloneElement } from 'react';
|
import { Children, cloneElement, useCallback } from 'react';
|
||||||
|
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
|
@ -21,6 +21,7 @@ import {
|
||||||
ListTimeline,
|
ListTimeline,
|
||||||
Directory,
|
Directory,
|
||||||
} from '../util/async-components';
|
} from '../util/async-components';
|
||||||
|
import { useColumnsContext } from '../util/columns_context';
|
||||||
|
|
||||||
import BundleColumnError from './bundle_column_error';
|
import BundleColumnError from './bundle_column_error';
|
||||||
import { ColumnLoading } from './column_loading';
|
import { ColumnLoading } from './column_loading';
|
||||||
|
@ -43,6 +44,17 @@ const componentMap = {
|
||||||
'DIRECTORY': Directory,
|
'DIRECTORY': Directory,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const TabsBarPortal = () => {
|
||||||
|
const {setTabsBarElement} = useColumnsContext();
|
||||||
|
|
||||||
|
const setRef = useCallback((element) => {
|
||||||
|
if(element)
|
||||||
|
setTabsBarElement(element);
|
||||||
|
}, [setTabsBarElement]);
|
||||||
|
|
||||||
|
return <div id='tabs-bar__portal' ref={setRef} />;
|
||||||
|
};
|
||||||
|
|
||||||
export default class ColumnsArea extends ImmutablePureComponent {
|
export default class ColumnsArea extends ImmutablePureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
columns: ImmutablePropTypes.list.isRequired,
|
columns: ImmutablePropTypes.list.isRequired,
|
||||||
|
@ -146,7 +158,7 @@ export default class ColumnsArea extends ImmutablePureComponent {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='columns-area__panels__main'>
|
<div className='columns-area__panels__main'>
|
||||||
<div className='tabs-bar__wrapper'><div id='tabs-bar__portal' /></div>
|
<div className='tabs-bar__wrapper'><TabsBarPortal /></div>
|
||||||
<div className='columns-area columns-area--mobile'>{children}</div>
|
<div className='columns-area columns-area--mobile'>{children}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,8 @@ import {
|
||||||
About,
|
About,
|
||||||
PrivacyPolicy,
|
PrivacyPolicy,
|
||||||
} from './util/async-components';
|
} from './util/async-components';
|
||||||
|
import { ColumnsContextProvider } from './util/columns_context';
|
||||||
import { WrappedSwitch, WrappedRoute } from './util/react_router_helpers';
|
import { WrappedSwitch, WrappedRoute } from './util/react_router_helpers';
|
||||||
|
|
||||||
// Dummy import, to make sure that <Status /> ends up in the application bundle.
|
// Dummy import, to make sure that <Status /> ends up in the application bundle.
|
||||||
// Without this it ends up in ~8 very commonly used bundles.
|
// Without this it ends up in ~8 very commonly used bundles.
|
||||||
import '../../components/status';
|
import '../../components/status';
|
||||||
|
@ -188,6 +188,7 @@ class SwitchingColumnsArea extends PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<ColumnsContextProvider multiColumn={!singleColumn}>
|
||||||
<ColumnsAreaContainer ref={this.setRef} singleColumn={singleColumn}>
|
<ColumnsAreaContainer ref={this.setRef} singleColumn={singleColumn}>
|
||||||
<WrappedSwitch>
|
<WrappedSwitch>
|
||||||
{redirect}
|
{redirect}
|
||||||
|
@ -251,6 +252,7 @@ class SwitchingColumnsArea extends PureComponent {
|
||||||
<Route component={BundleColumnError} />
|
<Route component={BundleColumnError} />
|
||||||
</WrappedSwitch>
|
</WrappedSwitch>
|
||||||
</ColumnsAreaContainer>
|
</ColumnsAreaContainer>
|
||||||
|
</ColumnsContextProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
import type { ReactElement } from 'react';
|
||||||
|
import { createContext, useContext, useMemo, useState } from 'react';
|
||||||
|
import { createPortal } from 'react-dom';
|
||||||
|
|
||||||
|
export const ColumnsContext = createContext<{
|
||||||
|
tabsBarElement: HTMLElement | null;
|
||||||
|
setTabsBarElement: (element: HTMLElement) => void;
|
||||||
|
multiColumn: boolean;
|
||||||
|
}>({
|
||||||
|
tabsBarElement: null,
|
||||||
|
multiColumn: false,
|
||||||
|
setTabsBarElement: () => undefined, // no-op
|
||||||
|
});
|
||||||
|
|
||||||
|
export function useColumnsContext() {
|
||||||
|
return useContext(ColumnsContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ButtonInTabsBar: React.FC<{
|
||||||
|
children: ReactElement | string | undefined;
|
||||||
|
}> = ({ children }) => {
|
||||||
|
const { multiColumn, tabsBarElement } = useColumnsContext();
|
||||||
|
|
||||||
|
if (multiColumn) {
|
||||||
|
return children;
|
||||||
|
} else if (!tabsBarElement) {
|
||||||
|
return children;
|
||||||
|
} else {
|
||||||
|
return createPortal(children, tabsBarElement);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
type ContextValue = React.ContextType<typeof ColumnsContext>;
|
||||||
|
|
||||||
|
export const ColumnsContextProvider: React.FC<
|
||||||
|
React.PropsWithChildren<{ multiColumn: boolean }>
|
||||||
|
> = ({ multiColumn, children }) => {
|
||||||
|
const [tabsBarElement, setTabsBarElement] =
|
||||||
|
useState<ContextValue['tabsBarElement']>(null);
|
||||||
|
|
||||||
|
const contextValue = useMemo<ContextValue>(
|
||||||
|
() => ({ multiColumn, tabsBarElement, setTabsBarElement }),
|
||||||
|
[multiColumn, tabsBarElement],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ColumnsContext.Provider value={contextValue}>
|
||||||
|
{children}
|
||||||
|
</ColumnsContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
|
@ -218,20 +218,6 @@ $ui-header-height: 55px;
|
||||||
margin-inline-end: 5px;
|
margin-inline-end: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.column-back-button--slim {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.column-back-button--slim-button {
|
|
||||||
cursor: pointer;
|
|
||||||
flex: 0 0 auto;
|
|
||||||
font-size: 16px;
|
|
||||||
padding: 15px;
|
|
||||||
position: absolute;
|
|
||||||
inset-inline-end: 0;
|
|
||||||
top: -48px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.switch-to-advanced {
|
.switch-to-advanced {
|
||||||
color: $light-text-color;
|
color: $light-text-color;
|
||||||
background-color: $ui-base-color;
|
background-color: $ui-base-color;
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import type { PropsWithChildren } from 'react';
|
||||||
|
import { Component } from 'react';
|
||||||
|
|
||||||
|
import { IntlProvider } from 'react-intl';
|
||||||
|
|
||||||
|
import { MemoryRouter } from 'react-router';
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
|
import { render as rtlRender } from '@testing-library/react';
|
||||||
|
|
||||||
|
class FakeIdentityWrapper extends Component<
|
||||||
|
PropsWithChildren<{ signedIn: boolean }>
|
||||||
|
> {
|
||||||
|
static childContextTypes = {
|
||||||
|
identity: PropTypes.shape({
|
||||||
|
signedIn: PropTypes.bool.isRequired,
|
||||||
|
accountId: PropTypes.string,
|
||||||
|
disabledAccountId: PropTypes.string,
|
||||||
|
accessToken: PropTypes.string,
|
||||||
|
}).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
getChildContext() {
|
||||||
|
return {
|
||||||
|
identity: {
|
||||||
|
signedIn: this.props.signedIn,
|
||||||
|
accountId: '123',
|
||||||
|
accessToken: 'test-access-token',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return this.props.children;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function render(
|
||||||
|
ui: React.ReactElement,
|
||||||
|
{ locale = 'en', signedIn = true, ...renderOptions } = {},
|
||||||
|
) {
|
||||||
|
const Wrapper = (props: { children: React.ReactElement }) => {
|
||||||
|
return (
|
||||||
|
<MemoryRouter>
|
||||||
|
<IntlProvider locale={locale}>
|
||||||
|
<FakeIdentityWrapper signedIn={signedIn}>
|
||||||
|
{props.children}
|
||||||
|
</FakeIdentityWrapper>
|
||||||
|
</IntlProvider>
|
||||||
|
</MemoryRouter>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
return rtlRender(ui, { wrapper: Wrapper, ...renderOptions });
|
||||||
|
}
|
||||||
|
|
||||||
|
// re-export everything
|
||||||
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
|
export * from '@testing-library/react';
|
||||||
|
|
||||||
|
// override render method
|
||||||
|
export { render };
|
Loading…
Reference in New Issue