|
|
@ -1,6 +1,7 @@
|
|
|
|
import api from '../api';
|
|
|
|
import api from '../api';
|
|
|
|
import { importFetchedAccounts } from './importer';
|
|
|
|
import { importFetchedAccounts } from './importer';
|
|
|
|
import { isLoggedIn } from 'soapbox/utils/auth';
|
|
|
|
import { isLoggedIn } from 'soapbox/utils/auth';
|
|
|
|
|
|
|
|
import { getFeatures } from 'soapbox/utils/features';
|
|
|
|
|
|
|
|
|
|
|
|
export const SUGGESTIONS_FETCH_REQUEST = 'SUGGESTIONS_FETCH_REQUEST';
|
|
|
|
export const SUGGESTIONS_FETCH_REQUEST = 'SUGGESTIONS_FETCH_REQUEST';
|
|
|
|
export const SUGGESTIONS_FETCH_SUCCESS = 'SUGGESTIONS_FETCH_SUCCESS';
|
|
|
|
export const SUGGESTIONS_FETCH_SUCCESS = 'SUGGESTIONS_FETCH_SUCCESS';
|
|
|
@ -8,38 +9,48 @@ export const SUGGESTIONS_FETCH_FAIL = 'SUGGESTIONS_FETCH_FAIL';
|
|
|
|
|
|
|
|
|
|
|
|
export const SUGGESTIONS_DISMISS = 'SUGGESTIONS_DISMISS';
|
|
|
|
export const SUGGESTIONS_DISMISS = 'SUGGESTIONS_DISMISS';
|
|
|
|
|
|
|
|
|
|
|
|
export function fetchSuggestions() {
|
|
|
|
export const SUGGESTIONS_V2_FETCH_REQUEST = 'SUGGESTIONS_V2_FETCH_REQUEST';
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
export const SUGGESTIONS_V2_FETCH_SUCCESS = 'SUGGESTIONS_V2_FETCH_SUCCESS';
|
|
|
|
dispatch(fetchSuggestionsRequest());
|
|
|
|
export const SUGGESTIONS_V2_FETCH_FAIL = 'SUGGESTIONS_V2_FETCH_FAIL';
|
|
|
|
|
|
|
|
|
|
|
|
api(getState).get('/api/v1/suggestions').then(response => {
|
|
|
|
export function fetchSuggestionsV1() {
|
|
|
|
dispatch(importFetchedAccounts(response.data));
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch(fetchSuggestionsSuccess(response.data));
|
|
|
|
dispatch({ type: SUGGESTIONS_FETCH_REQUEST, skipLoading: true });
|
|
|
|
}).catch(error => dispatch(fetchSuggestionsFail(error)));
|
|
|
|
api(getState).get('/api/v1/suggestions').then(({ data: accounts }) => {
|
|
|
|
|
|
|
|
dispatch(importFetchedAccounts(accounts));
|
|
|
|
|
|
|
|
dispatch({ type: SUGGESTIONS_FETCH_SUCCESS, accounts, skipLoading: true });
|
|
|
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
|
|
|
dispatch({ type: SUGGESTIONS_FETCH_FAIL, error, skipLoading: true, skipAlert: true });
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function fetchSuggestionsRequest() {
|
|
|
|
export function fetchSuggestionsV2() {
|
|
|
|
return {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
type: SUGGESTIONS_FETCH_REQUEST,
|
|
|
|
dispatch({ type: SUGGESTIONS_V2_FETCH_REQUEST, skipLoading: true });
|
|
|
|
skipLoading: true,
|
|
|
|
api(getState).get('/api/v2/suggestions').then(({ data: suggestions }) => {
|
|
|
|
|
|
|
|
const accounts = suggestions.map(({ account }) => account);
|
|
|
|
|
|
|
|
dispatch(importFetchedAccounts(accounts));
|
|
|
|
|
|
|
|
dispatch({ type: SUGGESTIONS_V2_FETCH_SUCCESS, suggestions, skipLoading: true });
|
|
|
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
|
|
|
dispatch({ type: SUGGESTIONS_V2_FETCH_FAIL, error, skipLoading: true, skipAlert: true });
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function fetchSuggestionsSuccess(accounts) {
|
|
|
|
export function fetchSuggestions() {
|
|
|
|
return {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
type: SUGGESTIONS_FETCH_SUCCESS,
|
|
|
|
const state = getState();
|
|
|
|
accounts,
|
|
|
|
const instance = state.get('instance');
|
|
|
|
skipLoading: true,
|
|
|
|
const features = getFeatures(instance);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function fetchSuggestionsFail(error) {
|
|
|
|
if (features.suggestionsV2) {
|
|
|
|
return {
|
|
|
|
dispatch(fetchSuggestionsV2());
|
|
|
|
type: SUGGESTIONS_FETCH_FAIL,
|
|
|
|
} else if (features.suggestions) {
|
|
|
|
error,
|
|
|
|
dispatch(fetchSuggestionsV1());
|
|
|
|
skipLoading: true,
|
|
|
|
} else {
|
|
|
|
skipAlert: true,
|
|
|
|
// Do nothing
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|