All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
META-INF.resources.js.pages.home.Home.js Maven / Gradle / Ivy
/**
* 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,
]
)}
View Topic
))) || (
{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
)}
);
});