Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
455a8b4
Pagination code added
DrizzyOVO Jan 27, 2024
24363b3
More changes
DrizzyOVO Jan 28, 2024
2614886
Merge branch 'develop' into develop
raclim Jul 22, 2024
5c52349
Merge branch 'develop' into develop
raclim Aug 2, 2024
de0d0fe
Merge branch 'develop' into develop
raclim Aug 2, 2024
2c8839d
Merge branch 'develop' into DrizzyOVO/develop
raclim Jan 23, 2025
721eebb
style: adjust colors and provide more padding
raclim Jan 28, 2025
efc886c
refactor: create new pagination component
raclim Jan 28, 2025
74ce8b5
update controller, reducer, selector to limit queries - could be brea…
raclim Jan 28, 2025
d668cc2
update SketchList file with Pagination component and metadata
raclim Jan 28, 2025
21c117e
Merge branch 'develop' into feat/pagination-copy
raclim Feb 24, 2025
3111d2f
Merge branch 'develop' into feat/pagination-copy
raclim Jan 15, 2026
e3ab5fb
fix merge issues in getProjectsForUser controller
raclim Jan 15, 2026
d5a4982
Merge branch 'develop' into feat/pagination-copy
raclim Jan 23, 2026
6d4a3ee
update pagination component and styling
raclim Jan 27, 2026
b080577
update reducers, actions
raclim Jan 27, 2026
d1e7175
update sketchlist and addtocollectionlist ui
raclim Jan 27, 2026
5c542c1
remove extra string
raclim Jan 27, 2026
6fd573d
remove sorting and filtering selectors for search
raclim Jan 27, 2026
2fb4389
update projects controller with pagination
raclim Jan 27, 2026
49eafd7
Merge branch 'develop' into feat/pagination-copy
raclim Feb 3, 2026
d040e0a
address redux errors
raclim Feb 8, 2026
a03b8e7
Merge branch 'develop' into feat/pagination-copy
raclim Feb 8, 2026
0659881
update tests for sketchlist and create tests for addtocollectionsketc…
raclim Feb 9, 2026
765b0a6
update reducer to use correct project state after obj structure changes
raclim Feb 9, 2026
078f218
remove misc changes
raclim Feb 9, 2026
8a4b900
add eng translations for pagination
raclim Feb 9, 2026
910fa29
update test descriptions
raclim Feb 9, 2026
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
2 changes: 2 additions & 0 deletions client/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const RESET_PROJECT = 'RESET_PROJECT';

export const SET_PROJECT = 'SET_PROJECT';
export const SET_PROJECTS = 'SET_PROJECTS';
export const SET_PROJECTS_FOR_COLLECTION_LIST =
'SET_PROJECTS_FOR_COLLECTION_LIST';

export const SET_COLLECTIONS = 'SET_COLLECTIONS';
export const CREATE_COLLECTION = 'CREATED_COLLECTION';
Expand Down
85 changes: 57 additions & 28 deletions client/modules/IDE/actions/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,60 @@ import { apiClient } from '../../../utils/apiClient';
import * as ActionTypes from '../../../constants';
import { startLoader, stopLoader } from '../reducers/loading';

// eslint-disable-next-line
export function getProjects(username) {
return (dispatch) => {
dispatch(startLoader());
let url;
if (username) {
url = `/${username}/projects`;
} else {
url = '/projects';
}
return apiClient
.get(url)
.then((response) => {
dispatch({
type: ActionTypes.SET_PROJECTS,
projects: response.data
});
dispatch(stopLoader());
})
.catch((error) => {
dispatch({
type: ActionTypes.ERROR,
error: error?.response?.data
});
dispatch(stopLoader());
});
};
}
const buildProjectsUrl = (username, options = {}) => {
const {
page = 1,
limit = 10,
sortField = 'updatedAt',
sortDir = 'desc',
q = ''
} = options;

const base = username
? `/${encodeURIComponent(username)}/projects`
: '/projects';

const params = new URLSearchParams({
page: String(page),
limit: String(limit),
sortField,
sortDir
});

const trimmed = q.trim();

if (trimmed) {
params.set('q', trimmed);
}

return `${base}?${params.toString()}`;
};

