import { Stack, Text } from '@mantine/core'; import { AppItem } from 'components'; import { useCommonHooks, useQueryAPI } from 'hooks'; import { useEffect, useState } from 'react'; import { textClasses } from 'styles'; import type { Application } from 'types'; function Applications({ contentType }: { contentType: string[] }) { const { data: applicationData, isFetching: isApplicationDataFetching } = useQueryAPI({ endpoint: 'api/enabledApplications', }); const { appSort, appDensity, appScale, theme } = useCommonHooks(); const [applications, setApplications] = useState([]); useEffect(() => { if (applicationData && !isApplicationDataFetching) { setApplications( applicationData.sort((a: Application, b: Application) => { switch (appSort) { case 'A>Z': return a.name > b.name ? 1 : -1; case 'Z>A': return a.name < b.name ? 1 : -1; case 'Newest': if (a.id && b.id) { return a.id < b.id ? 1 : -1; } return -1; case 'Oldest': if (a.id && b.id) { return a.id > b.id ? 1 : -1; } return -1; case 'Custom': return a.index > b.index ? 1 : -1; } }), ); } }, [applicationData, isApplicationDataFetching, appSort]); return ( <> {applications.length > 0 && contentType.length > 0 && ( Applications {applications ?.filter( (application: Application) => contentType.includes(application.filterName) || contentType.includes('All'), ) .map((application: Application) => { return ( ); })} )} ); } export default Applications;