feat: show empty state on posts pages [BD-38] [TNL-9484] [SE-5347] (#65)

When a user browses the discussion pages, show a page showing
that there is no data, rather than a blank page.

This PR implements the designs for this page while refactoring the
DiscussionHome component so that it doesn't get much larger.

- Created a hooks file and move some of the larger hooks in there.
- Added selectors for the state that would be needed for the
  components.
- Split the DiscussionHome into DiscussionContent and
  DiscussionSidebar to make it clearer where certain things get
  rendered.
- Adds a message to the sidebar to display No Results when
  appropriate.
- Added the NoResults component to show when filtering posts and there
  is nothing to show.
This commit is contained in:
Keith Grootboom
2022-03-09 14:15:32 +02:00
committed by GitHub
parent 4d8dff93a6
commit c65230d5da
19 changed files with 865 additions and 98 deletions

View File

@@ -0,0 +1,59 @@
import React from 'react';
import propTypes from 'prop-types';
import { useDispatch, useSelector } from 'react-redux';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { useIsOnDesktop } from '../data/hooks';
import { selectAreThreadsFiltered, selectPostThreadCount } from '../data/selectors';
import messages from '../messages';
import { messages as postMessages, showPostEditor } from '../posts';
import EmptyPage from './EmptyPage';
function EmptyPosts({ intl, subTitleMessage }) {
const dispatch = useDispatch();
const isFiltered = useSelector(selectAreThreadsFiltered);
const totalThreads = useSelector(selectPostThreadCount);
const isOnDesktop = useIsOnDesktop();
function addPost() {
return dispatch(showPostEditor());
}
let title = messages.noPostSelected;
let subTitle = null;
let action = null;
let actionText = null;
let fullWidth = false;
const isEmpty = [0, null].includes(totalThreads) && !isFiltered;
if (!(isOnDesktop || isEmpty)) {
return null;
} if (isEmpty) {
subTitle = subTitleMessage;
title = messages.emptyTitle;
action = addPost;
actionText = postMessages.addAPost;
fullWidth = true;
}
return (
<EmptyPage
title={intl.formatMessage(title)}
subTitle={subTitle ? intl.formatMessage(subTitle) : null}
action={action}
actionText={actionText ? intl.formatMessage(actionText) : null}
fullWidth={fullWidth}
/>
);
}
EmptyPosts.propTypes = {
subTitleMessage: propTypes.string.isRequired,
intl: intlShape.isRequired,
};
export default injectIntl(EmptyPosts);