Files
frontend-app-discussions/src/discussions/posts/data/selectors.js
sundasnoreen12 c1478dbb41 fix: fixed dynamic learner profile issue (#493)
* fix: fixed dynamic URL issue

* refactor: removed unused selectors

---------

Co-authored-by: sundasnoreen12 <sundasnoreen12@ggmail.com>
2023-04-05 16:21:25 +05:00

47 lines
1.3 KiB
JavaScript

/* eslint-disable import/prefer-default-export */
import { createSelector } from '@reduxjs/toolkit';
const selectThreads = state => state.threads.threadsById;
const mapIdsToThreads = (ids, threads) => ids.map(id => threads?.[id]);
export const selectPostEditorVisible = state => state.threads.postEditorVisible;
export const selectTopicThreads = topicIds => createSelector(
[
state => (topicIds || []).flatMap(topicId => state.threads.threadsInTopic[topicId] || []),
selectThreads,
],
mapIdsToThreads,
);
export const selectThread = threadId => createSelector(
[selectThreads],
(threads) => threads?.[threadId],
);
export const selectAllThreadsOnPage = (page) => createSelector(
[
state => state.threads.pages[page] || [],
selectThreads,
],
mapIdsToThreads,
);
export const selectAllThreads = createSelector(
[
state => state.threads.pages,
selectThreads,
],
(pages, threads) => pages.flatMap(ids => mapIdsToThreads(ids, threads)),
);
export const threadsLoadingStatus = () => state => state.threads.status;
export const selectThreadSorting = () => state => state.threads.sortedBy;
export const selectThreadFilters = () => state => state.threads.filters;
export const selectThreadNextPage = () => state => state.threads.nextPage;