Skip to content

Commit

Permalink
feat: Inline loading indicator for address lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
ianjon3s committed May 10, 2024
1 parent 420c3c9 commit 0c1f098
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { gql } from "@apollo/client";
import Box from "@mui/material/Box";
import Link from "@mui/material/Link";
import { styled } from "@mui/material/styles";
import Typography from "@mui/material/Typography";
import Card from "@planx/components/shared/Preview/Card";
import QuestionHeader from "@planx/components/shared/Preview/QuestionHeader";
Expand Down Expand Up @@ -33,6 +34,18 @@ export const FETCH_BLPU_CODES = gql`

type Props = PublicProps<FindProperty>;

const AddressLoadingWrap = styled(Box)(({ theme }) => ({
marginBottom: theme.spacing(-2.5),
minHeight: theme.spacing(3),
pointerEvents: "none",
[theme.breakpoints.up("md")]: {
position: "absolute",
bottom: theme.spacing(1),
margin: 0,
paddingRight: theme.spacing(14),
},
}));

export default Component;

function Component(props: Props) {
Expand Down Expand Up @@ -185,12 +198,15 @@ function Component(props: Props) {
</Link>
</Box>
)}
{Boolean(address) && isValidating && (
<DelayedLoadingIndicator
msDelayBeforeVisible={50}
text="Fetching data..."
/>
)}
<AddressLoadingWrap>
{Boolean(address) && isValidating && (
<DelayedLoadingIndicator
msDelayBeforeVisible={50}
text="Fetching address data..."
inline
/>
)}
</AddressLoadingWrap>
</>
);
}
Expand Down
17 changes: 14 additions & 3 deletions editor.planx.uk/src/components/DelayedLoadingIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@ import { styled } from "@mui/material/styles";
import Typography from "@mui/material/Typography";
import React, { useEffect, useState } from "react";

const Root = styled(Box)(() => ({
export interface Props {
inline?: boolean;
}

const Root = styled(Box, {
shouldForwardProp: (prop) => prop !== "inline",
})<Props>(({ inline }) => ({
padding: 60,
display: "flex",
alignItems: "center",
justifyContent: "center",
...(inline && {
padding: 0,
}),
}));

const DelayedLoadingIndicator: React.FC<{
msDelayBeforeVisible?: number;
text?: string;
}> = ({ msDelayBeforeVisible = 0, text }) => {
inline?: boolean;
}> = ({ msDelayBeforeVisible = 0, text, inline }) => {
const [visible, setVisible] = useState(false);

useEffect(() => {
Expand All @@ -30,8 +40,9 @@ const DelayedLoadingIndicator: React.FC<{
aria-busy="true"
aria-live="assertive"
data-testid="delayed-loading-indicator"
inline={inline}
>
<CircularProgress aria-label="Loading" />
<CircularProgress size={inline ? 30 : 40} aria-label="Loading" />
<Typography variant="body2" sx={{ ml: "1rem" }}>
{text ?? "Loading..."}
</Typography>
Expand Down

0 comments on commit 0c1f098

Please sign in to comment.