From 16c5354b8ca05f1805da5657094eb9b9138b2442 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 8 May 2023 14:02:41 +0200 Subject: [PATCH] Fix some more JS linting issues (#2211) * Minor refactor and linting fixup in `flavours/glitch/actions/accounts.js` This is some added boilerplate but it's much more consistent with the remaining of the code, and avoids the linting issue. * Fix missing /privacy-policy link in DM warning because of wrongly-named import * Fix unnecessary import * Fix regexp in flavours/glitch/utils/hashtag.js --- .../flavours/glitch/actions/accounts.js | 28 +++++++++++++++---- .../features/account/components/header.jsx | 1 - .../compose/containers/warning_container.jsx | 4 +-- .../glitch/reducers/pinned_accounts_editor.js | 6 ++-- .../flavours/glitch/utils/hashtag.js | 2 +- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/accounts.js b/app/javascript/flavours/glitch/actions/accounts.js index 92442ff59..9e5c85a15 100644 --- a/app/javascript/flavours/glitch/actions/accounts.js +++ b/app/javascript/flavours/glitch/actions/accounts.js @@ -81,7 +81,10 @@ export const PINNED_ACCOUNTS_FETCH_REQUEST = 'PINNED_ACCOUNTS_FETCH_REQUEST'; export const PINNED_ACCOUNTS_FETCH_SUCCESS = 'PINNED_ACCOUNTS_FETCH_SUCCESS'; export const PINNED_ACCOUNTS_FETCH_FAIL = 'PINNED_ACCOUNTS_FETCH_FAIL'; -export const PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_READY = 'PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_READY'; +export const PINNED_ACCOUNTS_SUGGESTIONS_FETCH_REQUEST = 'PINNED_ACCOUNTS_SUGGESTIONS_FETCH_REQUEST'; +export const PINNED_ACCOUNTS_SUGGESTIONS_FETCH_SUCCESS = 'PINNED_ACCOUNTS_SUGGESTIONS_FETCH_SUCCESS'; +export const PINNED_ACCOUNTS_SUGGESTIONS_FETCH_FAIL = 'PINNED_ACCOUNTS_SUGGESTIONS_FETCH_FAIL'; + export const PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_CLEAR = 'PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_CLEAR'; export const PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_CHANGE = 'PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_CHANGE'; @@ -841,6 +844,8 @@ export function fetchPinnedAccountsFail(error) { export function fetchPinnedAccountsSuggestions(q) { return (dispatch, getState) => { + dispatch(fetchPinnedAccountsSuggestionsRequest()); + const params = { q, resolve: false, @@ -850,19 +855,32 @@ export function fetchPinnedAccountsSuggestions(q) { api(getState).get('/api/v1/accounts/search', { params }).then(response => { dispatch(importFetchedAccounts(response.data)); - dispatch(fetchPinnedAccountsSuggestionsReady(q, response.data)); - }); + dispatch(fetchPinnedAccountsSuggestionsSuccess(q, response.data)); + }).catch(err => dispatch(fetchPinnedAccountsSuggestionsFail(err))); + }; +} + +export function fetchPinnedAccountsSuggestionsRequest() { + return { + type: PINNED_ACCOUNTS_SUGGESTIONS_FETCH_REQUEST, }; } -export function fetchPinnedAccountsSuggestionsReady(query, accounts) { +export function fetchPinnedAccountsSuggestionsSuccess(query, accounts) { return { - type: PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_READY, + type: PINNED_ACCOUNTS_SUGGESTIONS_FETCH_SUCCESS, query, accounts, }; } +export function fetchPinnedAccountsSuggestionsFail(error) { + return { + type: PINNED_ACCOUNTS_SUGGESTIONS_FETCH_FAIL, + error, + }; +} + export function clearPinnedAccountsSuggestions() { return { type: PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_CLEAR, diff --git a/app/javascript/flavours/glitch/features/account/components/header.jsx b/app/javascript/flavours/glitch/features/account/components/header.jsx index 6f918abcf..9fcdb82e7 100644 --- a/app/javascript/flavours/glitch/features/account/components/header.jsx +++ b/app/javascript/flavours/glitch/features/account/components/header.jsx @@ -10,7 +10,6 @@ import Icon from 'flavours/glitch/components/icon'; import IconButton from 'flavours/glitch/components/icon_button'; import Avatar from 'flavours/glitch/components/avatar'; import Button from 'flavours/glitch/components/button'; -import { NavLink } from 'react-router-dom'; import DropdownMenuContainer from 'flavours/glitch/containers/dropdown_menu_container'; import AccountNoteContainer from '../containers/account_note_container'; import FollowRequestNoteContainer from '../containers/follow_request_note_container'; diff --git a/app/javascript/flavours/glitch/features/compose/containers/warning_container.jsx b/app/javascript/flavours/glitch/features/compose/containers/warning_container.jsx index 5b48c45e4..8abc668fc 100644 --- a/app/javascript/flavours/glitch/features/compose/containers/warning_container.jsx +++ b/app/javascript/flavours/glitch/features/compose/containers/warning_container.jsx @@ -4,7 +4,7 @@ import Warning from '../components/warning'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import { me } from 'flavours/glitch/initial_state'; -import { profileLink, termsLink } from 'flavours/glitch/utils/backend_links'; +import { profileLink, privacyPolicyLink } from 'flavours/glitch/utils/backend_links'; const buildHashtagRE = () => { try { @@ -49,7 +49,7 @@ const WarningWrapper = ({ needsLockWarning, hashtagWarning, directMessageWarning if (directMessageWarning) { const message = ( - {!!termsLink && } + {!!privacyPolicyLink && } ); diff --git a/app/javascript/flavours/glitch/reducers/pinned_accounts_editor.js b/app/javascript/flavours/glitch/reducers/pinned_accounts_editor.js index 144418d12..00cde3640 100644 --- a/app/javascript/flavours/glitch/reducers/pinned_accounts_editor.js +++ b/app/javascript/flavours/glitch/reducers/pinned_accounts_editor.js @@ -4,7 +4,7 @@ import { PINNED_ACCOUNTS_FETCH_REQUEST, PINNED_ACCOUNTS_FETCH_SUCCESS, PINNED_ACCOUNTS_FETCH_FAIL, - PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_READY, + PINNED_ACCOUNTS_SUGGESTIONS_FETCH_SUCCESS, PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_CLEAR, PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_CHANGE, ACCOUNT_PIN_SUCCESS, @@ -38,10 +38,10 @@ export default function listEditorReducer(state = initialState, action) { map.set('loaded', true); map.set('items', ImmutableList(action.accounts.map(item => item.id))); })); + case PINNED_ACCOUNTS_SUGGESTIONS_FETCH_SUCCESS: + return state.setIn(['suggestions', 'items'], ImmutableList(action.accounts.map(item => item.id))); case PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_CHANGE: return state.setIn(['suggestions', 'value'], action.value); - case PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_READY: - return state.setIn(['suggestions', 'items'], ImmutableList(action.accounts.map(item => item.id))); case PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_CLEAR: return state.update('suggestions', suggestions => suggestions.withMutations(map => { map.set('items', ImmutableList()); diff --git a/app/javascript/flavours/glitch/utils/hashtag.js b/app/javascript/flavours/glitch/utils/hashtag.js index d91cd5591..6c529dce8 100644 --- a/app/javascript/flavours/glitch/utils/hashtag.js +++ b/app/javascript/flavours/glitch/utils/hashtag.js @@ -1,6 +1,6 @@ export function recoverHashtags (recognizedTags, text) { return recognizedTags.map(tag => { - const re = new RegExp(`(?:^|[^/)\w])#(${tag.name})`, 'i'); + const re = new RegExp(`(?:^|[^/)\\w])#(${tag.name})`, 'i'); const matched_hashtag = text.match(re); return matched_hashtag ? matched_hashtag[1] : null; },