80 lines
2.1 KiB
TypeScript
80 lines
2.1 KiB
TypeScript
import { Stack, Text } from '@mantine/core';
|
|
import { useCommonHooks, useQueryAPI } from 'hooks';
|
|
import { useEffect, useState } from 'react';
|
|
import { textClasses } from 'styles';
|
|
import type { Application } from 'types';
|
|
import AppItem from './AppItem';
|
|
|
|
function Applications({ contentType }: { contentType: [string] }) {
|
|
const { data: apps, isFetching: isAppsFetching } = useQueryAPI({
|
|
endpoint: 'api/apps',
|
|
});
|
|
const { isMobile, appSort } = useCommonHooks();
|
|
const [applicationData, setApplicationData] = useState<Application[]>([]);
|
|
|
|
useEffect(() => {
|
|
if (apps && !isAppsFetching) {
|
|
setApplicationData(
|
|
apps
|
|
.filter((a: Application) => a.enabled === 1)
|
|
.sort((a: any, b: any) => {
|
|
switch (appSort) {
|
|
case 'A>Z':
|
|
return a.name > b.name ? 1 : -1;
|
|
case 'Z>A':
|
|
return a.name < b.name ? 1 : -1;
|
|
case 'Newest':
|
|
return a.id < b.id ? 1 : -1;
|
|
case 'Oldest':
|
|
return a.id > b.id ? 1 : -1;
|
|
case 'Custom':
|
|
return a.index > b.index ? 1 : -1;
|
|
}
|
|
}),
|
|
);
|
|
}
|
|
}, [apps, isAppsFetching, appSort]);
|
|
return (
|
|
<>
|
|
{applicationData.length > 0 && contentType.length > 0 && (
|
|
<Stack id='apps' style={{ gap: 0 }}>
|
|
<Text className={textClasses.sectionTitle} classNames={textClasses}>
|
|
Applications
|
|
</Text>
|
|
<Stack
|
|
style={{
|
|
gap: '.25rem',
|
|
backgroundSize: 'cover',
|
|
borderBottom: '0px solid',
|
|
display: 'grid',
|
|
gridColumnGap: '5px',
|
|
gridRowGap: '5px',
|
|
gridTemplateColumns: isMobile ? '1fr 1fr 1fr' : '1fr 1fr 1fr 1fr 1fr 1fr',
|
|
gridTemplateRows: '64px',
|
|
}}
|
|
>
|
|
{applicationData
|
|
?.filter(
|
|
(application: Application) =>
|
|
contentType.includes(application.filterName) ||
|
|
contentType.includes('All'),
|
|
)
|
|
.map((application: Application) => {
|
|
return (
|
|
<AppItem
|
|
key={application.name}
|
|
name={application.name}
|
|
url={application.url}
|
|
icon={application.icon}
|
|
/>
|
|
);
|
|
})}
|
|
</Stack>
|
|
</Stack>
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default Applications;
|