Merge branch 'skip-api-requests-for-guests' into 'develop'

Skip API requests if logged out

See merge request soapbox-pub/soapbox-fe!1385
This commit is contained in:
Justin 2022-05-14 18:49:56 +00:00
commit e57e2258f8
2 changed files with 10 additions and 4 deletions

View file

@ -6,6 +6,9 @@ export const CUSTOM_EMOJIS_FETCH_FAIL = 'CUSTOM_EMOJIS_FETCH_FAIL';
export function fetchCustomEmojis() { export function fetchCustomEmojis() {
return (dispatch, getState) => { return (dispatch, getState) => {
const me = getState().get('me');
if (!me) return;
dispatch(fetchCustomEmojisRequest()); dispatch(fetchCustomEmojisRequest());
api(getState).get('/api/v1/custom_emojis').then(response => { api(getState).get('/api/v1/custom_emojis').then(response => {

View file

@ -48,23 +48,26 @@ export function fetchSuggestionsV2(params = {}) {
export function fetchSuggestions(params = { limit: 50 }) { export function fetchSuggestions(params = { limit: 50 }) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const me = state.get('me');
const instance = state.get('instance'); const instance = state.get('instance');
const features = getFeatures(instance); const features = getFeatures(instance);
if (!me) return;
if (features.suggestionsV2) { if (features.suggestionsV2) {
dispatch(fetchSuggestionsV2(params)) dispatch(fetchSuggestionsV2(params))
.then(suggestions => { .then(suggestions => {
const accountIds = suggestions.map(({ account }) => account.id); const accountIds = suggestions.map(({ account }) => account.id);
dispatch(fetchRelationships(accountIds)); dispatch(fetchRelationships(accountIds));
}) })
.catch(() => {}); .catch(() => { });
} else if (features.suggestions) { } else if (features.suggestions) {
dispatch(fetchSuggestionsV1(params)) dispatch(fetchSuggestionsV1(params))
.then(accounts => { .then(accounts => {
const accountIds = accounts.map(({ id }) => id); const accountIds = accounts.map(({ id }) => id);
dispatch(fetchRelationships(accountIds)); dispatch(fetchRelationships(accountIds));
}) })
.catch(() => {}); .catch(() => { });
} else { } else {
// Do nothing // Do nothing
} }