2020-11-11 13:52:47 +02:00
|
|
|
import { ModelFeedPage } from '../../../models/utils/paginatedFeed';
|
|
|
|
import { Request } from '../Api';
|
|
|
|
import requestPaginationOptions from '../utils/requestPaginationOptions';
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
export default function(items: any[], request: Request): ModelFeedPage {
|
2020-11-11 13:52:47 +02:00
|
|
|
const pagination = requestPaginationOptions(request);
|
|
|
|
const startIndex = (pagination.page - 1) * pagination.limit;
|
|
|
|
const itemCount = Math.min(items.length - startIndex, pagination.limit);
|
|
|
|
const hasMore = itemCount >= pagination.limit;
|
|
|
|
|
|
|
|
return {
|
|
|
|
items: items.slice(startIndex, startIndex + itemCount),
|
|
|
|
has_more: hasMore,
|
|
|
|
};
|
|
|
|
}
|