Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
balanza committed Sep 2, 2024
1 parent d369cb9 commit c8d3e60
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions assets/js/pages/ActivityLogPage/ActivityLogPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ function ActivityLogPage() {
const [searchParams, setSearchParams] = useSearchParams(
resetPaginationToSearchParams(defaultItemsPerPage)()
);
const [activityLog, setActivityLog] = useState([]);
const [activityLogMetadata, setActivityLogMetadata] = useState({});
const [activityLogResponse, setActivityLogResponse] = useState({ data: [] });

const [isLoading, setLoading] = useState(true);
const [activityLogDetailModalOpen, setActivityLogDetailModalOpen] =
Expand All @@ -80,11 +79,10 @@ function ActivityLogPage() {
setLoading(true);
const params = searchParamsToAPIParams(searchParams);
getActivityLog(params)
.then(({ data: { data = [], ...metadata } = {} }) => {
setActivityLog(data);
setActivityLogMetadata(metadata);
.then(({ data }) => {
setActivityLogResponse(data);
})
.catch(() => setActivityLog([]))
.catch(() => setActivityLogResponse({ data: [] }))
.finally(() => {
setLoading(false);
});
Expand All @@ -109,28 +107,28 @@ function ActivityLogPage() {
</div>
<ActivityLogOverview
activityLogDetailModalOpen={activityLogDetailModalOpen}
activityLog={activityLog}
activityLog={activityLogResponse.data}
loading={isLoading}
onActivityLogEntryClick={() => setActivityLogDetailModalOpen(true)}
onCloseActivityLogEntryDetails={() =>
setActivityLogDetailModalOpen(false)
}
/>
<PaginationPrevNext
hasPrev={activityLogMetadata.pagination?.has_previous_page}
hasNext={activityLogMetadata.pagination?.has_next_page}
hasPrev={activityLogResponse.pagination?.has_previous_page}
hasNext={activityLogResponse.pagination?.has_next_page}
currentItemsPerPage={itemsPerPage}
itemsPerPageOptions={itemsPerPageOptions}
onSelect={pipe(
(selection) =>
selection === 'prev'
? {
last: itemsPerPage,
before: activityLogMetadata.pagination.start_cursor,
before: activityLogResponse.pagination?.start_cursor,
}
: {
first: itemsPerPage,
after: activityLogMetadata.pagination.end_cursor,
after: activityLogResponse.pagination?.end_cursor,
},
setPaginationToSearchParams,
setSearchParams
Expand Down

0 comments on commit c8d3e60

Please sign in to comment.