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

META-INF.resources.js.pages.home.UserSubscriptions.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 {ClayButtonWithIcon} from '@clayui/button';
import {ClayDropDownWithItems} from '@clayui/drop-down';
import ClayEmptyState from '@clayui/empty-state';
import {useMutation, useQuery} from 'graphql-hooks';
import React, {useCallback, useContext, useState} from 'react';
import {withRouter} from 'react-router-dom';

import {AppContext} from '../../AppContext.es';
import Alert from '../../components/Alert.es';
import DeleteQuestion from '../../components/DeleteQuestion.es';
import Link from '../../components/Link.es';
import PaginatedList from '../../components/PaginatedList.es';
import QuestionRow from '../../components/QuestionRow.es';
import TagsLayout from '../../components/TagsLayout.es';
import useTags from '../../hooks/useTags.es';
import {
	getSubscriptionsQuery,
	unsubscribeMyUserAccountQuery,
} from '../../utils/client.es';
import {historyPushWithSlug} from '../../utils/utils.es';

export default withRouter(
	({
		history,
		location,
		match: {
			params: {creatorId},
		},
	}) => {
		const context = useContext(AppContext);

		const [info, setInfo] = useState({});
		const [questionToDelete, setQuestionToDelete] = useState({});

		const {
			changePage,
			error,
			loading,
			orderBy,
			page,
			pageSize,
			search,
			tags,
		} = useTags({
			baseURL: `/questions/subscriptions/${creatorId}`,
			filter: 'subscribed eq true',
			history,
			location,
		});

		const {data: threads, refetch: refetchThread} = useQuery(
			getSubscriptionsQuery,
			{
				variables: {
					contentType: 'MessageBoardThread',
				},
			}
		);

		if (threads && threads.myUserAccountSubscriptions.items) {
			threads.myUserAccountSubscriptions.items =
				threads.myUserAccountSubscriptions.items.filter(
					(thread) => thread.graphQLNode.showAsQuestion
				);
		}

		const {data: topics, refetch: refetchTopics} = useQuery(
			getSubscriptionsQuery,
			{
				variables: {
					contentType: 'MessageBoardSection',
				},
			}
		);

		const [unsubscribe] = useMutation(unsubscribeMyUserAccountQuery);

		const [showDeleteModalPanel, setShowDeleteModalPanel] = useState(false);

		const historyPushParser = historyPushWithSlug(history.push);

		const linkTagPage = location.pathname.split('/')[2];

		const actions = useCallback(
			(data) => {
				const question = data.graphQLNode;

				const actions = [
					{
						label: Liferay.Language.get('unsubscribe'),
						onClick: () => {
							unsubscribe({
								variables: {
									subscriptionId: data.id,
								},
							}).then(() => {
								refetchThread();
								refetchTopics();
								setInfo({
									title: 'You have unsubscribed from this asset successfully.',
								});
							});
						},
					},
				];

				if (question.actions && question.actions.delete) {
					actions.push({
						label: Liferay.Language.get('delete'),
						onClick: () => {
							setQuestionToDelete(question);
							setShowDeleteModalPanel(true);
						},
					});
				}

				if (question.actions && question.actions.replace) {
					actions.push({
						label: Liferay.Language.get('edit'),
						onClick: () => {
							historyPushParser(
								`/questions/${
									context.useTopicNamesInURL
										? question.messageBoardSection.title
										: question.messageBoardSection.id
								}/${data.graphQLNode.friendlyUrlPath}/edit`
							);
						},
					});
				}

				if (question.headline) {
					actions.push({
						label: Liferay.Language.get('reply'),
						onClick: () => {
							historyPushParser(
								`/questions/${
									context.useTopicNamesInURL
										? question.messageBoardSection.title
										: question.messageBoardSection.id
								}/${question.friendlyUrlPath}`
							);
						},
					});
				}

				return actions;
			},
			[
				context.useTopicNamesInURL,
				historyPushParser,
				refetchThread,
				refetchTopics,
				unsubscribe,
			]
		);

		return (
			

{Liferay.Language.get('tags')}

changePage(search, page, pageSize) } changePage={(page) => changePage(search, page, pageSize) } data={tags} emptyState={ } loading={loading} > {(tag) => (
)}

{Liferay.Language.get('topics')}

{topics && topics.myUserAccountSubscriptions.items && !topics.myUserAccountSubscriptions.items.length && ( )}
{topics && topics.myUserAccountSubscriptions.items && topics.myUserAccountSubscriptions.items.map( (data) => (
{ data .graphQLNode .title }
} />
) )}

{Liferay.Language.get('questions')}

{threads && threads.myUserAccountSubscriptions.items && !threads.myUserAccountSubscriptions.items .length && ( )} {threads && threads.myUserAccountSubscriptions.items && threads.myUserAccountSubscriptions.items.map( (data) => (
) )}
); } );




© 2015 - 2024 Weber Informatics LLC | Privacy Policy