Skip to content

Commit

Permalink
fix: add ignore eslint statements
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperhodge committed May 9, 2023
1 parent a41758d commit 1a44b40
Show file tree
Hide file tree
Showing 29 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import * as module from './hooks';
export const { navigateCallback } = textEditorHooks;

export const state = {
// eslint-disable-next-line react-hooks/rules-of-hooks
localTitle: (args) => React.useState(args),
};

export const hooks = {
isEditing: () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const [isEditing, setIsEditing] = React.useState(false);
return {
isEditing,
Expand All @@ -22,6 +24,7 @@ export const hooks = {
},

localTitle: ({ dispatch, stopEditing }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const title = useSelector(selectors.app.displayTitle);
const [localTitle, setLocalTitle] = module.state.localTitle(title);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export const TitleHeader = ({
intl,
}) => {
if (!isInitialized) { return intl.formatMessage(messages.loading); }
// eslint-disable-next-line react-hooks/rules-of-hooks
const dispatch = useDispatch();
// eslint-disable-next-line react-hooks/rules-of-hooks
const title = useSelector(selectors.app.displayTitle);

const {
Expand Down
7 changes: 7 additions & 0 deletions src/editors/containers/EditorContainer/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ export const {
} = appHooks;

export const state = StrictDict({
// eslint-disable-next-line react-hooks/rules-of-hooks
isCancelConfirmModalOpen: (val) => useState(val),
});

export const handleSaveClicked = ({ dispatch, getContent, validateEntry }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const destination = useSelector(selectors.app.returnUrl);
// eslint-disable-next-line react-hooks/rules-of-hooks
const analytics = useSelector(selectors.app.analytics);

return () => saveBlock({
Expand All @@ -46,14 +49,18 @@ export const handleCancel = ({ onClose }) => {
return onClose;
}
return navigateCallback({
// eslint-disable-next-line react-hooks/rules-of-hooks
destination: useSelector(selectors.app.returnUrl),
analyticsEvent: analyticsEvt.editorCancelClick,
// eslint-disable-next-line react-hooks/rules-of-hooks
analytics: useSelector(selectors.app.analytics),
});
};

// eslint-disable-next-line react-hooks/rules-of-hooks
export const isInitialized = () => useSelector(selectors.app.isInitialized);

// eslint-disable-next-line react-hooks/rules-of-hooks
export const saveFailed = () => useSelector((rootState) => (
selectors.requests.isFailed(rootState, { requestKey: RequestKeys.saveBlock })
));
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ProblemTypeKeys } from '../../../../../data/constants/problem';
import { fetchEditorContent } from '../hooks';

export const state = StrictDict({
// eslint-disable-next-line react-hooks/rules-of-hooks
isFeedbackVisible: (val) => useState(val),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import { ProblemTypeKeys, ProblemTypes, ShowAnswerTypesKeys } from '../../../../
import { fetchEditorContent } from '../hooks';

export const state = {
// eslint-disable-next-line react-hooks/rules-of-hooks
showAdvanced: (val) => useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
cardCollapsed: (val) => useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
summary: (val) => useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
showAttempts: (val) => useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
attemptDisplayValue: (val) => useState(val),
};

Expand Down Expand Up @@ -39,6 +44,7 @@ export const showFullCard = (hasExpandableTextArea) => {
export const hintsCardHooks = (hints, updateSettings) => {
const [summary, setSummary] = module.state.summary({ message: messages.noHintSummary, values: {} });

// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
const hintsNumber = hints.length;
if (hintsNumber === 0) {
Expand Down Expand Up @@ -89,6 +95,7 @@ export const hintsRowHooks = (id, hints, updateSettings) => {
export const matlabCardHooks = (matLabApiKey, updateSettings) => {
const [summary, setSummary] = module.state.summary({ message: '', values: {}, intl: false });

// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
if (_.isEmpty(matLabApiKey)) {
setSummary({ message: messages.matlabNoKeySummary, values: {}, intl: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import messages from './messages';
import * as module from './hooks';

export const state = {
// eslint-disable-next-line react-hooks/rules-of-hooks
summary: (val) => useState(val),
};

Expand All @@ -12,6 +13,7 @@ export const generalFeedbackHooks = (generalFeedback, updateSettings) => {
message: messages.noGeneralFeedbackSummary, values: {}, intl: true,
});

// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
if (_.isEmpty(generalFeedback)) {
setSummary({ message: messages.noGeneralFeedbackSummary, values: {}, intl: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import messages from './messages';
import * as module from './hooks';

export const state = {
// eslint-disable-next-line react-hooks/rules-of-hooks
summary: (val) => useState(val),
};

export const groupFeedbackCardHooks = (groupFeedbacks, updateSettings, answerslist) => {
const [summary, setSummary] = module.state.summary({ message: messages.noGroupFeedbackSummary, values: {} });

// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
if (groupFeedbacks.length === 0) {
setSummary({ message: messages.noGroupFeedbackSummary, values: {} });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RandomizationTypes, RandomizationTypesKeys } from '../../../../../../..
import * as module from './hooks';

export const state = {
// eslint-disable-next-line react-hooks/rules-of-hooks
summary: (val) => useState(val),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { setAssetToStaticUrl } from '../../../../sharedComponents/TinyMceWidget/
import { ProblemTypeKeys } from '../../../../data/constants/problem';

export const state = StrictDict({
// eslint-disable-next-line react-hooks/rules-of-hooks
isNoAnswerModalOpen: (val) => useState(val),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as module from './hooks';
import { getDataFromOlx } from '../../../../data/redux/thunkActions/problem';

export const state = StrictDict({
// eslint-disable-next-line react-hooks/rules-of-hooks
selected: (val) => useState(val),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import * as module from './SelectVideoModal';

export const hooks = {
videoList: ({ fetchVideos }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const [videos, setVideos] = React.useState(null);
// eslint-disable-next-line react-hooks/rules-of-hooks
React.useEffect(() => {
fetchVideos({ onSuccess: setVideos });
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as module from './VideoEditorModal';

export const hooks = {
initialize: (dispatch) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
React.useEffect(() => {
dispatch(thunkActions.video.loadVideoData());
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ const durationMatcher = /^(\d{0,2}):?(\d{0,2})?:?(\d{0,2})?$/i;
export const durationWidget = ({ duration, updateField }) => {
const setDuration = (val) => updateField({ duration: val });
const initialState = module.durationString(duration);
// eslint-disable-next-line react-hooks/rules-of-hooks
const [unsavedDuration, setUnsavedDuration] = useState(initialState);

// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
setUnsavedDuration(module.durationString(duration));
}, [duration]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { thunkActions } from '../../../../../../data/redux';
import * as module from './hooks';

export const state = {
// eslint-disable-next-line react-hooks/rules-of-hooks
showSizeError: (args) => React.useState(args),
};

Expand All @@ -28,7 +29,9 @@ export const checkValidFileSize = ({
};

export const fileInput = ({ fileSizeError }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const dispatch = useDispatch();
// eslint-disable-next-line react-hooks/rules-of-hooks
const ref = React.useRef();
const click = () => ref.current.click();
const addFile = (e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as constants from './constants';
import * as module from './hooks';

export const state = {
// eslint-disable-next-line react-hooks/rules-of-hooks
showSizeError: (args) => React.useState(args),
};

Expand Down Expand Up @@ -85,7 +86,9 @@ export const checkValidSize = ({ file, onSizeFail }) => {
};

export const fileInput = ({ setThumbnailSrc, imgRef, fileSizeError }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const dispatch = useDispatch();
// eslint-disable-next-line react-hooks/rules-of-hooks
const ref = React.useRef();
const click = () => ref.current.click();
const addFile = (e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import messages from './messages';

export const hooks = {
state: {
// eslint-disable-next-line react-hooks/rules-of-hooks
inDeleteConfirmation: (args) => React.useState(args),
},
setUpDeleteConfirmation: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import * as module from './index';

export const hooks = {
updateErrors: ({ isUploadError, isDeleteError }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const [error, setError] = React.useContext(ErrorContext).transcripts;
if (isUploadError) {
setError({ ...error, uploadError: messages.uploadTranscriptError.defaultMessage });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { parseYoutubeId } from '../../../../../../data/services/cms/api';
import * as requests from '../../../../../../data/redux/thunkActions/requests';

export const state = {
// eslint-disable-next-line react-hooks/rules-of-hooks
showVideoIdChangeAlert: (args) => React.useState(args),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const updatedObject = (obj, index, val) => ({ ...obj, [index]: val });
* @param {string} key - form key
* @return {func} - callback taking a value and updating the video redux field
*/
// eslint-disable-next-line react-hooks/rules-of-hooks
export const updateFormField = ({ dispatch, key }) => useCallback(
(val) => dispatch(actions.video.updateField({ [key]: val })),
[],
Expand All @@ -93,14 +94,17 @@ export const updateFormField = ({ dispatch, key }) => useCallback(
* setAll - sets form field in hook AND redux
*/
export const valueHooks = ({ dispatch, key }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const formValue = useSelector(selectors.video[key]);
const [local, setLocal] = module.state[key](formValue);
const setFormValue = module.updateFormField({ dispatch, key });

// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
setLocal(formValue);
}, [formValue]);

// eslint-disable-next-line react-hooks/rules-of-hooks
const setAll = useCallback(
(val) => {
setLocal(val);
Expand Down
8 changes: 8 additions & 0 deletions src/editors/containers/VideoGallery/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ import {
} from './utils';

export const state = {
// eslint-disable-next-line react-hooks/rules-of-hooks
highlighted: (val) => React.useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
searchString: (val) => React.useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
showSelectVideoError: (val) => React.useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
showSizeError: (val) => React.useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
sortBy: (val) => React.useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
filertBy: (val) => React.useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
hideSelectedVideos: (val) => React.useState(val),
};

Expand Down Expand Up @@ -125,6 +132,7 @@ export const videoListProps = ({ searchSortProps, videos }) => {

export const fileInputProps = () => {
// TODO [Update video] Implement this
// eslint-disable-next-line react-hooks/rules-of-hooks
const ref = React.useRef();
const click = () => ref.current.click();

Expand Down
1 change: 1 addition & 0 deletions src/editors/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { actions, thunkActions } from './data/redux';
import * as module from './hooks';
import { RequestKeys } from './data/constants/requests';

// eslint-disable-next-line react-hooks/rules-of-hooks
export const initializeApp = ({ dispatch, data }) => useEffect(
() => dispatch(thunkActions.app.initialize(data)),
[data],
Expand Down
2 changes: 2 additions & 0 deletions src/editors/sharedComponents/CodeEditor/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import './index.scss';
const CODEMIRROR_LANGUAGES = { HTML: 'html', XML: 'xml' };

export const state = {
// eslint-disable-next-line react-hooks/rules-of-hooks
showBtnEscapeHTML: (val) => React.useState(val),
};

Expand Down Expand Up @@ -60,6 +61,7 @@ export const createCodeMirrorDomNode = ({
upstreamRef,
lang,
}) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
const languageExtension = lang === CODEMIRROR_LANGUAGES.HTML ? html() : xml();
const cleanText = cleanHTML({ initialText });
Expand Down
2 changes: 2 additions & 0 deletions src/editors/sharedComponents/ErrorAlerts/ErrorAlert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import messages from './messages';

export const hooks = {
state: {
// eslint-disable-next-line react-hooks/rules-of-hooks
isDismissed: (val) => React.useState(val),
},
dismissalHooks: ({ dismissError, isError }) => {
const [isDismissed, setIsDismissed] = hooks.state.isDismissed(false);
// eslint-disable-next-line react-hooks/rules-of-hooks
React.useEffect(() => {
setIsDismissed(isDismissed && !isError);
},
Expand Down
1 change: 1 addition & 0 deletions src/editors/sharedComponents/FileInput/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';

export const fileInput = ({ onAddFile }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const ref = React.useRef();
const click = () => ref.current.click();
const addFile = (e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@ import * as module from './hooks';

// Simple wrappers for useState to allow easy mocking for tests.
export const state = {
// eslint-disable-next-line react-hooks/rules-of-hooks
altText: (val) => React.useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
dimensions: (val) => React.useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
showAltTextDismissibleError: (val) => React.useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
showAltTextSubmissionError: (val) => React.useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
isDecorative: (val) => React.useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
isLocked: (val) => React.useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
local: (val) => React.useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
lockDims: (val) => React.useState(val),
// eslint-disable-next-line react-hooks/rules-of-hooks
lockInitialized: (val) => React.useState(val),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const testVal = 'MY test VALUE';

describe('state values', () => {
const testStateMethod = (key) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
expect(hooks.state[key](testVal)).toEqual(React.useState(testVal));
};
test('provides altText state value', () => testStateMethod(state.keys.altText));
Expand Down
Loading

0 comments on commit 1a44b40

Please sign in to comment.