From ba659b6247469b9cb09285bec5435d39d57ba360 Mon Sep 17 00:00:00 2001 From: Manuel <30572287+manuel-rw@users.noreply.github.com> Date: Fri, 9 Jun 2023 20:10:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20dash.=20api=20(#1024)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/api/modules/dashdot/info.ts | 1 + src/widgets/dashDot/DashDotCompactNetwork.tsx | 5 +++-- src/widgets/dashDot/DashDotCompactStorage.tsx | 20 +++++++++---------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/pages/api/modules/dashdot/info.ts b/src/pages/api/modules/dashdot/info.ts index 1f7b178a0..83f8cc341 100644 --- a/src/pages/api/modules/dashdot/info.ts +++ b/src/pages/api/modules/dashdot/info.ts @@ -44,6 +44,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) { ? dashDotUrl.substring(0, dashDotUrl.length - 1) : dashDotUrl; const response = await axios.get(`${url}/info`); + // Return the response return res.status(200).json(response.data); } diff --git a/src/widgets/dashDot/DashDotCompactNetwork.tsx b/src/widgets/dashDot/DashDotCompactNetwork.tsx index c283a6d14..815b136b7 100644 --- a/src/widgets/dashDot/DashDotCompactNetwork.tsx +++ b/src/widgets/dashDot/DashDotCompactNetwork.tsx @@ -9,8 +9,9 @@ interface DashDotCompactNetworkProps { export interface DashDotInfo { storage: { - layout: { size: number }[]; - }; + size: number; + disks: { device: string; brand: string; type: string }[]; + }[]; network: { speedUp: number; speedDown: number; diff --git a/src/widgets/dashDot/DashDotCompactStorage.tsx b/src/widgets/dashDot/DashDotCompactStorage.tsx index 319ffe10c..5b3c7cdfe 100644 --- a/src/widgets/dashDot/DashDotCompactStorage.tsx +++ b/src/widgets/dashDot/DashDotCompactStorage.tsx @@ -17,11 +17,10 @@ export const DashDotCompactStorage = ({ info, widgetId }: DashDotCompactStorageP const { data: storageLoad } = useDashDotStorage(widgetId); const totalUsed = calculateTotalLayoutSize({ - layout: storageLoad?.layout ?? [], - key: 'load', + layout: storageLoad ?? [], }); const totalSize = calculateTotalLayoutSize({ - layout: info?.storage?.layout ?? [], + layout: info?.storage ?? [], key: 'size', }); @@ -44,11 +43,16 @@ const calculateTotalLayoutSize = ({ layout, key, }: CalculateTotalLayoutSizeProps) => - layout.reduce((total, current) => total + (current[key] as number), 0); + layout.reduce((total, current) => { + if (key) { + return total + (current[key] as number); + } + return total + (current as number); + }, 0); interface CalculateTotalLayoutSizeProps { layout: TLayoutItem[]; - key: keyof TLayoutItem; + key?: keyof TLayoutItem; } const useDashDotStorage = (widgetId: string) => { @@ -71,9 +75,5 @@ async function fetchDashDotStorageLoad(configName: string | undefined, widgetId: if (!configName) throw new Error('configName is undefined'); return (await ( await axios.get('/api/modules/dashdot/storage', { params: { configName, widgetId } }) - ).data) as DashDotStorageLoad; -} - -interface DashDotStorageLoad { - layout: { load: number }[]; + ).data) as number[]; }