Skip to content

Commit

Permalink
Fix linting problems
Browse files Browse the repository at this point in the history
- Lots from mathtex being coded in a shitty olde javascript style
- Fix one use of "favourite" that is still in upstream
- Revert changes to add exclusive to lists migrations - rails 7 wants us to do it in a different way, but upstream is still using 6.1, so undo those changes and use the masto migration helpers instead to match upstream behavior
- fix repeated tests in exclusive lists spec
  • Loading branch information
sneakers-the-rat committed Oct 8, 2023
1 parent 4ed02ee commit 9c2f74f
Show file tree
Hide file tree
Showing 33 changed files with 222 additions and 228 deletions.
5 changes: 3 additions & 2 deletions app/javascript/flavours/glitch/actions/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import { tagHistory } from 'flavours/glitch/settings';
import { recoverHashtags } from 'flavours/glitch/utils/hashtag';
import resizeImage from 'flavours/glitch/utils/resize_image';

import { tex_to_unicode } from '../features/compose/util/autolatex/autolatex';

import { showAlert, showAlertForError } from './alerts';
import { useEmoji } from './emojis';
import { importFetchedAccounts, importFetchedStatus } from './importer';
import { openModal } from './modal';
import { updateTimeline } from './timelines';
import { tex_to_unicode } from '../features/compose/util/autolatex/autolatex.js';

