From b59170078db3064db1e42e08b79e8e3ac35bef71 Mon Sep 17 00:00:00 2001 From: Prathamesh Gursal Date: Tue, 8 Oct 2024 01:19:26 +0530 Subject: [PATCH] make single loader more responsive --- frontend/src/settings/APIKeys.tsx | 2 +- frontend/src/settings/Analytics.tsx | 29 +++++++------- frontend/src/settings/Documents.tsx | 2 +- frontend/src/settings/Logs.tsx | 4 +- frontend/src/utils/loader.tsx | 62 ++++++++++++++++++++++++----- package-lock.json | 2 +- 6 files changed, 71 insertions(+), 30 deletions(-) diff --git a/frontend/src/settings/APIKeys.tsx b/frontend/src/settings/APIKeys.tsx index e05f3a1f..eb9c14e8 100644 --- a/frontend/src/settings/APIKeys.tsx +++ b/frontend/src/settings/APIKeys.tsx @@ -107,7 +107,7 @@ export default function APIKeys() {
{loading ? ( - + ) : ( diff --git a/frontend/src/settings/Analytics.tsx b/frontend/src/settings/Analytics.tsx index b736f6ad..b6948d70 100644 --- a/frontend/src/settings/Analytics.tsx +++ b/frontend/src/settings/Analytics.tsx @@ -18,6 +18,7 @@ import { APIKeyData } from './types'; import type { ChartData } from 'chart.js'; import SkeletonLoader from '../utils/loader'; + ChartJS.register( CategoryScale, LinearScale, @@ -100,7 +101,7 @@ export default function Analytics() { }; const fetchTokenData = async (chatbot_id?: string, filter?: string) => { - setLoadingTokens(true); // Start loading + setLoadingTokens(true); try { const response = await userService.getTokenAnalytics({ api_key_id: chatbot_id, @@ -195,7 +196,7 @@ export default function Analytics() { {/* Messages Analytics */}
-
+

Messages @@ -246,7 +247,7 @@ export default function Analytics() {

{/* Token Usage Analytics */} -
+

Token Usage @@ -273,7 +274,7 @@ export default function Analytics() { className="flex flex-row items-center justify-end" >

{loadingTokens ? ( - + ) : ( {/* Feedback Analytics */} -
-
+
+

- User Feedback + Feedback

{loadingFeedback ? ( - + ) : ( item.positive, ), - backgroundColor: '#8BD154', + backgroundColor: '#7D54D1', }, { - label: 'Negative', + label: 'Negative Feedback', data: Object.values(feedbackData || {}).map( (item) => item.negative, ), - backgroundColor: '#D15454', + backgroundColor: '#FF6384', }, ], }} legendID="legend-container-3" - maxTicksLimitInX={10} - isStacked={true} + maxTicksLimitInX={8} + isStacked={false} /> )}
diff --git a/frontend/src/settings/Documents.tsx b/frontend/src/settings/Documents.tsx index a5e5efb7..f1cfc0b9 100644 --- a/frontend/src/settings/Documents.tsx +++ b/frontend/src/settings/Documents.tsx @@ -64,7 +64,7 @@ const Documents: React.FC = ({
{loading ? ( - + ) : (
diff --git a/frontend/src/settings/Logs.tsx b/frontend/src/settings/Logs.tsx index 32d89564..28bca57f 100644 --- a/frontend/src/settings/Logs.tsx +++ b/frontend/src/settings/Logs.tsx @@ -69,7 +69,7 @@ export default function Logs() { Filter by chatbot

{loadingChatbots ? ( - + ) : ( {loadingLogs ? ( - + ) : ( )} diff --git a/frontend/src/utils/loader.tsx b/frontend/src/utils/loader.tsx index bbf8ba25..de9cf766 100644 --- a/frontend/src/utils/loader.tsx +++ b/frontend/src/utils/loader.tsx @@ -1,21 +1,64 @@ -import React from 'react'; +import React, { useState, useEffect } from 'react'; interface SkeletonLoaderProps { - count?: number; // Optional prop to define the number of skeleton loaders + count?: number; } const SkeletonLoader: React.FC = ({ count = 1 }) => { + const [skeletonCount, setSkeletonCount] = useState(count); + + useEffect(() => { + const handleResize = () => { + const windowWidth = window.innerWidth; + + if (windowWidth > 1024) { + setSkeletonCount(1); + } else if (windowWidth > 768) { + setSkeletonCount(count); + } else { + setSkeletonCount(Math.min(count, 2)); + } + }; + + handleResize(); + window.addEventListener('resize', handleResize); + + return () => { + window.removeEventListener('resize', handleResize); + }; + }, [count]); + return ( -
- {[...Array(count)].map((_, idx) => ( +
+ {[...Array(skeletonCount)].map((_, idx) => (
-
-
-
+
+
{' '} +
{' '} +
{' '} +
{' '} +
{' '} +
+
{' '} +
+
{' '} +
{' '} +
{' '} +
+
{' '} +
+
{' '} +
{' '} +
{' '} +
{' '} +
+
{' '} +
{' '} +
{' '}
))} @@ -24,6 +67,3 @@ const SkeletonLoader: React.FC = ({ count = 1 }) => { }; export default SkeletonLoader; - -// calling function should be pass --- no. of sketeton cards -// eg . ----------->>> diff --git a/package-lock.json b/package-lock.json index 1d8f28b5..9582c111 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "DocsGPT", + "name": "DocsGpt", "lockfileVersion": 3, "requires": true, "packages": {