Skip to content

Commit

Permalink
Remove global boosts state and convert boosts modal to Typescript
Browse files Browse the repository at this point in the history
The state was only used in the boosts modal, so we can use a local state here
  • Loading branch information
renchap committed Mar 27, 2024
1 parent d49343e commit 0e63eae
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 183 deletions.
32 changes: 0 additions & 32 deletions app/javascript/mastodon/actions/boosts.js

This file was deleted.

6 changes: 3 additions & 3 deletions app/javascript/mastodon/components/button.tsx
Expand Up @@ -5,16 +5,16 @@ import classNames from 'classnames';
interface BaseProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
block?: boolean;
secondary?: boolean;
text?: JSX.Element;
text?: JSX.Element | string;
}

interface PropsWithChildren extends BaseProps {
text?: never;
}

interface PropsWithText extends BaseProps {
text: JSX.Element;
children: never;
text: JSX.Element | string;
children?: never;
}

type Props = PropsWithText | PropsWithChildren;
Expand Down
15 changes: 8 additions & 7 deletions app/javascript/mastodon/components/relative_timestamp.tsx
Expand Up @@ -191,7 +191,7 @@ const timeRemainingString = (
interface Props {
intl: IntlShape;
timestamp: string;
year: number;
year?: number;
futureDate?: boolean;
short?: boolean;
}
Expand All @@ -203,11 +203,6 @@ class RelativeTimestamp extends Component<Props, States> {
now: Date.now(),
};

static defaultProps = {
year: new Date().getFullYear(),
short: true,
};

_timer: number | undefined;

shouldComponentUpdate(nextProps: Props, nextState: States) {
Expand Down Expand Up @@ -257,7 +252,13 @@ class RelativeTimestamp extends Component<Props, States> {
}

render() {
const { timestamp, intl, year, futureDate, short } = this.props;
const {
timestamp,
intl,
year = new Date().getFullYear(),
futureDate,
short = true,
} = this.props;

const timeGiven = timestamp.includes('T');
const date = new Date(timestamp);
Expand Down
5 changes: 2 additions & 3 deletions app/javascript/mastodon/components/visibility_icon.tsx
Expand Up @@ -4,11 +4,10 @@ import AlternateEmailIcon from '@/material-icons/400-24px/alternate_email.svg?re
import LockIcon from '@/material-icons/400-24px/lock.svg?react';
import PublicIcon from '@/material-icons/400-24px/public.svg?react';
import QuietTimeIcon from '@/material-icons/400-24px/quiet_time.svg?react';
import type { StatusVisibility } from 'mastodon/models/status';

import { Icon } from './icon';

type Visibility = 'public' | 'unlisted' | 'private' | 'direct';

const messages = defineMessages({
public_short: { id: 'privacy.public.short', defaultMessage: 'Public' },
unlisted_short: {
Expand All @@ -25,7 +24,7 @@ const messages = defineMessages({
},
});

export const VisibilityIcon: React.FC<{ visibility: Visibility }> = ({
export const VisibilityIcon: React.FC<{ visibility: StatusVisibility }> = ({
visibility,
}) => {
const intl = useIntl();
Expand Down
3 changes: 1 addition & 2 deletions app/javascript/mastodon/containers/status_container.jsx
Expand Up @@ -8,7 +8,6 @@ import {
} from '../actions/accounts';
import { showAlertForError } from '../actions/alerts';
import { initBlockModal } from '../actions/blocks';
import { initBoostModal } from '../actions/boosts';
import {
replyCompose,
mentionCompose,
Expand Down Expand Up @@ -107,7 +106,7 @@ const mapDispatchToProps = (dispatch, { intl, contextType }) => ({
if ((e && e.shiftKey) || !boostModal) {
this.onModalReblog(status);
} else {
dispatch(initBoostModal({ status, onReblog: this.onModalReblog }));
dispatch(openModal({ modalType: 'BOOST', modalProps: { status, onReblog: this.onModalReblog } }));
}
},

Expand Down
@@ -1,13 +1,13 @@
import { connect } from 'react-redux';

import { initBoostModal } from '../../../actions/boosts';
import { mentionCompose } from '../../../actions/compose';
import {
reblog,
favourite,
unreblog,
unfavourite,
} from '../../../actions/interactions';
import { openModal } from '../../../actions/modal';
import {
hideStatus,
revealStatus,
Expand Down Expand Up @@ -49,7 +49,7 @@ const mapDispatchToProps = dispatch => ({
if (e.shiftKey || !boostModal) {
this.onModalReblog(status);
} else {
dispatch(initBoostModal({ status, onReblog: this.onModalReblog }));
dispatch(openModal({ modalType: 'BOOST', modalProps: { status, onReblog: this.onModalReblog } }));
}
}
},
Expand Down
Expand Up @@ -14,7 +14,6 @@ import RepeatIcon from '@/material-icons/400-24px/repeat.svg?react';
import ReplyIcon from '@/material-icons/400-24px/reply.svg?react';
import ReplyAllIcon from '@/material-icons/400-24px/reply_all.svg?react';
import StarIcon from '@/material-icons/400-24px/star.svg?react';
import { initBoostModal } from 'mastodon/actions/boosts';
import { replyCompose } from 'mastodon/actions/compose';
import { reblog, favourite, unreblog, unfavourite } from 'mastodon/actions/interactions';
import { openModal } from 'mastodon/actions/modal';
Expand Down Expand Up @@ -140,7 +139,7 @@ class Footer extends ImmutablePureComponent {
} else if ((e && e.shiftKey) || !boostModal) {
this._performReblog(status);
} else {
dispatch(initBoostModal({ status, onReblog: this._performReblog }));
dispatch(openModal({ modalType: 'BOOST', modalProps: { status, onReblog: this._performReblog } }));
}
} else {
dispatch(openModal({
Expand Down
Expand Up @@ -4,7 +4,6 @@ import { connect } from 'react-redux';

import { showAlertForError } from '../../../actions/alerts';
import { initBlockModal } from '../../../actions/blocks';
import { initBoostModal } from '../../../actions/boosts';
import {
replyCompose,
mentionCompose,
Expand Down Expand Up @@ -85,7 +84,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
if (e.shiftKey || !boostModal) {
this.onModalReblog(status);
} else {
dispatch(initBoostModal({ status, onReblog: this.onModalReblog }));
dispatch(openModal({ modalType: 'BOOST', modalProps: { status, onReblog: this.onModalReblog } }));
}
}
},
Expand Down
3 changes: 1 addition & 2 deletions app/javascript/mastodon/features/status/index.jsx
Expand Up @@ -27,7 +27,6 @@ import {
unmuteAccount,
} from '../../actions/accounts';
import { initBlockModal } from '../../actions/blocks';
import { initBoostModal } from '../../actions/boosts';
import {
replyCompose,
mentionCompose,
Expand Down Expand Up @@ -317,7 +316,7 @@ class Status extends ImmutablePureComponent {
if ((e && e.shiftKey) || !boostModal) {
this.handleModalReblog(status);
} else {
dispatch(initBoostModal({ status, onReblog: this.handleModalReblog }));
dispatch(openModal({ modalType: 'BOOST', modalProps: { status, onReblog: this.handleModalReblog } }));
}
}
} else {
Expand Down
125 changes: 0 additions & 125 deletions app/javascript/mastodon/features/ui/components/boost_modal.jsx

This file was deleted.

0 comments on commit 0e63eae

Please sign in to comment.