Merge branch 'tsx-conversions' into 'develop'

TSX conversions

See merge request soapbox-pub/soapbox-fe!1495
dnd
Alex Gleason 2022-06-06 18:57:06 +00:00
commit ddd0cc2d27
5 zmienionych plików z 132 dodań i 207 usunięć

Wyświetl plik

@ -30,7 +30,7 @@ const Sidebar: React.FC = ({ children }) => (
const Main: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({ children, className }) => ( const Main: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({ children, className }) => (
<main <main
className={classNames({ className={classNames({
'md:col-span-12 lg:col-span-9 xl:col-span-6 sm:space-y-4 pb-36': true, 'md:col-span-12 lg:col-span-9 xl:col-span-6 pb-36': true,
}, className)} }, className)}
> >
{children} {children}

Wyświetl plik

@ -1,130 +0,0 @@
import { OrderedSet as ImmutableOrderedSet } from 'immutable';
import PropTypes from 'prop-types';
import React from 'react';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import BundleContainer from 'soapbox/features/ui/containers/bundle_container';
import { getFeatures } from 'soapbox/utils/features';
import { expandHomeTimeline } from '../../actions/timelines';
import { Column } from '../../components/ui';
import Timeline from '../ui/components/timeline';
function FollowRecommendationsContainer() {
return import(/* webpackChunkName: "features/follow_recommendations" */'soapbox/features/follow_recommendations/components/follow_recommendations_container');
}
const messages = defineMessages({
title: { id: 'column.home', defaultMessage: 'Home' },
});
const mapStateToProps = state => {
const instance = state.get('instance');
const features = getFeatures(instance);
return {
hasUnread: state.getIn(['timelines', 'home', 'unread']) > 0,
isPartial: state.getIn(['timelines', 'home', 'isPartial']),
siteTitle: state.getIn(['instance', 'title']),
isLoading: state.getIn(['timelines', 'home', 'isLoading'], true),
loadingFailed: state.getIn(['timelines', 'home', 'loadingFailed'], false),
isEmpty: state.getIn(['timelines', 'home', 'items'], ImmutableOrderedSet()).isEmpty(),
features,
};
};
export default @connect(mapStateToProps)
@injectIntl
class HomeTimeline extends React.PureComponent {
static propTypes = {
dispatch: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
hasUnread: PropTypes.bool,
isPartial: PropTypes.bool,
siteTitle: PropTypes.string,
isLoading: PropTypes.bool,
loadingFailed: PropTypes.bool,
isEmpty: PropTypes.bool,
features: PropTypes.object.isRequired,
};
state = {
done: false,
}
handleLoadMore = maxId => {
this.props.dispatch(expandHomeTimeline({ maxId }));
}
componentDidMount() {
this._checkIfReloadNeeded(false, this.props.isPartial);
}
componentDidUpdate(prevProps) {
this._checkIfReloadNeeded(prevProps.isPartial, this.props.isPartial);
}
componentWillUnmount() {
this._stopPolling();
}
_checkIfReloadNeeded(wasPartial, isPartial) {
const { dispatch } = this.props;
if (wasPartial === isPartial) {
return;
} else if (!wasPartial && isPartial) {
this.polling = setInterval(() => {
dispatch(expandHomeTimeline());
}, 3000);
} else if (wasPartial && !isPartial) {
this._stopPolling();
}
}
_stopPolling() {
if (this.polling) {
clearInterval(this.polling);
this.polling = null;
}
}
handleDone = e => {
this.props.dispatch(expandHomeTimeline());
this.setState({ done: true });
}
handleRefresh = () => {
const { dispatch } = this.props;
return dispatch(expandHomeTimeline());
}
render() {
const { intl, siteTitle, isLoading, loadingFailed, isEmpty, features } = this.props;
const { done } = this.state;
const showSuggestions = features.suggestions && isEmpty && !isLoading && !loadingFailed && !done;
return (
<Column label={intl.formatMessage(messages.title)} transparent={!showSuggestions}>
{showSuggestions ? (
<BundleContainer fetchComponent={FollowRecommendationsContainer}>
{Component => <Component onDone={this.handleDone} />}
</BundleContainer>
) : (
<Timeline
scrollKey='home_timeline'
onLoadMore={this.handleLoadMore}
onRefresh={this.handleRefresh}
timelineId='home'
divideType='space'
emptyMessage={<FormattedMessage id='empty_column.home' defaultMessage='Your home timeline is empty! Visit {public} to get started and meet other users.' values={{ public: <Link to='/timeline/local'><FormattedMessage id='empty_column.home.local_tab' defaultMessage='the {site_title} tab' values={{ site_title: siteTitle }} /></Link> }} />}
/>
)}
</Column>
);
}
}

Wyświetl plik

@ -0,0 +1,71 @@
import React, { useEffect, useRef } from 'react';
import { defineMessages, useIntl, FormattedMessage } from 'react-intl';
import { Link } from 'react-router-dom';
import { expandHomeTimeline } from 'soapbox/actions/timelines';
import { Column } from 'soapbox/components/ui';
import Timeline from 'soapbox/features/ui/components/timeline';
import { useAppSelector, useAppDispatch } from 'soapbox/hooks';
const messages = defineMessages({
title: { id: 'column.home', defaultMessage: 'Home' },
});
const HomeTimeline: React.FC = () => {
const intl = useIntl();
const dispatch = useAppDispatch();
const polling = useRef<NodeJS.Timer | null>(null);
const isPartial = useAppSelector(state => state.timelines.getIn(['home', 'isPartial']) === true);
const siteTitle = useAppSelector(state => state.instance.title);
const handleLoadMore = (maxId: string) => {
dispatch(expandHomeTimeline({ maxId }));
};
// Mastodon generates the feed in Redis, and can return a partial timeline
// (HTTP 206) for new users. Poll until we get a full page of results.
const checkIfReloadNeeded = () => {
if (isPartial) {
polling.current = setInterval(() => {
dispatch(expandHomeTimeline());
}, 3000);
} else {
stopPolling();
}
};
const stopPolling = () => {
if (polling.current) {
clearInterval(polling.current);
polling.current = null;
}
};
const handleRefresh = () => {
return dispatch(expandHomeTimeline());
};
useEffect(() => {
checkIfReloadNeeded();
return () => {
stopPolling();
};
}, [isPartial]);
return (
<Column label={intl.formatMessage(messages.title)} transparent>
<Timeline
scrollKey='home_timeline'
onLoadMore={handleLoadMore}
onRefresh={handleRefresh}
timelineId='home'
divideType='space'
emptyMessage={<FormattedMessage id='empty_column.home' defaultMessage='Your home timeline is empty! Visit {public} to get started and meet other users.' values={{ public: <Link to='/timeline/local'><FormattedMessage id='empty_column.home.local_tab' defaultMessage='the {site_title} tab' values={{ site_title: siteTitle }} /></Link> }} />}
/>
</Column>
);
};
export default HomeTimeline;

Wyświetl plik

@ -1,9 +1,7 @@
import classNames from 'classnames'; import classNames from 'classnames';
import { History } from 'history';
import React from 'react'; import React from 'react';
import ImmutablePureComponent from 'react-immutable-pure-component'; import { defineMessages, useIntl, FormattedMessage, FormattedList } from 'react-intl';
import { defineMessages, injectIntl, FormattedMessage, IntlShape, FormattedList } from 'react-intl'; import { useHistory } from 'react-router-dom';
import { withRouter } from 'react-router-dom';
import StatusMedia from 'soapbox/components/status-media'; import StatusMedia from 'soapbox/components/status-media';
import { Stack, Text } from 'soapbox/components/ui'; import { Stack, Text } from 'soapbox/components/ui';
@ -16,49 +14,42 @@ const messages = defineMessages({
}); });
interface IQuotedStatus { interface IQuotedStatus {
/** The quoted status entity. */
status?: StatusEntity, status?: StatusEntity,
/** Callback when cancelled (during compose). */
onCancel?: Function, onCancel?: Function,
intl: IntlShape, /** Whether the status is shown in the post composer. */
compose?: boolean, compose?: boolean,
history: History,
} }
class QuotedStatus extends ImmutablePureComponent<IQuotedStatus> { /** Status embedded in a quote post. */
const QuotedStatus: React.FC<IQuotedStatus> = ({ status, onCancel, compose }) => {
handleExpandClick = (e: React.MouseEvent<HTMLDivElement>) => { const intl = useIntl();
const { compose, status } = this.props; const history = useHistory();
const handleExpandClick = (e: React.MouseEvent<HTMLDivElement>) => {
if (!status) return; if (!status) return;
const account = status.account as AccountEntity; const account = status.account as AccountEntity;
if (!compose && e.button === 0) { if (!compose && e.button === 0) {
if (!this.props.history) { history.push(`/@${account.acct}/posts/${status.id}`);
return;
}
this.props.history.push(`/@${account.acct}/posts/${status.id}`);
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
} }
} };
handleClose = () => { const handleClose = () => {
if (this.props.onCancel) { if (onCancel) {
this.props.onCancel(); onCancel();
} }
} };
renderReplyMentions = () => {
const { status } = this.props;
const renderReplyMentions = () => {
if (!status?.in_reply_to_id) { if (!status?.in_reply_to_id) {
return null; return null;
} }
const account = status.account as AccountEntity; const account = status.account as AccountEntity;
const to = status.mentions || []; const to = status.mentions || [];
if (to.size === 0) { if (to.size === 0) {
@ -102,58 +93,51 @@ class QuotedStatus extends ImmutablePureComponent<IQuotedStatus> {
/> />
</div> </div>
); );
};
if (!status) {
return null;
} }
render() { const account = status.account as AccountEntity;
const { status, onCancel, intl, compose } = this.props;
if (!status) { let actions = {};
return null; if (onCancel) {
} actions = {
onActionClick: handleClose,
const account = status.account as AccountEntity; actionIcon: require('@tabler/icons/icons/x.svg'),
actionAlignment: 'top',
let actions = {}; actionTitle: intl.formatMessage(messages.cancel),
if (onCancel) { };
actions = {
onActionClick: this.handleClose,
actionIcon: require('@tabler/icons/icons/x.svg'),
actionAlignment: 'top',
actionTitle: intl.formatMessage(messages.cancel),
};
}
const quotedStatus = (
<Stack
space={2}
className={classNames('mt-3 p-4 rounded-lg border border-solid border-gray-100 dark:border-slate-700 cursor-pointer', {
'hover:bg-gray-50 dark:hover:bg-slate-700': !compose,
})}
onClick={this.handleExpandClick}
>
<AccountContainer
{...actions}
id={account.id}
timestamp={status.created_at}
withRelationship={false}
showProfileHoverCard={!compose}
/>
{this.renderReplyMentions()}
<Text
className='break-words'
size='sm'
dangerouslySetInnerHTML={{ __html: status.contentHtml }}
/>
<StatusMedia status={status} />
</Stack>
);
return quotedStatus;
} }
} return (
<Stack
space={2}
className={classNames('mt-3 p-4 rounded-lg border border-solid border-gray-100 dark:border-slate-700 cursor-pointer', {
'hover:bg-gray-50 dark:hover:bg-slate-700': !compose,
})}
onClick={handleExpandClick}
>
<AccountContainer
{...actions}
id={account.id}
timestamp={status.created_at}
withRelationship={false}
showProfileHoverCard={!compose}
/>
export default withRouter(injectIntl(QuotedStatus) as any); {renderReplyMentions()}
<Text
className='break-words'
size='sm'
dangerouslySetInnerHTML={{ __html: status.contentHtml }}
/>
<StatusMedia status={status} />
</Stack>
);
};
export default QuotedStatus;

Wyświetl plik

@ -36,7 +36,7 @@ const HomePage: React.FC = ({ children }) => {
return ( return (
<> <>
<Layout.Main className='pt-4 sm:pt-0 dark:divide-slate-700 space-y-4'> <Layout.Main className='pt-3 sm:pt-0 dark:divide-slate-700 space-y-3'>
{me && ( {me && (
<Card variant='rounded' ref={composeBlock}> <Card variant='rounded' ref={composeBlock}>
<CardBody> <CardBody>