@elementor/editor-site-navigation 0.19.11 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/index.js +128 -50
  3. package/dist/index.mjs +124 -44
  4. package/package.json +5 -5
  5. package/src/api/post.ts +32 -4
  6. package/src/api/settings.ts +5 -9
  7. package/src/api/user.ts +20 -0
  8. package/src/components/panel/actions-menu/actions/__tests__/delete.test.tsx +8 -0
  9. package/src/components/panel/actions-menu/actions/__tests__/set-home.test.tsx +52 -0
  10. package/src/components/panel/actions-menu/actions/__tests__/view.test.tsx +4 -0
  11. package/src/components/panel/actions-menu/actions/delete.tsx +4 -1
  12. package/src/components/panel/actions-menu/actions/duplicate.tsx +5 -1
  13. package/src/components/panel/actions-menu/actions/rename.tsx +1 -0
  14. package/src/components/panel/actions-menu/actions/set-home.tsx +9 -1
  15. package/src/components/panel/add-new-button.tsx +3 -0
  16. package/src/components/panel/posts-list/__tests__/post-list-item.test.tsx +20 -0
  17. package/src/components/panel/posts-list/__tests__/posts-collapsible-list.test.tsx +56 -8
  18. package/src/components/panel/posts-list/collapsible-list.tsx +1 -1
  19. package/src/components/panel/posts-list/list-items/list-item-view.tsx +50 -29
  20. package/src/components/panel/posts-list/posts-collapsible-list.tsx +14 -7
  21. package/src/components/top-bar/__tests__/add-new-page.test.tsx +36 -0
  22. package/src/components/top-bar/__tests__/recently-edited.test.tsx +68 -0
  23. package/src/components/top-bar/create-post-list-item.tsx +3 -1
  24. package/src/components/top-bar/post-list-item.tsx +1 -0
  25. package/src/hooks/__tests__/use-homepage.test.ts +1 -1
  26. package/src/hooks/__tests__/use-posts.test.ts +44 -10
  27. package/src/hooks/use-posts.ts +25 -4
  28. package/src/hooks/use-user.ts +11 -0
  29. package/src/types.ts +8 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.21.0](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.20.0...@elementor/editor-site-navigation@0.21.0) (2024-01-29)