const fetchProjects = (username, options, successType) => (dispatch) => {
dispatch(startLoader());

const url = buildProjectsUrl(username, options);

return apiClient
.get(url)
.then((response) => {
dispatch({ type: successType, projects: response.data });
dispatch(stopLoader());
return response.data;
})
.catch((error) => {
dispatch({ type: ActionTypes.ERROR, error: error?.response?.data });
dispatch(stopLoader());
throw error;
});
};

export const getProjects = (username, options) =>
fetchProjects(username, options, ActionTypes.SET_PROJECTS);

export const getProjectsForCollectionList = (username, options) =>
fetchProjects(
username,
options,
ActionTypes.SET_PROJECTS_FOR_COLLECTION_LIST
);
63 changes: 51 additions & 12 deletions client/modules/IDE/components/AddToCollectionSketchList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Helmet } from 'react-helmet';
import { useDispatch, useSelector } from 'react-redux';
import { useTranslation } from 'react-i18next';
import { addToCollection, removeFromCollection } from '../actions/collections';
import { getProjects } from '../actions/projects';
import getSortedSketches from '../selectors/projects';
import { getProjectsForCollectionList } from '../actions/projects';
import { Loader } from '../../App/components/Loader';
import Pagination from './Pagination';
import QuickAddList from './QuickAddList';
import {
CollectionAddSketchWrapper,
Expand All @@ -20,16 +20,39 @@ const AddToCollectionSketchList = ({ collection }) => {

const username = useSelector((state) => state.user.username);

const sketches = useSelector(getSortedSketches);
const sketches = useSelector(
(state) => state.collectionsListProjects.projects
);

const paginationMeta = useSelector(
(state) => state.collectionsListProjects.metadata
);

const q = useSelector((state) => state.search.sketchSearchTerm);

const hasSketches = () => sketches?.length > 0;

const [page, setPage] = useState(1);
const limit = 10;

// TODO: improve loading state
const loading = useSelector((state) => state.loading);
const [hasLoadedData, setHasLoadedData] = useState(false);
const showLoader = loading && !hasLoadedData;

useEffect(() => {
dispatch(getProjects(username)).then(() => setHasLoadedData(true));
}, [dispatch, username]);
dispatch(
getProjectsForCollectionList(username, {
page,
limit,
q
})
).finally(() => setHasLoadedData(true));
}, [dispatch, username, page, q]);

useEffect(() => {
setPage(1);
}, [q]);

const handleCollectionAdd = (sketch) => {
dispatch(addToCollection(collection.id, sketch.id));
Expand All @@ -43,7 +66,8 @@ const AddToCollectionSketchList = ({ collection }) => {
...sketch,
url: `/${username}/sketches/${sketch.id}`,
isAdded: collection.items.some(
(item) => item.projectId === sketch.id && !item.isDeleted
(item) =>
(item.projectId || item.project?.id) === sketch.id && !item.isDeleted
)
}));

Expand All @@ -55,11 +79,23 @@ const AddToCollectionSketchList = ({ collection }) => {
return t('AddToCollectionSketchList.NoCollections');
}
return (
<QuickAddList
items={sketchesWithAddedStatus}
onAdd={handleCollectionAdd}
onRemove={handleCollectionRemove}
/>
<>
<QuickAddList
items={sketchesWithAddedStatus}
onAdd={handleCollectionAdd}
onRemove={handleCollectionRemove}
/>
{hasSketches() && (
<Pagination
page={page}
totalPages={paginationMeta.totalPages}
onPageChange={setPage}
limit={limit}
totalSketches={paginationMeta.totalProjects}
isOverlay
/>
)}
</>
);
};

Expand All @@ -81,7 +117,10 @@ AddToCollectionSketchList.propTypes = {
name: PropTypes.string.isRequired,
items: PropTypes.arrayOf(
PropTypes.shape({
projectId: PropTypes.string.isRequired,
projectId: PropTypes.string,
project: PropTypes.shape({
id: PropTypes.string
}),
isDeleted: PropTypes.bool
})
)
Expand Down
Loading