diff --git a/packages/core/dev-test/config.yml b/packages/core/dev-test/config.yml index 4129b4274..e77d14bd7 100644 --- a/packages/core/dev-test/config.yml +++ b/packages/core/dev-test/config.yml @@ -39,6 +39,7 @@ collections: field: title create: true view_filters: + default: posts-with-index filters: - name: posts-with-index label: Posts With Index @@ -53,6 +54,7 @@ collections: field: draft pattern: true view_groups: + default: by-year groups: - name: by-year label: Year diff --git a/packages/core/dev-test/data.js b/packages/core/dev-test/data.js index d1a1dcdf4..6a92cb395 100644 --- a/packages/core/dev-test/data.js +++ b/packages/core/dev-test/data.js @@ -34,6 +34,10 @@ window.repoFiles = { content: '---\ntitle: This post should not appear because the extension is different\nimage: /assets/uploads/moby-dick.jpg\ndate: 2015-02-16T00:00:00.000Z\ndescription: YAML front matter post\ncategory: yaml\ntags:\n - yaml---\n\n# I Am a Title in Markdown\n\nHello, world\n\n* One Thing\n* Another Thing\n* A Third Thing\n', }, + '2015-02-15-this-is-post-number-2015.md': { + content: + '+++\ntitle = "This is post #2015"\nimage = "/assets/uploads/moby-dick.jpg"\ndate = "2015-02-15T00:00:00.000Z"\n+++\n\n# I Am a Title in Markdown\n\nHello, world\n\n* One Thing\n* Another Thing\n* A Third Thing\n', + }, }, _faqs: { 'what-is-static-cms.md': { diff --git a/packages/core/src/actions/entries.ts b/packages/core/src/actions/entries.ts index 698ff2a40..4df27ab27 100644 --- a/packages/core/src/actions/entries.ts +++ b/packages/core/src/actions/entries.ts @@ -338,13 +338,8 @@ export function groupByField(collection: CollectionWithDefaults, group: ViewGrou return async (dispatch: ThunkDispatch, getState: () => RootState) => { const state = getState(); const isFetching = selectIsFetching(state, collection.name); - dispatch({ - type: GROUP_ENTRIES_REQUEST, - payload: { - collection: collection.name, - group, - }, - }); + dispatch(groupEntriesRequest(collection, group)); + if (isFetching) { return; } diff --git a/packages/core/src/components/collections/CollectionView.tsx b/packages/core/src/components/collections/CollectionView.tsx index ab9e97aa4..bf577642c 100644 --- a/packages/core/src/components/collections/CollectionView.tsx +++ b/packages/core/src/components/collections/CollectionView.tsx @@ -189,22 +189,37 @@ const CollectionView: FC = ({ const sortGroupFilterEntries = () => { setTimeout(async () => { if (defaultSort && defaultSort.field) { - await onSortClick(defaultSort.field, defaultSort.direction ?? SORT_DIRECTION_ASCENDING); + const isDefaultSortActive = Boolean( + Object.values(sort).find(s => s.key === defaultSort.field), + ); + if (!isDefaultSortActive) { + await onSortClick(defaultSort.field, defaultSort.direction ?? SORT_DIRECTION_ASCENDING); + } } if (defaultViewGroupName) { - const defaultViewGroup = viewGroups?.groups.find(g => g.name === defaultViewGroupName); - if (defaultViewGroup) { - await onGroupClick(defaultViewGroup); + const isDefaultGroupActive = Boolean( + Object.values(group).find(g => g.name === defaultViewGroupName && g.active), + ); + if (!isDefaultGroupActive) { + const defaultViewGroup = viewGroups?.groups.find(g => g.name === defaultViewGroupName); + if (defaultViewGroup) { + await onGroupClick(defaultViewGroup); + } } } if (defaultViewFilterName) { - const defaultViewFilter = viewFilters?.filters.find( - f => f.name === defaultViewFilterName, + const isDefaultFilterActive = Boolean( + Object.values(filter).find(f => f.name === defaultViewFilterName && f.active), ); - if (defaultViewFilter) { - await onFilterClick(defaultViewFilter); + if (!isDefaultFilterActive) { + const defaultViewFilter = viewFilters?.filters.find( + f => f.name === defaultViewFilterName, + ); + if (defaultViewFilter) { + await onFilterClick(defaultViewFilter); + } } } @@ -219,17 +234,8 @@ const CollectionView: FC = ({ return () => { alive = false; }; - }, [ - collection, - onFilterClick, - onGroupClick, - onSortClick, - prevCollection, - readyToLoad, - sort, - viewFilters?.filters, - viewGroups?.groups, - ]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [collection, onFilterClick, onGroupClick, onSortClick, prevCollection, readyToLoad]); const collectionDescription = collection?.description;