style(dashboard-v2): improve code readability

This commit is contained in:
Michał Leszczyk 2022-03-08 09:37:24 +01:00
parent 623a4b816b
commit a5327d00f3
No known key found for this signature in database
GPG Key ID: FA123CA8BAA2FBF4
1 changed files with 8 additions and 4 deletions

View File

@ -13,16 +13,20 @@ import { UsageGraph } from "./UsageGraph";
const useUsageData = () => { const useUsageData = () => {
const { user } = useUser(); const { user } = useUser();
const { activePlan, error } = useActivePlan(user); const { activePlan, error } = useActivePlan(user);
const [loading, setLoading] = useState(true);
const { data: stats, error: statsError } = useSWR("user/stats"); const { data: stats, error: statsError } = useSWR("user/stats");
const [loading, setLoading] = useState(true);
const [usage, setUsage] = useState({}); const [usage, setUsage] = useState({});
const hasError = error || statsError;
const hasData = activePlan && stats;
useEffect(() => { useEffect(() => {
if ((activePlan && stats) || error || statsError) { if (hasData || hasError) {
setLoading(false); setLoading(false);
} }
if (activePlan && stats && !error && !statsError) { if (hasData && !hasError) {
setUsage({ setUsage({
filesUsed: stats?.numUploads, filesUsed: stats?.numUploads,
filesLimit: activePlan?.limits?.maxNumberUploads, filesLimit: activePlan?.limits?.maxNumberUploads,
@ -30,7 +34,7 @@ const useUsageData = () => {
storageLimit: activePlan?.limits?.storageLimit, storageLimit: activePlan?.limits?.storageLimit,
}); });
} }
}, [activePlan, stats, error, statsError]); }, [hasData, hasError, stats, activePlan]);
return { return {
error: error || statsError, error: error || statsError,