@@ -115,11 +145,11 @@ export default function ProtectionOverview() {
)}
{isOpen ? (
-
{filesInfo?.totalSize ? filesInfo?.totalSize : 0} / 0
+
{filesInfo?.totalSize ? convertBytes(filesInfo?.totalSize) : 0} / 0
{t('disk-space-used')}
diff --git a/src/app/ui/dashboard/stats-grid.tsx b/src/app/ui/dashboard/stats-grid.tsx
index 18bbd7c..9e2bbdb 100644
--- a/src/app/ui/dashboard/stats-grid.tsx
+++ b/src/app/ui/dashboard/stats-grid.tsx
@@ -1,8 +1,24 @@
+'use client'
+
import { useTranslations } from 'next-intl';
import { IconImageFile, IconVideoFile, IconAudioFile } from '@/app/ui/icons/icons';
+import { useQuery } from '@tanstack/react-query';
+import { getUserFilesInfo } from '@/app/actions/action';
+import {convertBytes} from '@/app/lib/convertBytes';
+
export default function StatsGrid() {
const t = useTranslations("Global");
+ const {
+ data: filesInfo,
+ isLoading,
+ isError,
+ error,
+ } = useQuery({
+ queryKey: ['userFilesInfo'],
+ queryFn: getUserFilesInfo,
+ });
+
return (
@@ -30,10 +46,10 @@ export default function StatsGrid() {
{t('images')}
- 0
+ {filesInfo.images_quantity ? filesInfo.images_quantity : 0}
- 0
+ {filesInfo.images_size ? convertBytes(filesInfo.images_size) : 0}
0
@@ -47,10 +63,10 @@ export default function StatsGrid() {
{t('videos')}
- 0
+ {filesInfo.videos_quantity ? filesInfo.videos_quantity : 0}
- 0
+ {filesInfo.videos_size ? convertBytes(filesInfo.videos_size) : 0}
0
@@ -64,10 +80,10 @@ export default function StatsGrid() {
{t('audios')}
- 0
+ {filesInfo.audios_quantity ? filesInfo.audios_quantity : 0}
- 0
+ {filesInfo.audios_size ? convertBytes(filesInfo.audios_size) : 0}
0
diff --git a/src/app/ui/marking-page/protection-summary.tsx b/src/app/ui/marking-page/protection-summary.tsx
index f07d0c4..7c32df8 100644
--- a/src/app/ui/marking-page/protection-summary.tsx
+++ b/src/app/ui/marking-page/protection-summary.tsx
@@ -3,15 +3,43 @@
import { useTranslations } from 'next-intl';
import { useQuery } from '@tanstack/react-query';
import { getUserFilesData } from '@/app/actions/fileEntity';
+import { getUserFilesInfo } from '@/app/actions/action';
+import { convertBytes } from '@/app/lib/convertBytes';
type FilesInfo = {
- totalSize: string;
+ totalSize: number;
totalCount: number;
};
-export default function ProtectionSummary() {
+export default function ProtectionSummary({ fileType }: { fileType: string }) {
const t = useTranslations('Global');
+ console.log(fileType);
+
+ const getFileTypeFields = (fileType: string): { totalSize: string, totalCount: string } => {
+ switch (fileType) {
+ case 'image':
+ return {
+ totalSize: 'images_size',
+ totalCount: 'images_quantity'
+ };
+ case 'video':
+ return {
+ totalSize: 'videos_size',
+ totalCount: 'videos_quantity'
+ };
+ case 'audio':
+ return {
+ totalSize: 'audios_size',
+ totalCount: 'audios_quantity'
+ };
+ default:
+ return {
+ totalSize: 'all_files_size',
+ totalCount: 'all_files_quantity'
+ };
+ }
+ };
const {
data: filesInfo,
@@ -19,24 +47,26 @@ export default function ProtectionSummary() {
isError,
error,
} = useQuery<{
- formattedTotalSize: string,
- totalCount: number
+ all_files_size: number,
+ all_files_quantity: number
}, Error, FilesInfo>({
- queryKey: ['userFilesData'],
- queryFn: getUserFilesData,
+ queryKey: ['userFilesInfo'],
+ queryFn: getUserFilesInfo,
select: (data): FilesInfo => {
if (!data) {
return {
- totalSize: '0',
+ totalSize: 0,
totalCount: 0
}
}
+ const fields = getFileTypeFields(fileType);
+
return {
- totalSize: data.formattedTotalSize,
- totalCount: (data.totalCount)
+ totalSize: data[fields.totalSize as keyof typeof data],
+ totalCount: data[fields.totalCount as keyof typeof data]
}
- },
+ }
});
@@ -56,7 +86,7 @@ export default function ProtectionSummary() {
{t('violations')}
-
{filesInfo?.totalSize ? filesInfo?.totalSize : 0} / 0
+
{filesInfo?.totalSize ? convertBytes(filesInfo?.totalSize) : 0} / 0
{t('disk-space-used')}
diff --git a/src/app/ui/my-content/my-content-info-block.tsx b/src/app/ui/my-content/my-content-info-block.tsx
index b8cb607..c3d5eb6 100644
--- a/src/app/ui/my-content/my-content-info-block.tsx
+++ b/src/app/ui/my-content/my-content-info-block.tsx
@@ -1,6 +1,72 @@
+'use client'
+
import { IconDocument, IconImageFile, IconVideoFile, IconAudioFile } from '@/app/ui/icons/icons';
+import { useQuery } from '@tanstack/react-query';
+import { getUserFilesInfo } from '@/app/actions/action';
+import { useTranslations } from 'next-intl';
+import { convertBytes } from '@/app/lib/convertBytes';
export default function MyContentInfoBlock() {
+ const t = useTranslations('Global');
+
+ const {
+ data: filesInfo,
+ isLoading,
+ isError,
+ error,
+ } = useQuery({
+ queryKey: ['userFilesInfo'],
+ queryFn: getUserFilesInfo,
+ });
+
+ const fileTypeSizePercents = () => {
+ if (!filesInfo?.all_files_size) {
+ return {
+ images: 0,
+ videos: 0,
+ audios: 0,
+ documents: 0,
+ };
+ }
+
+ const sizes = {
+ images: filesInfo.images_size || 0,
+ videos: filesInfo.videos_size || 0,
+ audios: filesInfo.audios_size || 0,
+ documents: filesInfo.documents_size || 0,
+ };
+
+ const total = filesInfo.all_files_size;
+
+ const rawPercents = {
+ images: (sizes.images / total) * 100,
+ videos: (sizes.videos / total) * 100,
+ audios: (sizes.audios / total) * 100,
+ documents: (sizes.documents / total) * 100,
+ };
+
+ const roundedPercents = {
+ images: Math.floor(rawPercents.images),
+ videos: Math.floor(rawPercents.videos),
+ audios: Math.floor(rawPercents.audios),
+ documents: Math.floor(rawPercents.documents),
+ };
+
+ const remainder = 100 - Object.values(roundedPercents).reduce((a, b) => a + b, 0);
+
+ const fractions = Object.entries(rawPercents).map(([key, value]) => ({
+ key,
+ fraction: value - Math.floor(value)
+ })).sort((a, b) => b.fraction - a.fraction);
+
+ const result = { ...roundedPercents };
+ for (let i = 0; i < remainder; i++) {
+ result[fractions[i].key as keyof typeof result]++;
+ }
+
+ return result;
+ };
+
return (
@@ -11,13 +77,17 @@ export default function MyContentInfoBlock() {
-
Image
- 0%
+ {t('images')}
+ {fileTypeSizePercents().images}%
- 0 files
- 0 GB
+
+ {filesInfo.images_quantity ? filesInfo.images_quantity : 0} {t('files')}
+
+
+ {filesInfo.images_size ? convertBytes(filesInfo.images_size) : 0}
+
@@ -27,13 +97,17 @@ export default function MyContentInfoBlock() {