From 30e895299ceff095da3e4c8ee50b3d003225f021 Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Wed, 18 Jan 2023 08:44:33 -0700 Subject: Add listing of followed hashtags (#21773) * Add followed_tags route. This at least gets us to the point where the page can actually be rendered, although it doesn't display any hashtags (yet?). Attempting to implement #20763. * Fix minor issues. * I've got the followed tags data partially working But the Hashtag component errors for some reason. Something about the value of the history attribute being invalid. * Fix a mistake in the code * Minor change. * Get the followed hashtags list fully working. Still need to add the Follow/Unfollow buttons, though. * Resolve JS linter issues. * Add pagination logic to followed tags list view. However, it currently loads further pages immediately on page load, so that's not ideal. Need to figure that one out. * Appease the linter. * Apply suggestions from code review Co-authored-by: Claire * Fixes and resolve some other feedback. * Use set/update instead of setIn/updateIn. Co-authored-by: Claire --- app/javascript/mastodon/actions/tags.js | 82 ++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) (limited to 'app/javascript/mastodon/actions/tags.js') diff --git a/app/javascript/mastodon/actions/tags.js b/app/javascript/mastodon/actions/tags.js index 37e79d4cb..08a08cda3 100644 --- a/app/javascript/mastodon/actions/tags.js +++ b/app/javascript/mastodon/actions/tags.js @@ -1,9 +1,17 @@ -import api from '../api'; +import api, { getLinks } from '../api'; export const HASHTAG_FETCH_REQUEST = 'HASHTAG_FETCH_REQUEST'; export const HASHTAG_FETCH_SUCCESS = 'HASHTAG_FETCH_SUCCESS'; export const HASHTAG_FETCH_FAIL = 'HASHTAG_FETCH_FAIL'; +export const FOLLOWED_HASHTAGS_FETCH_REQUEST = 'FOLLOWED_HASHTAGS_FETCH_REQUEST'; +export const FOLLOWED_HASHTAGS_FETCH_SUCCESS = 'FOLLOWED_HASHTAGS_FETCH_SUCCESS'; +export const FOLLOWED_HASHTAGS_FETCH_FAIL = 'FOLLOWED_HASHTAGS_FETCH_FAIL'; + +export const FOLLOWED_HASHTAGS_EXPAND_REQUEST = 'FOLLOWED_HASHTAGS_EXPAND_REQUEST'; +export const FOLLOWED_HASHTAGS_EXPAND_SUCCESS = 'FOLLOWED_HASHTAGS_EXPAND_SUCCESS'; +export const FOLLOWED_HASHTAGS_EXPAND_FAIL = 'FOLLOWED_HASHTAGS_EXPAND_FAIL'; + export const HASHTAG_FOLLOW_REQUEST = 'HASHTAG_FOLLOW_REQUEST'; export const HASHTAG_FOLLOW_SUCCESS = 'HASHTAG_FOLLOW_SUCCESS'; export const HASHTAG_FOLLOW_FAIL = 'HASHTAG_FOLLOW_FAIL'; @@ -37,6 +45,78 @@ export const fetchHashtagFail = error => ({ error, }); +export const fetchFollowedHashtags = () => (dispatch, getState) => { + dispatch(fetchFollowedHashtagsRequest()); + + api(getState).get('/api/v1/followed_tags').then(response => { + const next = getLinks(response).refs.find(link => link.rel === 'next'); + dispatch(fetchFollowedHashtagsSuccess(response.data, next ? next.uri : null)); + }).catch(err => { + dispatch(fetchFollowedHashtagsFail(err)); + }); +}; + +export function fetchFollowedHashtagsRequest() { + return { + type: FOLLOWED_HASHTAGS_FETCH_REQUEST, + }; +}; + +export function fetchFollowedHashtagsSuccess(followed_tags, next) { + return { + type: FOLLOWED_HASHTAGS_FETCH_SUCCESS, + followed_tags, + next, + }; +}; + +export function fetchFollowedHashtagsFail(error) { + return { + type: FOLLOWED_HASHTAGS_FETCH_FAIL, + error, + }; +}; + +export function expandFollowedHashtags() { + return (dispatch, getState) => { + const url = getState().getIn(['followed_tags', 'next']); + + if (url === null) { + return; + } + + dispatch(expandFollowedHashtagsRequest()); + + api(getState).get(url).then(response => { + const next = getLinks(response).refs.find(link => link.rel === 'next'); + dispatch(expandFollowedHashtagsSuccess(response.data, next ? next.uri : null)); + }).catch(error => { + dispatch(expandFollowedHashtagsFail(error)); + }); + }; +}; + +export function expandFollowedHashtagsRequest() { + return { + type: FOLLOWED_HASHTAGS_EXPAND_REQUEST, + }; +}; + +export function expandFollowedHashtagsSuccess(followed_tags, next) { + return { + type: FOLLOWED_HASHTAGS_EXPAND_SUCCESS, + followed_tags, + next, + }; +}; + +export function expandFollowedHashtagsFail(error) { + return { + type: FOLLOWED_HASHTAGS_EXPAND_FAIL, + error, + }; +}; + export const followHashtag = name => (dispatch, getState) => { dispatch(followHashtagRequest(name)); -- cgit From d9088ef3272421a9267467fb95674d4b4afb38ab Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Sun, 29 Jan 2023 17:44:03 -0500 Subject: Separate ESLint CI from Superlinter (#23029) * Separate ESLint CI from Superlinter * Correct JS indenting level * Remove extra semicolons with ESLint autofix --- .github/workflows/lint-js.yml | 40 ++++++++++++++++++++++ .github/workflows/linter.yml | 2 -- app/javascript/mastodon/actions/tags.js | 14 ++++---- .../mastodon/features/account/components/header.js | 6 ++-- .../mastodon/features/followed_tags/index.js | 2 +- app/javascript/mastodon/reducers/followed_tags.js | 2 +- 6 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/lint-js.yml (limited to 'app/javascript/mastodon/actions/tags.js') diff --git a/.github/workflows/lint-js.yml b/.github/workflows/lint-js.yml new file mode 100644 index 000000000..49d989771 --- /dev/null +++ b/.github/workflows/lint-js.yml @@ -0,0 +1,40 @@ +name: JavaScript Linting +on: + push: + branches-ignore: + - 'dependabot/**' + paths: + - 'package.json' + - 'yarn.lock' + - '.prettier*' + - '.eslint*' + - '**/*.js' + - '.github/workflows/lint-js.yml' + + pull_request: + paths: + - 'package.json' + - 'yarn.lock' + - '.prettier*' + - '.eslint*' + - '**/*.js' + - '.github/workflows/lint-js.yml' + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Clone repository + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + cache: yarn + + - name: Install all yarn packages + run: yarn --frozen-lockfile + + - name: ESLint + run: yarn test:lint:js diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index b6438d665..575732845 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -74,10 +74,8 @@ jobs: DEFAULT_BRANCH: main NO_COLOR: 1 # https://github.com/xt0rted/stylelint-problem-matcher/issues/360 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - JAVASCRIPT_ES_CONFIG_FILE: .eslintrc.js LINTER_RULES_PATH: . RUBY_CONFIG_FILE: .rubocop.yml VALIDATE_ALL_CODEBASE: false VALIDATE_CSS: true - VALIDATE_JAVASCRIPT_ES: true VALIDATE_RUBY: true diff --git a/app/javascript/mastodon/actions/tags.js b/app/javascript/mastodon/actions/tags.js index 08a08cda3..dda8c924b 100644 --- a/app/javascript/mastodon/actions/tags.js +++ b/app/javascript/mastodon/actions/tags.js @@ -60,7 +60,7 @@ export function fetchFollowedHashtagsRequest() { return { type: FOLLOWED_HASHTAGS_FETCH_REQUEST, }; -}; +} export function fetchFollowedHashtagsSuccess(followed_tags, next) { return { @@ -68,14 +68,14 @@ export function fetchFollowedHashtagsSuccess(followed_tags, next) { followed_tags, next, }; -}; +} export function fetchFollowedHashtagsFail(error) { return { type: FOLLOWED_HASHTAGS_FETCH_FAIL, error, }; -}; +} export function expandFollowedHashtags() { return (dispatch, getState) => { @@ -94,13 +94,13 @@ export function expandFollowedHashtags() { dispatch(expandFollowedHashtagsFail(error)); }); }; -}; +} export function expandFollowedHashtagsRequest() { return { type: FOLLOWED_HASHTAGS_EXPAND_REQUEST, }; -}; +} export function expandFollowedHashtagsSuccess(followed_tags, next) { return { @@ -108,14 +108,14 @@ export function expandFollowedHashtagsSuccess(followed_tags, next) { followed_tags, next, }; -}; +} export function expandFollowedHashtagsFail(error) { return { type: FOLLOWED_HASHTAGS_EXPAND_FAIL, error, }; -}; +} export const followHashtag = name => (dispatch, getState) => { dispatch(followHashtagRequest(name)); diff --git a/app/javascript/mastodon/features/account/components/header.js b/app/javascript/mastodon/features/account/components/header.js index 46fb89f2f..d0715d20d 100644 --- a/app/javascript/mastodon/features/account/components/header.js +++ b/app/javascript/mastodon/features/account/components/header.js @@ -296,9 +296,9 @@ class Header extends ImmutablePureComponent { if ((permissions & PERMISSION_MANAGE_USERS) === PERMISSION_MANAGE_USERS) { menu.push({ text: intl.formatMessage(messages.admin_account, { name: account.get('username') }), href: `/admin/accounts/${account.get('id')}` }); } - if (isRemote && (permissions & PERMISSION_MANAGE_FEDERATION) === PERMISSION_MANAGE_FEDERATION) { - menu.push({ text: intl.formatMessage(messages.admin_domain, { domain: remoteDomain }), href: `/admin/instances/${remoteDomain}` }); - } + if (isRemote && (permissions & PERMISSION_MANAGE_FEDERATION) === PERMISSION_MANAGE_FEDERATION) { + menu.push({ text: intl.formatMessage(messages.admin_domain, { domain: remoteDomain }), href: `/admin/instances/${remoteDomain}` }); + } } const content = { __html: account.get('note_emojified') }; diff --git a/app/javascript/mastodon/features/followed_tags/index.js b/app/javascript/mastodon/features/followed_tags/index.js index 0a62ca76d..c2d0e4731 100644 --- a/app/javascript/mastodon/features/followed_tags/index.js +++ b/app/javascript/mastodon/features/followed_tags/index.js @@ -38,7 +38,7 @@ class FollowedTags extends ImmutablePureComponent { componentDidMount() { this.props.dispatch(fetchFollowedHashtags()); - }; + } handleLoadMore = debounce(() => { this.props.dispatch(expandFollowedHashtags()); diff --git a/app/javascript/mastodon/reducers/followed_tags.js b/app/javascript/mastodon/reducers/followed_tags.js index f50ee6aa3..da20b7b12 100644 --- a/app/javascript/mastodon/reducers/followed_tags.js +++ b/app/javascript/mastodon/reducers/followed_tags.js @@ -39,4 +39,4 @@ export default function followed_tags(state = initialState, action) { default: return state; } -}; +} -- cgit