From 00cc1536f2851a23806c0200673781479e8ba648 Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Wed, 18 Jan 2023 08:44:33 -0700 Subject: [Glitch] Add listing of followed hashtags Port 30e895299ceff095da3e4c8ee50b3d003225f021 to glitch-soc Co-authored-by: Claire Signed-off-by: Claire --- app/javascript/flavours/glitch/actions/tags.js | 82 +++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) (limited to 'app/javascript/flavours/glitch/actions/tags.js') diff --git a/app/javascript/flavours/glitch/actions/tags.js b/app/javascript/flavours/glitch/actions/tags.js index 37e79d4cb..08a08cda3 100644 --- a/app/javascript/flavours/glitch/actions/tags.js +++ b/app/javascript/flavours/glitch/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 ed7cb797235d86aedf04e235da40d5d6aa8e1cb1 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Sun, 29 Jan 2023 17:44:03 -0500 Subject: [Glitch] Remove extra semicolons with ESLint autofix Port d9088ef3272421a9267467fb95674d4b4afb38ab to glitch-soc Signed-off-by: Claire --- app/javascript/flavours/glitch/actions/tags.js | 14 +++++++------- .../flavours/glitch/features/followed_tags/index.js | 2 +- app/javascript/flavours/glitch/reducers/followed_tags.js | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'app/javascript/flavours/glitch/actions/tags.js') diff --git a/app/javascript/flavours/glitch/actions/tags.js b/app/javascript/flavours/glitch/actions/tags.js index 08a08cda3..dda8c924b 100644 --- a/app/javascript/flavours/glitch/actions/tags.js +++ b/app/javascript/flavours/glitch/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/flavours/glitch/features/followed_tags/index.js b/app/javascript/flavours/glitch/features/followed_tags/index.js index 4a23afc2d..73203636c 100644 --- a/app/javascript/flavours/glitch/features/followed_tags/index.js +++ b/app/javascript/flavours/glitch/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/flavours/glitch/reducers/followed_tags.js b/app/javascript/flavours/glitch/reducers/followed_tags.js index 4109b0b10..84c744640 100644 --- a/app/javascript/flavours/glitch/reducers/followed_tags.js +++ b/app/javascript/flavours/glitch/reducers/followed_tags.js @@ -39,4 +39,4 @@ export default function followed_tags(state = initialState, action) { default: return state; } -}; +} -- cgit