Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/handle connection state failed #138

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/components/production-line/production-line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { useIsLoading } from "./use-is-loading.ts";
import { useCheckBadLineData } from "./use-check-bad-line-data.ts";
import { NavigateToRootButton } from "../navigate-to-root-button/navigate-to-root-button.tsx";
import { useAudioCue } from "./use-audio-cue.ts";
import { DisplayWarning } from "../display-box.tsx";

const TempDiv = styled.div`
padding: 0 0 2rem 0;
Expand Down Expand Up @@ -94,6 +95,13 @@ const StateText = styled.span<{ state: string }>`
}};
`;

const ConnectionErrorWrapper = styled(FlexContainer)`
width: 100vw;
justify-content: center;
align-items: center;
padding-top: 12rem;
`;

export const ProductionLine: FC = () => {
const { productionId: paramProductionId, lineId: paramLineId } = useParams();
const [
Expand Down Expand Up @@ -186,7 +194,7 @@ export const ProductionLine: FC = () => {
});
}, [dispatch, fetchProductionError]);

const loading = useIsLoading({ connectionState });
const { loading, connectionError } = useIsLoading({ connectionState });

useHeartbeat({ sessionId });

Expand Down Expand Up @@ -239,9 +247,18 @@ export const ProductionLine: FC = () => {
</FlexContainer>
)}

{joinProductionOptions && loading && (
<Spinner className="join-production" />
)}
{joinProductionOptions &&
loading &&
(!connectionError ? (
<Spinner className="join-production" />
) : (
<ConnectionErrorWrapper>
<DisplayWarning
text="Please return to previous page and try to join again."
title="Connection failed"
/>
</ConnectionErrorWrapper>
))}

{joinProductionOptions && !loading && (
<FlexContainer>
Expand Down
9 changes: 7 additions & 2 deletions src/components/production-line/use-is-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ type TProps = {

export const useIsLoading = ({ connectionState }: TProps) => {
const [loading, setLoading] = useState<boolean>(true);
const [connectionError, setConnectionError] = useState<boolean>(false);

useEffect(() => {
if (connectionState === "connected") {
setLoading(false);
} else if (connectionState === "failed") {
setConnectionError(true);
}
// TODO add handling for `connectionState === "failed"`
}, [connectionState]);

return loading;
return {
loading,
connectionError,
};
};
Loading