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

fix(lottie-react): create component to render lottie on client only #1518

Merged
merged 1 commit into from
Dec 13, 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
12 changes: 12 additions & 0 deletions app/components/zxing-scanner/success-animation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Lottie from "lottie-react";
import successfullScanAnimation from "../../lottie/success-scan.json";

export default function SuccessAnimation() {
return (
<Lottie
animationData={successfullScanAnimation}
loop={false}
style={{ width: 200, height: 200 }}
/>
);
}
14 changes: 5 additions & 9 deletions app/components/zxing-scanner/zxing-scanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import {
useNavigation,
useRouteLoaderData,
} from "@remix-run/react";
import Lottie from "lottie-react";
import { useZxing } from "react-zxing";

import { ClientOnly } from "remix-utils/client-only";
import type { LayoutLoaderResponse } from "~/routes/_layout+/_layout";
import { ShelfError } from "~/utils/error";
import { isFormProcessing } from "~/utils/form";
import { isQrId } from "~/utils/id";
import { tw } from "~/utils/tw";
import SuccessAnimation from "./success-animation";
import {
Select,
SelectContent,
Expand All @@ -22,7 +23,6 @@ import {
} from "../forms/select";
import Icon from "../icons/icon";
import { Spinner } from "../shared/spinner";
import successfullScanAnimation from "./../../lottie/success-scan.json";

type ZXingScannerProps = {
onQrDetectionSuccess?: (qrId: string, error?: string) => void | Promise<void>;
Expand Down Expand Up @@ -205,13 +205,9 @@ export const ZXingScanner = ({
{paused && (
<div className="flex h-full flex-col items-center justify-center p-4 text-center">
<h5>Code detected</h5>
<div>
<Lottie
animationData={successfullScanAnimation}
loop={false}
style={{ width: 200, height: 200 }}
/>
</div>
<ClientOnly fallback={null}>
{() => <SuccessAnimation />}
</ClientOnly>
<p>Scanner paused</p>
</div>
)}
Expand Down
Loading