Skip to content

Commit

Permalink
Corrected the skeleton loading logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishith25 committed Nov 23, 2024
1 parent 59c58da commit 9401a8c
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/CAREUI/display/Count.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import CareIcon, { IconName } from "@/CAREUI/icons/CareIcon";
import { classNames } from "@/Utils/utils";

interface Props {
count: number | null;
count: number;
text: string;
loading: boolean;
icon: IconName;
Expand All @@ -21,7 +21,7 @@ export default function CountBlock(props: Props) {
<dt className="mb-1 truncate text-sm font-semibold text-secondary-700">
{props.text}
</dt>
{props.loading || props.count == null ? (
{props.loading ? (
<dd className="h-10 w-full max-w-[100px] animate-pulse rounded-lg bg-secondary-300" />
) : (
<dd id="count" className="text-5xl font-black leading-9">
Expand Down
8 changes: 4 additions & 4 deletions src/components/Assets/AssetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const AssetsList = () => {
const [assets, setAssets] = useState([{} as AssetData]);
const [isLoading, setIsLoading] = useState(false);
const [isScannerActive, setIsScannerActive] = useState(false);
const [totalCount, setTotalCount] = useState<number | null>(null);
const [totalCount, setTotalCount] = useState(0);
const [facility, setFacility] = useState<FacilityModel>();
const [status, setStatus] = useState<string>();
const [asset_class, setAssetClass] = useState<string>();
Expand Down Expand Up @@ -75,7 +75,7 @@ const AssetsList = () => {
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setAssets(data.results);
setTotalCount(data?.count);
setTotalCount(data.count);
}
},
});
Expand Down Expand Up @@ -370,8 +370,8 @@ const AssetsList = () => {
<div className="mt-5 gap-3 space-y-2 lg:flex">
<CountBlock
text="Total Assets"
count={totalCount ? totalCount : null}
loading={loading}
count={totalCount}
loading={loading || !totalCount}
icon="l-monitor-heart-rate"
className="flex-1"
/>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Facility/DischargedPatientsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const DischargedPatientsList = ({
const [emergency_phone_number, setEmergencyPhoneNumber] = useState("");
const [emergencyPhoneNumberError, setEmergencyPhoneNumberError] =
useState("");
const [count, setCount] = useState<number | null>(null);
const [count, setCount] = useState(0);

const setPhoneNum = (phone_number: string) => {
setPhoneNumber(phone_number);
Expand Down Expand Up @@ -286,8 +286,8 @@ const DischargedPatientsList = ({
<div className="flex-1">
<CountBlock
text="Discharged Patients"
count={count ? count : null}
loading={facilityQuery.loading || count == null}
count={count}
loading={facilityQuery.loading || !count}
icon="l-user-injured"
className="pb-12"
/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Facility/FacilityList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ export const FacilityList = () => {
<div className="mt-4 gap-2 lg:flex">
<CountBlock
text="Total Facilities"
count={permittedData ? permittedData.count : null}
loading={isLoading}
count={permittedData ? permittedData.count : 0}
loading={isLoading || !permittedData}
icon="l-hospital"
className="flex-1"
/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Facility/FacilityUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ export default function FacilityUsers(props: any) {
{facilityUserData && (
<CountBlock
text={t("total_users")}
count={facilityData ? facilityUserData?.count : null}
loading={isLoading}
count={facilityUserData.count}
loading={isLoading || !facilityUserData}
icon="l-user-injured"
className="flex-1"
/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Patient/ManagePatients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,8 @@ export const PatientManager = () => {
<div className="flex-1" id="total-patientcount">
<CountBlock
text="Total Patients"
count={data ? data.count : null}
loading={isLoading}
count={data?.count || 0}
loading={isLoading || !data}
icon="l-user-injured"
className="pb-12"
/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Patient/SampleViewAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ export default function SampleViewAdmin() {
<div className="w-full">
<CountBlock
text="Total Samples Taken"
count={sampeleData ? sampeleData.count : null}
loading={isLoading}
count={sampeleData?.count || 0}
loading={isLoading || !sampeleData}
icon="l-thermometer"
className="flex-1"
/>
Expand Down
6 changes: 4 additions & 2 deletions src/components/Users/ManageUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,10 @@ export default function ManageUsers() {
<div className="mt-5 grid grid-cols-1 sm:grid-cols-3 md:gap-5">
<CountBlock
text="Total Users"
count={userListData ? userListData.count : null}
loading={userListLoading || districtDataLoading}
count={userListData?.count || 0}
loading={
userListLoading || districtDataLoading || !userListData?.results
}
icon="l-user-injured"
className="flex-1"
/>
Expand Down

0 comments on commit 9401a8c

Please sign in to comment.