7
+
8
+
9
+ ### Features
10
+
11
+ * **editor-site-navigation:** pagination for pages panel ([#154](https://github.com/elementor/elementor-packages/issues/154)) ([1a1e1f4](https://github.com/elementor/elementor-packages/commit/1a1e1f46006988d10e0a7af292dbbc57644ed16f))
12
+
13
+
14
+
15
+
16
+
17
+ # [0.20.0](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.19.11...@elementor/editor-site-navigation@0.20.0) (2024-01-07)
18
+
19
+
20
+ ### Features
21
+
22
+ * **editor-site-navigation:** add permission based UI disabling [ED-13216] ([#152](https://github.com/elementor/elementor-packages/issues/152)) ([45f3e99](https://github.com/elementor/elementor-packages/commit/45f3e9955149045487ce21db9006c703e7777006))
23
+
24
+
25
+
26
+
27
+
6
28
  ## [0.19.11](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.19.10...@elementor/editor-site-navigation@0.19.11) (2024-01-04)
7
29
 
8
30
 
package/dist/index.js CHANGED
@@ -153,6 +153,7 @@ function PostListItem({ post, closePopup, ...props }) {
153
153
  return /* @__PURE__ */ React3.createElement(
154
154
  import_ui3.MenuItem,
155
155
  {
156
+ disabled: !post.user_can.edit,
156
157
  onClick: async () => {
157
158
  closePopup();
158
159
  await navigateToDocument(post.id);
@@ -208,12 +209,41 @@ async function addNewPage() {
208
209
  var import_icons3 = require("@elementor/icons");
209
210
  var import_i18n = require("@wordpress/i18n");
210
211
  var import_editor_documents2 = require("@elementor/editor-documents");
212
+
213
+ // src/hooks/use-user.ts
214
+ var import_query2 = require("@elementor/query");
215
+
216
+ // src/api/user.ts
217
+ var import_api_fetch3 = __toESM(require("@wordpress/api-fetch"));
218
+ var getUser = () => {
219
+ const baseUri = "/wp/v2/users/me";
220
+ const keys = ["capabilities"];
221
+ const queryParams = new URLSearchParams({
222
+ _fields: keys.join(","),
223
+ context: "edit"
224
+ });
225
+ const uri = baseUri + "?" + queryParams.toString();
226
+ return (0, import_api_fetch3.default)({ path: uri });
227
+ };
228
+
229
+ // src/hooks/use-user.ts
230
+ var userQueryKey = () => ["site-navigation", "user"];
231
+ function useUser() {
232
+ return (0, import_query2.useQuery)({
233
+ queryKey: userQueryKey(),
234
+ queryFn: () => getUser()
235
+ });
236
+ }
237
+
238
+ // src/components/top-bar/create-post-list-item.tsx
211
239
  function CreatePostListItem({ closePopup, ...props }) {
212
240
  const { create, isLoading } = useCreatePage();
213
241
  const navigateToDocument = (0, import_editor_documents2.__useNavigateToDocument)();
242
+ const { data: user } = useUser();
214
243
  return /* @__PURE__ */ React4.createElement(
215
244
  import_ui4.MenuItem,
216
245
  {
246
+ disabled: isLoading || !user?.capabilities?.edit_pages,
217
247
  onClick: async () => {
218
248
  const { id } = await create();
219
249
  closePopup();
@@ -314,10 +344,10 @@ var import_icons15 = require("@elementor/icons");
314
344
  var import_ui15 = require("@elementor/ui");
315
345
 
316
346
  // src/hooks/use-posts.ts
317
- var import_query2 = require("@elementor/query");
347
+ var import_query3 = require("@elementor/query");
318
348
 
319
349
  // src/api/post.ts
320
- var import_api_fetch3 = __toESM(require("@wordpress/api-fetch"));
350
+ var import_api_fetch4 = __toESM(require("@wordpress/api-fetch"));
321
351
  var import_i18n3 = require("@wordpress/i18n");
322
352
  var postTypesMap = {
323
353
  page: {
@@ -328,21 +358,32 @@ var postTypesMap = {
328
358
  rest_base: "pages"
329
359
  }
330
360
  };
331
- var getRequest2 = (postTypeSlug) => {
361
+ var POST_PER_PAGE = 10;
362
+ var getRequest2 = async (postTypeSlug, page) => {
332
363
  const baseUri = `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`;
333
- const keys = ["id", "type", "title", "link", "status"];
364
+ const keys = ["id", "type", "title", "link", "status", "user_can"];
334
365
  const queryParams = new URLSearchParams({
335
366
  status: "any",
336
- per_page: "-1",
337
367
  order: "asc",
368
+ page: page.toString(),
369
+ per_page: POST_PER_PAGE.toString(),
338
370
  _fields: keys.join(",")
339
371
  });
340
372
  const uri = baseUri + "?" + queryParams.toString();
341
- return (0, import_api_fetch3.default)({ path: uri });
373
+ const result = await (0, import_api_fetch4.default)({ path: uri, parse: false });
374
+ const data = await result.json();
375
+ const totalPages = Number(result.headers.get("x-wp-totalpages"));
376
+ const totalPosts = Number(result.headers.get("x-wp-total"));
377
+ return {
378
+ data,
379
+ totalPages,
380
+ totalPosts,
381
+ currentPage: page
382
+ };
342
383
  };
343
384
  var createRequest = (postTypeSlug, newPost) => {
344
385
  const path = `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`;
345
- return (0, import_api_fetch3.default)({
386
+ return (0, import_api_fetch4.default)({
346
387
  path,
347
388
  method: "POST",
348
389
  data: newPost
@@ -351,7 +392,7 @@ var createRequest = (postTypeSlug, newPost) => {
351
392
  var updateRequest = (postTypeSlug, updatedPost) => {
352
393
  const path = `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`;
353
394
  const { id, ...data } = updatedPost;
354
- return (0, import_api_fetch3.default)({
395
+ return (0, import_api_fetch4.default)({
355
396
  path: `${path}/${id}`,
356
397
  method: "POST",
357
398
  data
@@ -359,14 +400,14 @@ var updateRequest = (postTypeSlug, updatedPost) => {
359
400
  };
360
401
  var deleteRequest = (postTypeSlug, postId) => {
361
402
  const path = `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`;
362
- return (0, import_api_fetch3.default)({
403
+ return (0, import_api_fetch4.default)({
363
404
  path: `${path}/${postId}`,
364
405
  method: "DELETE"
365
406
  });
366
407
  };
367
408
  var duplicateRequest = (originalPost) => {
368
409
  const path = `/elementor/v1/site-navigation/duplicate-post`;
369
- return (0, import_api_fetch3.default)({
410
+ return (0, import_api_fetch4.default)({
370
411
  path,
371
412
  method: "POST",
372
413
  data: {
@@ -378,11 +419,26 @@ var duplicateRequest = (originalPost) => {
378
419
 
379
420
  // src/hooks/use-posts.ts
380
421
  var postsQueryKey = (postTypeSlug) => ["site-navigation", "posts", postTypeSlug];
422
+ var flattenData = (data) => {
423
+ if (!data) {
424
+ return data;
425
+ }
426
+ const flattened = [];
427
+ data.pages.forEach((page) => {
428
+ flattened.push(...page.data);
429
+ });
430
+ return flattened;
431
+ };
381
432
  function usePosts(postTypeSlug) {
382
- return (0, import_query2.useQuery)({
433
+ const query = (0, import_query3.useInfiniteQuery)({
383
434
  queryKey: postsQueryKey(postTypeSlug),
384
- queryFn: () => getRequest2(postTypeSlug)
435
+ queryFn: ({ pageParam = 1 }) => getRequest2(postTypeSlug, pageParam),
436
+ initialPageParam: 1,
437
+ getNextPageParam: (lastPage) => {
438
+ return lastPage.currentPage < lastPage.totalPages ? lastPage.currentPage + 1 : void 0;
439
+ }
385
440
  });
441
+ return { ...query, data: { posts: flattenData(query.data), total: query.data?.pages[0]?.totalPosts ?? 0 } };
386
442
  }
387
443
 
388
444
  // src/contexts/post-list-context.tsx
@@ -473,7 +529,7 @@ function CollapsibleList({
473
529
  unmountOnExit: true
474
530
  },
475
531
  /* @__PURE__ */ React7.createElement(import_ui6.List, { dense: true }, children)
476
- ), /* @__PURE__ */ React7.createElement(import_ui6.Divider, { sx: { my: 3 } }));
532
+ ), /* @__PURE__ */ React7.createElement(import_ui6.Divider, { sx: { mt: 1 } }));
477
533
  }
478
534
 
479
535
  // src/components/panel/posts-list/post-list-item.tsx
@@ -483,23 +539,23 @@ var React20 = __toESM(require("react"));
483
539
  var React9 = __toESM(require("react"));
484
540
 
485
541
  // src/hooks/use-posts-actions.ts
486
- var import_query3 = require("@elementor/query");
542
+ var import_query4 = require("@elementor/query");
487
543
  function usePostActions(postTypeSlug) {
488
544
  const invalidatePosts = useInvalidatePosts(postTypeSlug);
489
545
  const onSuccess = () => invalidatePosts({ exact: true });
490
- const createPost = (0, import_query3.useMutation)({
546
+ const createPost = (0, import_query4.useMutation)({
491
547
  mutationFn: (newPost) => createRequest(postTypeSlug, newPost),
492
548
  onSuccess
493
549
  });
494
- const updatePost = (0, import_query3.useMutation)({
550
+ const updatePost = (0, import_query4.useMutation)({
495
551
  mutationFn: (updatedPost) => updateRequest(postTypeSlug, updatedPost),
496
552
  onSuccess
497
553
  });
498
- const deletePost = (0, import_query3.useMutation)({
554
+ const deletePost = (0, import_query4.useMutation)({
499
555
  mutationFn: (postId) => deleteRequest(postTypeSlug, postId),
500
556
  onSuccess
501
557
  });
502
- const duplicatePost = (0, import_query3.useMutation)({
558
+ const duplicatePost = (0, import_query4.useMutation)({
503
559
  mutationFn: (originalPost) => duplicateRequest(originalPost),
504
560
  onSuccess
505
561
  });
@@ -511,7 +567,7 @@ function usePostActions(postTypeSlug) {
511
567
  };
512
568
  }
513
569
  function useInvalidatePosts(postTypeSlug) {
514
- const queryClient = (0, import_query3.useQueryClient)();
570
+ const queryClient = (0, import_query4.useQueryClient)();
515
571
  return (options = {}) => {
516
572
  const queryKey = postsQueryKey(postTypeSlug);
517
573
  queryClient.invalidateQueries({ queryKey: recentPostsQueryKey }, options);
@@ -779,6 +835,7 @@ function Rename({ post }) {
779
835
  title: (0, import_i18n7.__)("Rename", "elementor"),
780
836
  icon: import_icons7.EraseIcon,
781
837
  MenuItemProps: {
838
+ disabled: !post.user_can.edit,
782
839
  onClick: () => {
783
840
  setEditMode({
784
841
  mode: "rename",
@@ -798,6 +855,7 @@ var import_icons8 = require("@elementor/icons");
798
855
  var import_i18n8 = require("@wordpress/i18n");
799
856
  function Duplicate({ post, popupState }) {
800
857
  const { setEditMode } = usePostListContext();
858
+ const { data: user } = useUser();
801
859
  const onClick = () => {
802
860
  popupState.close();
803
861
  setEditMode({
@@ -808,12 +866,14 @@ function Duplicate({ post, popupState }) {
808
866
  }
809
867
  });
810
868
  };
869
+ const isDisabled = !user?.capabilities?.edit_pages;
811
870
  return /* @__PURE__ */ React15.createElement(
812
871
  ActionMenuItem,
813
872
  {
814
873
  title: (0, import_i18n8.__)("Duplicate", "elementor"),
815
874
  icon: import_icons8.CopyIcon,
816
875
  MenuItemProps: {
876
+ disabled: isDisabled,
817
877
  onClick
818
878
  }
819
879
  }
@@ -831,13 +891,15 @@ function Delete({ post }) {
831
891
  const [isDialogOpen, setIsDialogOpen] = (0, import_react6.useState)(false);
832
892
  const activeDocument = (0, import_editor_documents7.__useActiveDocument)();
833
893
  const isPostActive = activeDocument?.id === post.id;
894
+ const userCanDelete = post.user_can.delete;
895
+ const isDisabled = !userCanDelete || post.isHome || isPostActive;
834
896
  return /* @__PURE__ */ React16.createElement(React16.Fragment, null, /* @__PURE__ */ React16.createElement(
835
897
  ActionMenuItem,
836
898
  {
837
899
  title: (0, import_i18n9.__)("Delete", "elementor"),
838
900
  icon: import_icons9.TrashIcon,
839
901
  MenuItemProps: {
840
- disabled: post.isHome || isPostActive,
902
+ disabled: isDisabled,
841
903
  onClick: () => setIsDialogOpen(true),
842
904
  sx: { "&:hover": { color: "error.main" } }
843
905
  }
@@ -902,21 +964,17 @@ var import_icons11 = require("@elementor/icons");
902
964
  var import_i18n11 = require("@wordpress/i18n");
903
965
 
904
966
  // src/hooks/use-homepage-actions.ts
905
- var import_query5 = require("@elementor/query");
967
+ var import_query6 = require("@elementor/query");
906
968
 
907
969
  // src/api/settings.ts
908
- var import_api_fetch4 = __toESM(require("@wordpress/api-fetch"));
970
+ var import_api_fetch5 = __toESM(require("@wordpress/api-fetch"));
909
971
  var getSettings = () => {
910
- const baseUri = "/wp/v2/settings";
911
- const keys = ["show_on_front", "page_on_front"];
912
- const queryParams = new URLSearchParams({
913
- _fields: keys.join(",")
914
- });
915
- const uri = baseUri + "?" + queryParams.toString();
916
- return (0, import_api_fetch4.default)({ path: uri });
972
+ const baseUri = "/elementor/v1/site-navigation/homepage";
973
+ const uri = baseUri;
974
+ return (0, import_api_fetch5.default)({ path: uri });
917
975
  };
918
976
  var updateSettings = (settings) => {
919
- return (0, import_api_fetch4.default)({
977
+ return (0, import_api_fetch5.default)({
920
978
  path: "/wp/v2/settings",
921
979
  method: "POST",
922
980
  data: settings
@@ -924,10 +982,10 @@ var updateSettings = (settings) => {
924
982
  };
925
983
 
926
984
  // src/hooks/use-homepage.ts
927
- var import_query4 = require("@elementor/query");
985
+ var import_query5 = require("@elementor/query");
928
986
  var settingsQueryKey = () => ["site-navigation", "homepage"];
929
987
  function useHomepage() {
930
- return (0, import_query4.useQuery)({
988
+ return (0, import_query5.useQuery)({
931
989
  queryKey: settingsQueryKey(),
932
990
  queryFn: () => getSettings()
933
991
  });
@@ -937,14 +995,14 @@ function useHomepage() {
937
995
  function useHomepageActions() {
938
996
  const invalidateSettings = useInvalidateSettings();
939
997
  const onSuccess = async () => invalidateSettings({ exact: true });
940
- const updateSettingsMutation = (0, import_query5.useMutation)({
998
+ const updateSettingsMutation = (0, import_query6.useMutation)({
941
999
  mutationFn: (settings) => updateSettings(settings),
942
1000
  onSuccess
943
1001
  });
944
1002
  return { updateSettingsMutation };
945
1003
  }
946
1004
  function useInvalidateSettings() {
947
- const queryClient = (0, import_query5.useQueryClient)();
1005
+ const queryClient = (0, import_query6.useQueryClient)();
948
1006
  return (options = {}) => {
949
1007
  const queryKey = settingsQueryKey();
950
1008
  return queryClient.invalidateQueries({ queryKey }, options);
@@ -956,6 +1014,7 @@ var import_ui11 = require("@elementor/ui");
956
1014
  function SetHome({ post, closeMenu }) {
957
1015
  const { updateSettingsMutation } = useHomepageActions();
958
1016
  const { setError } = usePostListContext();
1017
+ const { data: user } = useUser();
959
1018
  const handleClick = async () => {
960
1019
  try {
961
1020
  await updateSettingsMutation.mutateAsync({ show_on_front: "page", page_on_front: post.id });
@@ -965,13 +1024,17 @@ function SetHome({ post, closeMenu }) {
965
1024
  closeMenu();
966
1025
  }
967
1026
  };
1027
+ const canManageOptions = !!user?.capabilities?.manage_options;
1028
+ const isPostPublished = post.status === "publish";
1029
+ const isPostHomepage = !!post.isHome;
1030
+ const isDisabled = !canManageOptions || isPostHomepage || !isPostPublished || updateSettingsMutation.isPending;
968
1031
  return /* @__PURE__ */ React18.createElement(
969
1032
  ActionMenuItem,
970
1033
  {
971
1034
  title: (0, import_i18n11.__)("Set as homepage", "elementor"),
972
1035
  icon: !updateSettingsMutation.isPending ? import_icons11.HomeIcon : import_ui11.CircularProgress,
973
1036
  MenuItemProps: {
974
- disabled: !!post.isHome || post.status !== "publish" || updateSettingsMutation.isPending,
1037
+ disabled: isDisabled,
975
1038
  onClick: handleClick
976
1039
  }
977
1040
  }
@@ -980,6 +1043,21 @@ function SetHome({ post, closeMenu }) {
980
1043
 
981
1044
  // src/components/panel/posts-list/list-items/list-item-view.tsx
982
1045
  var import_i18n12 = require("@wordpress/i18n");
1046
+ var DisabledPostTooltip = ({ children, isDisabled }) => {
1047
+ if (isDisabled) {
1048
+ const title = /* @__PURE__ */ React19.createElement(import_ui12.Typography, { variant: "caption" }, "You cannot edit this page.", /* @__PURE__ */ React19.createElement("br", null), "To edit it directly, contact the site owner");
1049
+ return /* @__PURE__ */ React19.createElement(
1050
+ import_ui12.Tooltip,
1051
+ {
1052
+ title,
1053
+ placement: "bottom",
1054
+ arrow: false
1055
+ },
1056
+ children
1057
+ );
1058
+ }
1059
+ return /* @__PURE__ */ React19.createElement(React19.Fragment, null, children);
1060
+ };
983
1061
  function ListItemView({ post }) {
984
1062
  const activeDocument = (0, import_editor_documents8.__useActiveDocument)();
985
1063
  const navigateToDocument = (0, import_editor_documents8.__useNavigateToDocument)();
@@ -991,7 +1069,8 @@ function ListItemView({ post }) {
991
1069
  const isActive = activeDocument?.id === post.id;
992
1070
  const status = isActive ? activeDocument?.status.value : post.status;
993
1071
  const title = isActive ? activeDocument?.title : post.title.rendered;
994
- return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement(
1072
+ const isDisabled = !post.user_can.edit;
1073
+ return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement(DisabledPostTooltip, { isDisabled }, /* @__PURE__ */ React19.createElement(
995
1074
  import_ui12.ListItem,
996
1075
  {
997
1076
  disablePadding: true,
@@ -1009,6 +1088,7 @@ function ListItemView({ post }) {
1009
1088
  import_ui12.ListItemButton,
1010
1089
  {
1011
1090
  selected: isActive,
1091
+ disabled: isDisabled,
1012
1092
  onClick: () => {
1013
1093
  if (!isActive) {
1014
1094
  navigateToDocument(post.id);
@@ -1016,16 +1096,10 @@ function ListItemView({ post }) {
1016
1096
  },
1017
1097
  dense: true
1018
1098
  },
1019
- /* @__PURE__ */ React19.createElement(
1020
- import_ui12.ListItemText,
1021
- {
1022
- disableTypography: true
1023
- },
1024
- /* @__PURE__ */ React19.createElement(PageTitleAndStatus, { title, status })
1025
- ),
1099
+ /* @__PURE__ */ React19.createElement(import_ui12.ListItemText, { disableTypography: true }, /* @__PURE__ */ React19.createElement(PageTitleAndStatus, { title, status })),
1026
1100
  post.isHome && /* @__PURE__ */ React19.createElement(import_icons12.HomeIcon, { titleAccess: (0, import_i18n12.__)("Homepage", "elementor"), color: "disabled" })
1027
1101
  )
1028
- ), /* @__PURE__ */ React19.createElement(
1102
+ )), /* @__PURE__ */ React19.createElement(
1029
1103
  import_ui12.Menu,
1030
1104
  {
1031
1105
  PaperProps: { sx: { mt: 2, width: 200 } },
@@ -1066,11 +1140,13 @@ var import_icons13 = require("@elementor/icons");
1066
1140
  var import_i18n13 = require("@wordpress/i18n");
1067
1141
  function AddNewButton() {
1068
1142
  const { setEditMode } = usePostListContext();
1143
+ const { data: user } = useUser();
1069
1144
  return /* @__PURE__ */ React21.createElement(
1070
1145
  import_ui13.Button,
1071
1146
  {
1072
1147
  size: "small",
1073
1148
  startIcon: /* @__PURE__ */ React21.createElement(import_icons13.PlusIcon, null),
1149
+ disabled: !user?.capabilities?.edit_pages,
1074
1150
  onClick: () => {
1075
1151
  setEditMode({ mode: "create", details: {} });
1076
1152
  },
@@ -1107,8 +1183,8 @@ function ErrorState() {
1107
1183
  // src/components/panel/posts-list/posts-collapsible-list.tsx
1108
1184
  function PostsCollapsibleList({ isOpenByDefault = false }) {
1109
1185
  const { type, editMode } = usePostListContext();
1110
- const { data: posts, isLoading: postsLoading, isError: postsError } = usePosts(type);
1111
- const { data: homepageSettings } = useHomepage();
1186
+ const { data: { posts, total }, isLoading: postsLoading, isError: postsError, fetchNextPage, hasNextPage, isFetchingNextPage } = usePosts(type);
1187
+ const { data: homepageId } = useHomepage();
1112
1188
  if (postsError) {
1113
1189
  return /* @__PURE__ */ React23.createElement(ErrorState, null);
1114
1190
  }
@@ -1123,9 +1199,7 @@ function PostsCollapsibleList({ isOpenByDefault = false }) {
1123
1199
  /* @__PURE__ */ React23.createElement(import_ui15.Skeleton, { sx: { my: 4 }, animation: "wave", variant: "rounded", width: "110px", height: "28px" })
1124
1200
  ), /* @__PURE__ */ React23.createElement(import_ui15.Box, null, /* @__PURE__ */ React23.createElement(import_ui15.Skeleton, { sx: { my: 3 }, animation: "wave", variant: "rounded", width: "100%", height: "24px" }), /* @__PURE__ */ React23.createElement(import_ui15.Skeleton, { sx: { my: 3 }, animation: "wave", variant: "rounded", width: "70%", height: "24px" }), /* @__PURE__ */ React23.createElement(import_ui15.Skeleton, { sx: { my: 3 }, animation: "wave", variant: "rounded", width: "70%", height: "24px" }), /* @__PURE__ */ React23.createElement(import_ui15.Skeleton, { sx: { my: 3 }, animation: "wave", variant: "rounded", width: "70%", height: "24px" })));
1125
1201
  }
1126
- const label = `${postTypesMap[type].labels.plural_name} (${posts.length.toString()})`;
1127
- const isHomepageSet = homepageSettings?.show_on_front === "page" && !!homepageSettings?.page_on_front;
1128
- const homepageId = isHomepageSet ? homepageSettings.page_on_front : null;
1202
+ const label = `${postTypesMap[type].labels.plural_name} (${total.toString()})`;
1129
1203
  const mappedPosts = posts.map((post) => {
1130
1204
  if (post.id === homepageId) {
1131
1205
  return { ...post, isHome: true };
@@ -1163,7 +1237,11 @@ function PostsCollapsibleList({ isOpenByDefault = false }) {
1163
1237
  sortedPosts.map((post) => {
1164
1238
  return /* @__PURE__ */ React23.createElement(PostListItem2, { key: post.id, post });
1165
1239
  }),
1166
- ["duplicate", "create"].includes(editMode.mode) && /* @__PURE__ */ React23.createElement(PostListItem2, null)
1240
+ ["duplicate", "create"].includes(editMode.mode) && /* @__PURE__ */ React23.createElement(PostListItem2, null),
1241
+ hasNextPage && /* @__PURE__ */ React23.createElement(import_ui15.Box, { sx: {
1242
+ display: "flex",
1243
+ justifyContent: "center"
1244
+ } }, /* @__PURE__ */ React23.createElement(import_ui15.Button, { onClick: fetchNextPage, color: "secondary" }, isFetchingNextPage ? /* @__PURE__ */ React23.createElement(import_ui15.CircularProgress, null) : "Load More"))
1167
1245
  )));
1168
1246
  }
1169
1247