Files
frontend-app-discussions/src/discussions/empty-posts/EmptyPosts.jsx
ayesha waris e1c78dda6e fix: fixed limited content visibility due to oversized sidebar (#692)
* fix: fixed limited content visibility due to oversized sidebar

* refactor: changed names of constants

---------

Co-authored-by: Awais Ansari <79941147+awais-ansari@users.noreply.github.com>
2024-04-08 23:43:24 +05:00

64 lines
1.7 KiB
JavaScript

import React, { useCallback } from 'react';
import propTypes from 'prop-types';
import { useDispatch, useSelector } from 'react-redux';
import { useIntl } from '@edx/frontend-platform/i18n';
import { useIsOnTablet } from '../data/hooks';
import { selectAreThreadsFiltered, selectPostThreadCount } from '../data/selectors';
import messages from '../messages';
import { showPostEditor } from '../posts/data';
import postMessages from '../posts/post-actions-bar/messages';
import EmptyPage from './EmptyPage';
const EmptyPosts = ({ subTitleMessage }) => {
const intl = useIntl();
const dispatch = useDispatch();
const isOnTabletorDesktop = useIsOnTablet();
const isFiltered = useSelector(selectAreThreadsFiltered);
const totalThreads = useSelector(selectPostThreadCount);
const addPost = useCallback(() => (
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 (!(isOnTabletorDesktop || 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.shape({
id: propTypes.string,
defaultMessage: propTypes.string,
description: propTypes.string,
}).isRequired,
};
export default React.memo(EmptyPosts);