style(dashboard-v2): improve code readability
This commit is contained in:
parent
623a4b816b
commit
a5327d00f3
|
@ -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,
|
||||||
|
|
Reference in New Issue