Merge branch 'block-pagination' into 'develop'
Fix pagination for blocks/mutes See merge request soapbox-pub/soapbox-fe!460
This commit is contained in:
commit
26ef34ea6a
|
@ -2,6 +2,7 @@ import api, { getLinks } from '../api';
|
||||||
import { fetchRelationships } from './accounts';
|
import { fetchRelationships } from './accounts';
|
||||||
import { importFetchedAccounts } from './importer';
|
import { importFetchedAccounts } from './importer';
|
||||||
import { isLoggedIn } from 'soapbox/utils/auth';
|
import { isLoggedIn } from 'soapbox/utils/auth';
|
||||||
|
import { getNextLinkName } from 'soapbox/utils/quirks';
|
||||||
|
|
||||||
export const BLOCKS_FETCH_REQUEST = 'BLOCKS_FETCH_REQUEST';
|
export const BLOCKS_FETCH_REQUEST = 'BLOCKS_FETCH_REQUEST';
|
||||||
export const BLOCKS_FETCH_SUCCESS = 'BLOCKS_FETCH_SUCCESS';
|
export const BLOCKS_FETCH_SUCCESS = 'BLOCKS_FETCH_SUCCESS';
|
||||||
|
@ -14,11 +15,12 @@ export const BLOCKS_EXPAND_FAIL = 'BLOCKS_EXPAND_FAIL';
|
||||||
export function fetchBlocks() {
|
export function fetchBlocks() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
if (!isLoggedIn(getState)) return;
|
if (!isLoggedIn(getState)) return;
|
||||||
|
const nextLinkName = getNextLinkName(getState);
|
||||||
|
|
||||||
dispatch(fetchBlocksRequest());
|
dispatch(fetchBlocksRequest());
|
||||||
|
|
||||||
api(getState).get('/api/v1/blocks').then(response => {
|
api(getState).get('/api/v1/blocks').then(response => {
|
||||||
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
const next = getLinks(response).refs.find(link => link.rel === nextLinkName);
|
||||||
dispatch(importFetchedAccounts(response.data));
|
dispatch(importFetchedAccounts(response.data));
|
||||||
dispatch(fetchBlocksSuccess(response.data, next ? next.uri : null));
|
dispatch(fetchBlocksSuccess(response.data, next ? next.uri : null));
|
||||||
dispatch(fetchRelationships(response.data.map(item => item.id)));
|
dispatch(fetchRelationships(response.data.map(item => item.id)));
|
||||||
|
@ -50,6 +52,7 @@ export function fetchBlocksFail(error) {
|
||||||
export function expandBlocks() {
|
export function expandBlocks() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
if (!isLoggedIn(getState)) return;
|
if (!isLoggedIn(getState)) return;
|
||||||
|
const nextLinkName = getNextLinkName(getState);
|
||||||
|
|
||||||
const url = getState().getIn(['user_lists', 'blocks', 'next']);
|
const url = getState().getIn(['user_lists', 'blocks', 'next']);
|
||||||
|
|
||||||
|
@ -60,7 +63,7 @@ export function expandBlocks() {
|
||||||
dispatch(expandBlocksRequest());
|
dispatch(expandBlocksRequest());
|
||||||
|
|
||||||
api(getState).get(url).then(response => {
|
api(getState).get(url).then(response => {
|
||||||
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
const next = getLinks(response).refs.find(link => link.rel === nextLinkName);
|
||||||
dispatch(importFetchedAccounts(response.data));
|
dispatch(importFetchedAccounts(response.data));
|
||||||
dispatch(expandBlocksSuccess(response.data, next ? next.uri : null));
|
dispatch(expandBlocksSuccess(response.data, next ? next.uri : null));
|
||||||
dispatch(fetchRelationships(response.data.map(item => item.id)));
|
dispatch(fetchRelationships(response.data.map(item => item.id)));
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { fetchRelationships } from './accounts';
|
||||||
import { importFetchedAccounts } from './importer';
|
import { importFetchedAccounts } from './importer';
|
||||||
import { openModal } from './modal';
|
import { openModal } from './modal';
|
||||||
import { isLoggedIn } from 'soapbox/utils/auth';
|
import { isLoggedIn } from 'soapbox/utils/auth';
|
||||||
|
import { getNextLinkName } from 'soapbox/utils/quirks';
|
||||||
|
|
||||||
export const MUTES_FETCH_REQUEST = 'MUTES_FETCH_REQUEST';
|
export const MUTES_FETCH_REQUEST = 'MUTES_FETCH_REQUEST';
|
||||||
export const MUTES_FETCH_SUCCESS = 'MUTES_FETCH_SUCCESS';
|
export const MUTES_FETCH_SUCCESS = 'MUTES_FETCH_SUCCESS';
|
||||||
|
@ -18,11 +19,12 @@ export const MUTES_TOGGLE_HIDE_NOTIFICATIONS = 'MUTES_TOGGLE_HIDE_NOTIFICATIONS'
|
||||||
export function fetchMutes() {
|
export function fetchMutes() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
if (!isLoggedIn(getState)) return;
|
if (!isLoggedIn(getState)) return;
|
||||||
|
const nextLinkName = getNextLinkName(getState);
|
||||||
|
|
||||||
dispatch(fetchMutesRequest());
|
dispatch(fetchMutesRequest());
|
||||||
|
|
||||||
api(getState).get('/api/v1/mutes').then(response => {
|
api(getState).get('/api/v1/mutes').then(response => {
|
||||||
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
const next = getLinks(response).refs.find(link => link.rel === nextLinkName);
|
||||||
dispatch(importFetchedAccounts(response.data));
|
dispatch(importFetchedAccounts(response.data));
|
||||||
dispatch(fetchMutesSuccess(response.data, next ? next.uri : null));
|
dispatch(fetchMutesSuccess(response.data, next ? next.uri : null));
|
||||||
dispatch(fetchRelationships(response.data.map(item => item.id)));
|
dispatch(fetchRelationships(response.data.map(item => item.id)));
|
||||||
|
@ -54,6 +56,7 @@ export function fetchMutesFail(error) {
|
||||||
export function expandMutes() {
|
export function expandMutes() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
if (!isLoggedIn(getState)) return;
|
if (!isLoggedIn(getState)) return;
|
||||||
|
const nextLinkName = getNextLinkName(getState);
|
||||||
|
|
||||||
const url = getState().getIn(['user_lists', 'mutes', 'next']);
|
const url = getState().getIn(['user_lists', 'mutes', 'next']);
|
||||||
|
|
||||||
|
@ -64,7 +67,7 @@ export function expandMutes() {
|
||||||
dispatch(expandMutesRequest());
|
dispatch(expandMutesRequest());
|
||||||
|
|
||||||
api(getState).get(url).then(response => {
|
api(getState).get(url).then(response => {
|
||||||
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
const next = getLinks(response).refs.find(link => link.rel === nextLinkName);
|
||||||
dispatch(importFetchedAccounts(response.data));
|
dispatch(importFetchedAccounts(response.data));
|
||||||
dispatch(expandMutesSuccess(response.data, next ? next.uri : null));
|
dispatch(expandMutesSuccess(response.data, next ? next.uri : null));
|
||||||
dispatch(fetchRelationships(response.data.map(item => item.id)));
|
dispatch(fetchRelationships(response.data.map(item => item.id)));
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { parseVersion } from './features';
|
||||||
|
|
||||||
|
// For solving bugs between API implementations
|
||||||
|
export const getQuirks = instance => {
|
||||||
|
const v = parseVersion(instance.get('version'));
|
||||||
|
return {
|
||||||
|
invertedPagination: v.software === 'Pleroma',
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getNextLinkName = getState =>
|
||||||
|
getQuirks(getState().get('instance')).invertedPagination ? 'prev' : 'next';
|
Loading…
Reference in New Issue