/** @type {AbortController | undefined} */
let fetchComposeSuggestionsAccountsController;
Expand Down Expand Up @@ -570,7 +571,7 @@ const fetchComposeSuggestionsAccounts = throttle((dispatch, getState, token) =>
const fetchComposeSuggestionsLatex = (dispatch, getState, token) => {
const start_delimiter = token.slice(0,2);
const end_delimiter = {'\\(': '\\)', '\\[': '\\]'}[start_delimiter];
let expression = token.slice(2).replace(/\\[\)\]]?$/,'');
let expression = token.slice(2).replace(/\\[)\]]?$/,'');
let brace = 0;
for(let i=0;i<expression.length;i++) {
switch(expression[i]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';

const assetHost = process.env.CDN_HOST || '';
import React from 'react';

export default class AutosuggestLatex extends React.PureComponent {

Expand All @@ -15,6 +13,9 @@ export default class AutosuggestLatex extends React.PureComponent {

componentDidMount() {
try {
// Loaded in script tag on page. not great but we couldn't figure out
// How to use MathJax as a module
// eslint-disable-next-line no-undef
MathJax.typeset([this.node]);
} catch(e) {
console.error(e);
Expand All @@ -28,7 +29,7 @@ export default class AutosuggestLatex extends React.PureComponent {
return (
<div className='autosuggest-latex' ref={this.setRef}>
\({latex.expression}\)
<br/>
<br />
<small>Convert to unicode</small>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const textAtCursorMatchesToken = (str, caretPosition) => {
let left;
let right;

left = str.slice(0, caretPosition).search(/\\[\(\[](?:(?!\\[\)\]]).)*(?:\\[\)\]])?$/);
left = str.slice(0, caretPosition).search(/\\[([](?:(?!\\[)\]]).)*(?:\\[)\]])?$/);
if (left >= 0) {
right = str.slice(caretPosition).search(/\\[\)\]]/);
right = str.slice(caretPosition).search(/\\[)\]]/);
if (right < 0) {
word = str.slice(left);
} else {
Expand Down
4 changes: 3 additions & 1 deletion app/javascript/flavours/glitch/components/status.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import classNames from 'classnames';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';

import { HotKeys } from 'react-hotkeys';

import PictureInPicturePlaceholder from 'flavours/glitch/components/picture_in_picture_placeholder';
import PollContainer from 'flavours/glitch/containers/poll_container';
import NotificationOverlayContainer from 'flavours/glitch/features/notifications/containers/overlay_container';
import { displayMedia } from 'flavours/glitch/initial_state';
import { autoUnfoldCW } from 'flavours/glitch/utils/content_warning';
import { HotKeys } from 'react-hotkeys';

import Card from '../features/status/components/card';
import Bundle from '../features/ui/components/bundle';
Expand All @@ -24,6 +25,7 @@ import StatusContent from './status_content';
import StatusExpandButton from './status_expand_button';
import StatusHeader from './status_header';
import StatusIcons from './status_icons';
import StatusPrepend from './status_prepend';

const domParser = new DOMParser();

Expand Down
9 changes: 6 additions & 3 deletions app/javascript/flavours/glitch/components/status_content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import classnames from 'classnames';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { connect } from 'react-redux';

import { Icon } from 'flavours/glitch/components/icon';
import { autoPlayGif, languages as preloadedLanguages } from 'flavours/glitch/initial_state';
import { decode as decodeIDNA } from 'flavours/glitch/utils/idna';
import StatusExpandButton from './status_expand_button';

import Permalink from './permalink';
import StatusExpandButton from './status_expand_button';


const textMatchesTarget = (text, origin, host) => {
return (text === origin || text === host
Expand Down Expand Up @@ -239,11 +239,14 @@ class StatusContent extends PureComponent {
_renderMathJax() {
const {status} = this.props;
const contentHtml = status.get('contentHtml');
if(this.last_contentHtml == contentHtml) {
if(this.last_contentHtml === contentHtml) {
return;
}
this.last_contentHtml = contentHtml;
try {
// Loaded in script tag on page. not great but we couldn't figure out
// How to use MathJax as a module
// eslint-disable-next-line no-undef
MathJax.typeset([this.contentsNode]);
} catch(e) {
console.error(e);
Expand Down
71 changes: 0 additions & 71 deletions app/javascript/flavours/glitch/components/status_expand_button.js

This file was deleted.

73 changes: 73 additions & 0 deletions app/javascript/flavours/glitch/components/status_expand_button.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import PropTypes from 'prop-types';
import React, { useState, useEffect } from 'react';

import { FormattedMessage } from 'react-intl';

import { Icon } from './icon';

const makeToggleText = (hidden, mediaIcons) => {
let newText;
if (hidden) {
newText = [
<FormattedMessage
id='status.show_more'
defaultMessage='Show more'
key='0'
/>,
];
if (mediaIcons) {
mediaIcons.forEach((mediaIcon, idx) => {
newText.push(
<Icon
fixedWidth
className='status__content__spoiler-icon'
id={mediaIcon}
aria-hidden='true'
key={`icon-${idx}`}
/>,
);
});
}
} else {
newText = (
<FormattedMessage
id='status.show_less'
defaultMessage='Show less'
key='0'
/>
);
}
return(newText);
};

const StatusExpandButton=(
{
hidden,
handleSpoilerClick,
mediaIcons,
},
)=>{


// const [hidden, setHidden] = useState(false);
const [toggleText, setToggleText] = useState(makeToggleText());

// Change the text when the hidden state changes
useEffect(() => {
setToggleText(makeToggleText(hidden, mediaIcons));
}, [hidden, mediaIcons]);

return(
<button type='button' className='status__content__spoiler-link' onClick={handleSpoilerClick} aria-expanded={!hidden}>
{toggleText}
</button>
);
};

StatusExpandButton.propTypes = {
hidden: PropTypes.bool,
handleSpoilerClick: PropTypes.func,
mediaIcons: PropTypes.arrayOf(PropTypes.string),
};

export default StatusExpandButton;
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import React from 'react';
import PropTypes from 'prop-types';
import React from 'react';

import { injectIntl, defineMessages } from 'react-intl';
import IconButton from '../../../components/icon_button';

import classNames from 'classnames';

import { supportsPassiveEvents } from 'detect-passive-events';
import spring from 'react-motion/lib/spring';
import Overlay from 'react-overlays/Overlay';

import { Icon } from 'flavours/glitch/components/icon';
import { assetHost } from 'flavours/glitch/utils/config';

import Motion from '../../ui/util/optional_motion';
import spring from 'react-motion/lib/spring';
import { supportsPassiveEvents } from 'detect-passive-events';
import classNames from 'classnames';
import { Icon } from 'mastodon/components/icon';
import { assetHost } from 'mastodon/utils/config';

const messages = defineMessages({
inline_short: { id: 'latex.inline.short', defaultMessage: 'Inline' },
Expand All @@ -28,6 +32,7 @@ class LaTeXDropdownMenu extends React.PureComponent {
placement: PropTypes.string.isRequired,
onClose: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
value: PropTypes.any
};

state = {
Expand Down Expand Up @@ -161,6 +166,7 @@ class LaTeXDropdown extends React.PureComponent {
disabled: PropTypes.bool,
intl: PropTypes.object.isRequired,
button: PropTypes.node,
value: PropTypes.any
};

state = {
Expand Down Expand Up @@ -249,7 +255,7 @@ class LaTeXDropdown extends React.PureComponent {
};

render () {
const { value, container, disabled, intl, button } = this.props;
const { container, intl, button } = this.props;
const { open, placement } = this.state;

const title = intl.formatMessage(messages.start_latex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { connect } from 'react-redux';
import LaTeXDropdown from '../components/latex_dropdown';
import { startLaTeXCompose } from '../../../actions/compose';

import { openModal, closeModal } from '../../../actions/modal';
import { isUserTouching } from '../../../is_mobile';
import LaTeXDropdown from '../components/latex_dropdown';

const mapStateToProps = state => ({
value: state.getIn(['compose', 'startlatex']),
Expand Down
Loading

0 comments on commit 9c2f74f

Please sign in to comment.