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

META-INF.resources.js.pages.home.UserActivity.es.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 ClayEmptyState from '@clayui/empty-state';
import classNames from 'classnames';
import {useManualQuery} from 'graphql-hooks';
import React, {useContext, useEffect, useState} from 'react';
import {withRouter} from 'react-router-dom';

import {AppContext} from '../../AppContext.es';
import ActivityQuestionRow from '../../components/ActivityQuestionRow.es';
import PaginatedList from '../../components/PaginatedList.es';
import useQueryParams from '../../hooks/useQueryParams.es';
import {getUserActivityQuery} from '../../utils/client.es';
import {historyPushWithSlug} from '../../utils/utils.es';
import {Question} from '../questions/Question.es';

export default withRouter(
	({
		history,
		location,
		match: {
			params: {creatorId},
			url,
		},
	}) => {
		const [currentQuestion, setCurrentQuestion] = useState(null);
		const [loading, setLoading] = useState(true);
		const [page, setPage] = useState(null);
		const [pageSize, setPageSize] = useState(null);
		const [totalCount, setTotalCount] = useState(0);
		const context = useContext(AppContext);
		const queryParams = useQueryParams(location);
		const siteKey = context.siteKey;

		useEffect(() => {
			const pageNumber = queryParams.get('page') || 1;
			setPage(isNaN(pageNumber) ? 1 : parseInt(pageNumber, 10));
		}, [queryParams]);

		useEffect(() => {
			setPageSize(queryParams.get('pagesize') || 20);
		}, [queryParams]);

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

		const [fetchUserActivity, {data}] = useManualQuery(
			getUserActivityQuery,
			{
				useCache: false,
				variables: {
					filter: `creatorId eq ${creatorId}`,
					page,
					pageSize,
					siteKey,
				},
			}
		);

		useEffect(() => {
			if (!page || !pageSize) {
				return;
			}

			setLoading(true);

			fetchUserActivity().then(({data}) => {
				setTotalCount(data?.messageBoardMessages.totalCount || 0);
				setLoading(false);
			});
		}, [fetchUserActivity, page, pageSize]);

		const historyPushParser = historyPushWithSlug(history.push);

		function buildUrl(page, pageSize) {
			return `/questions/activity/${creatorId}?page=${page}&pagesize=${pageSize}`;
		}

		function changePage(page, pageSize) {
			historyPushParser(buildUrl(page, pageSize));
		}

		const addSectionToQuestion = (question) => {
			return {
				...question,
				messageBoardSection:
					question?.messageBoardThread?.messageBoardSection,
			};
		};

		useEffect(() => {
			if (data) {
				setCurrentQuestion(data?.messageBoardMessages?.items[0]);
			}
		}, [data]);

		const sectionTitleQuestion =
			data?.messageBoardMessages?.items[0]?.messageBoardThread
				.messageBoardSection.title;

		const hasActivities = totalCount > 0;

		return (
			

{Liferay.Language.get('latest-activity')}

changePage(page, pageSize)} changePage={(page) => changePage(page, pageSize)} data={data && data.messageBoardMessages} emptyState={ } hidden loading={loading} totalCount={totalCount} > {(question) => ( { event.preventDefault(); setCurrentQuestion(question); }, }} question={addSectionToQuestion(question)} rowSelected={currentQuestion?.friendlyUrlPath} /> )}
{hasActivities && (
)}
); } );




© 2015 - 2024 Weber Informatics LLC | Privacy Policy