Merge pull request #1229 from Tagaishi/media-request-ui-rework
💄 Media requests stats widget stretch elements to fit tile
This commit is contained in:
@@ -3,7 +3,10 @@
|
|||||||
"name": "Media request stats",
|
"name": "Media request stats",
|
||||||
"description": "Statistics about your media requests",
|
"description": "Statistics about your media requests",
|
||||||
"settings": {
|
"settings": {
|
||||||
"title": "Media requests stats"
|
"title": "Media requests stats",
|
||||||
|
"direction": {
|
||||||
|
"label": "Direction of the layout."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"stats": {
|
"stats": {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Card, Center, Flex, Stack, Text } from '@mantine/core';
|
import { Card, Flex, Stack, Text } from '@mantine/core';
|
||||||
import { IconChartBar } from '@tabler/icons-react';
|
import { IconChartBar } from '@tabler/icons-react';
|
||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
|
|
||||||
@@ -11,14 +11,23 @@ import { MediaRequestStatus } from './media-request-types';
|
|||||||
const definition = defineWidget({
|
const definition = defineWidget({
|
||||||
id: 'media-requests-stats',
|
id: 'media-requests-stats',
|
||||||
icon: IconChartBar,
|
icon: IconChartBar,
|
||||||
options: {},
|
options: {
|
||||||
component: MediaRequestStatsTile,
|
direction: {
|
||||||
|
type: 'select',
|
||||||
|
defaultValue: 'row' as 'row' | 'column',
|
||||||
|
data: [
|
||||||
|
{ label: 'Horizontal', value: 'row' },
|
||||||
|
{ label: 'Vertical', value: 'column' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
gridstack: {
|
gridstack: {
|
||||||
minWidth: 1,
|
minWidth: 1,
|
||||||
minHeight: 2,
|
minHeight: 1,
|
||||||
maxWidth: 12,
|
maxWidth: 12,
|
||||||
maxHeight: 12,
|
maxHeight: 12,
|
||||||
},
|
},
|
||||||
|
component: MediaRequestStatsTile,
|
||||||
});
|
});
|
||||||
|
|
||||||
export type MediaRequestStatsWidget = IWidget<(typeof definition)['id'], typeof definition>;
|
export type MediaRequestStatsWidget = IWidget<(typeof definition)['id'], typeof definition>;
|
||||||
@@ -36,41 +45,46 @@ function MediaRequestStatsTile({ widget }: MediaRequestStatsWidgetProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex gap="md" wrap="wrap">
|
<Flex
|
||||||
<Card w={100} h={100} withBorder>
|
w="100%"
|
||||||
<Center h="100%">
|
h="100%"
|
||||||
<Stack spacing={0} align="center">
|
gap="md"
|
||||||
<Text>
|
direction={ widget.properties.direction?? 'row' }
|
||||||
{data.filter((x) => x.status === MediaRequestStatus.PendingApproval).length}
|
>
|
||||||
</Text>
|
<StatCard
|
||||||
<Text color="dimmed" align="center" size="xs">
|
number={data.filter((x) => x.status === MediaRequestStatus.PendingApproval).length}
|
||||||
{t('stats.pending')}
|
label={t('stats.pending')}
|
||||||
</Text>
|
/>
|
||||||
</Stack>
|
<StatCard
|
||||||
</Center>
|
number={data.filter((x) => x.type === 'tv').length}
|
||||||
</Card>
|
label={t('stats.tvRequests')}
|
||||||
<Card w={100} h={100} withBorder>
|
/>
|
||||||
<Center h="100%">
|
<StatCard
|
||||||
<Stack spacing={0} align="center">
|
number={data.filter((x) => x.type === 'movie').length}
|
||||||
<Text align="center">{data.filter((x) => x.type === 'tv').length}</Text>
|
label={t('stats.movieRequests')}
|
||||||
<Text color="dimmed" align="center" size="xs">
|
/>
|
||||||
{t('stats.tvRequests')}
|
|
||||||
</Text>
|
|
||||||
</Stack>
|
|
||||||
</Center>
|
|
||||||
</Card>
|
|
||||||
<Card w={100} h={100} withBorder>
|
|
||||||
<Center h="100%">
|
|
||||||
<Stack spacing={0} align="center">
|
|
||||||
<Text align="center">{data.filter((x) => x.type === 'movie').length}</Text>
|
|
||||||
<Text color="dimmed" align="center" size="xs">
|
|
||||||
{t('stats.movieRequests')}
|
|
||||||
</Text>
|
|
||||||
</Stack>
|
|
||||||
</Center>
|
|
||||||
</Card>
|
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface StatCardProps {
|
||||||
|
number: number;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StatCard = ({ number, label }: StatCardProps) => {
|
||||||
|
return (
|
||||||
|
<Card w="100%" h="100%" withBorder style={{flex:"1 1 auto"}}>
|
||||||
|
<Stack w="100%" h="100%" align="center" justify="center" spacing={0}>
|
||||||
|
<Text align="center">
|
||||||
|
{number}
|
||||||
|
</Text>
|
||||||
|
<Text color="dimmed" align="center" size="xs">
|
||||||
|
{label}
|
||||||
|
</Text>
|
||||||
|
</Stack>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default definition;
|
export default definition;
|
||||||
Reference in New Issue
Block a user