All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.js.pages.home.Home.js Maven / Gradle / Ivy

There is a newer version: 2.0.121
Show newest version
/**
 * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
 */

import ClayButton from '@clayui/button';
import ClayCard from '@clayui/card';
import ClayEmptyState from '@clayui/empty-state';
import ClayIcon from '@clayui/icon';
import ClayLoadingIndicator from '@clayui/loading-indicator';
import classNames from 'classnames';
import {useManualQuery} from 'graphql-hooks';
import React, {useContext, useEffect, useState} from 'react';
import {Helmet} from 'react-helmet';
import {Redirect, withRouter} from 'react-router-dom';

import {AppContext} from '../../AppContext.es';
import Alert from '../../components/Alert.es';
import Link from '../../components/Link.es';
import NewTopicModal from '../../components/NewTopicModal.es';
import {
	getSectionBySectionTitleQuery,
	getSectionsQuery,
} from '../../utils/client.es';
import lang from '../../utils/lang.es';
import {
	getBasePathWithHistoryRouter,
	historyPushWithSlug,
} from '../../utils/utils.es';

export default withRouter(({history, isHomePath}) => {
	const context = useContext(AppContext);
	const historyPushParser = historyPushWithSlug(history.push);
	const [topicModalVisibility, setTopicModalVisibility] = useState(false);

	const [error, setError] = useState({});
	const [loading, setLoading] = useState(true);
	const [sections, setSections] = useState({});

	useEffect(() => {
		document.title = 'Questions';
	}, []);

	const [getSections] = useManualQuery(getSectionsQuery, {
		variables: {siteKey: context.siteKey},
	});
	const [getSectionBySectionTitle] = useManualQuery(
		getSectionBySectionTitleQuery,
		{
			variables: {
				filter: `title eq '${context.rootTopicId}' or id eq '${context.rootTopicId}'`,
				siteKey: context.siteKey,
			},
		}
	);

	useEffect(() => {
		const fn =
			!context.rootTopicId || context.rootTopicId === '0'
				? getSections()
				: getSectionBySectionTitle().then((result) => ({
						...result,
						data: result.data.messageBoardSections.items[0],
					}));

		fn.then((result) => ({
			...result,
			data: result.data.messageBoardSections,
		}))
			.then(({data, loading}) => {
				setSections(data || []);
				setLoading(loading);
			})
			.catch((error) => {
				if (process.env.NODE_ENV === 'development') {
					console.error(error);
				}
				setLoading(false);
				setError({message: 'Loading Topics', title: 'Error'});
			});
	}, [
		context.rootTopicId,
		context.siteKey,
		getSectionBySectionTitle,
		getSections,
	]);

	function descriptionTruncate(description) {
		return description?.length > 150
			? description.substring(0, 150) + '...'
			: description;
	}

	return (
		
{!context.showCardsForTopicNavigation && ( )}
history.push('/questions/all')} > {Liferay.Language.get('all-questions')}
{!loading && ( <> {sections && sections.actions && !!sections.actions.create && sections.items && !!sections.items.length && (
setTopicModalVisibility(true) } > {Liferay.Language.get( 'new-topic' )}
)} {(sections.items && !!sections.items.length && sections.items.map((section) => (
{section.title} {descriptionTruncate( section.description )} {lang.sub( Liferay.Language.get( 'x-questions' ), [ section.numberOfMessageBoardThreads, ] )}
))) || ( {sections && sections.actions && !!sections.actions.create && ( setTopicModalVisibility(true) } > {Liferay.Language.get('new-topic')} )} )} )} setTopicModalVisibility(false)} onCreateNavigateTo={() => { historyPushParser(`/tmp`); history.goBack(); }} setError={setError} visible={topicModalVisibility} />
{loading && } {context.historyRouterBasePath && ( Questions )}
); });




© 2015 - 2024 Weber Informatics LLC | Privacy Policy