Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed pagination issue for uppy #936

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions studio/src/components/MediaSelector/MediaList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { List, Avatar, Space, Input } from 'antd';
import { List, Avatar, Space, Input ,Pagination} from 'antd';
import { CheckCircleTwoTone } from '@ant-design/icons';
import { useDispatch, useSelector } from 'react-redux';
import { getMedia } from '../../actions/media';
Expand All @@ -10,7 +10,7 @@ function MediaList({ onSelect, selected, onUnselect, profile = false }) {

const [filters, setFilters] = React.useState({
page: 1,
limit: 8,
limit: 10, // Set default page size
});

const { media, total } = useSelector((state) => {
Expand All @@ -35,6 +35,7 @@ function MediaList({ onSelect, selected, onUnselect, profile = false }) {
const fetchMedia = () => {
dispatch(getMedia(filters, profile));
};
const lastPage = Math.ceil(total / filters.limit);

return (
<Space direction={'vertical'}>
Expand All @@ -47,14 +48,6 @@ function MediaList({ onSelect, selected, onUnselect, profile = false }) {
gutter: 16,
md: 4,
}}
pagination={{
current: filters.page,
total: total,
pageSize: filters.limit,
onChange: (pageNumber, pageSize) => {
setFilters({ page: pageNumber, limit: pageSize });
},
}}
dataSource={media}
renderItem={(item) => (
<List.Item>
Expand Down Expand Up @@ -89,6 +82,42 @@ function MediaList({ onSelect, selected, onUnselect, profile = false }) {
</List.Item>
)}
/>
<Space style={{ display: 'flex', justifyContent: 'left', alignItems: 'center', width: '100%' }}>
<Pagination
current={filters.page}
total={total}
pageSize={filters.limit}
showSizeChanger
pageSizeOptions={['2', '5', '10', '20', '50', '100']}
onShowSizeChange={(current, size) => {
setFilters((prevFilters) => ({ ...prevFilters, limit: size, page: 1 })); // Reset to first page when page size changes
}}
onChange={(pageNumber) => {
setFilters((prevFilters) => ({ ...prevFilters, page: pageNumber }));
}}
itemRender={(page, type, originalElement) => {
if (type === 'page') {
if (page === filters.page) {
return <span style={{ margin: '0 8px' }}>{page}</span>;
}
if (page === 1 || page === lastPage) {
return <a style={{ margin: '0 8px' }}>{page}</a>;
}
if (page === filters.page + 1) {
return <span style={{ margin: '0 8px' }}>...</span>;
}
return null;
}
if (type === 'prev') {
return <a style={{ margin: '0 8px' }}> &lt;</a>;
}
if (type === 'next') {
return <a style={{ margin: '0 8px' }}>&gt;</a>;
}
return null;
}}
/>
</Space>
</Space>
);
}
Expand Down
Loading