Skip to content

Commit

Permalink
feat: loading placeholder for generated image
Browse files Browse the repository at this point in the history
  • Loading branch information
bripkens committed Dec 20, 2023
1 parent 5bcae08 commit b9ace45
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/otelbin/src/components/share/ShareContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import { IconButton } from "~/components/icon-button";
import { useToast } from "~/components/use-toast";
import { fetcher } from "~/lib/fetcher";
import useSWRImmutable from "swr/immutable";
import { useState } from "react";
import { cn } from "~/lib/utils";

export function ShareContent() {
const { toast } = useToast();
const [{ config }, getLink] = useUrlState([editorBinding]);
let fullURL = window.location.origin + getLink({});
const { isSignedIn } = useAuth();
const [loadedImgUrl, setLoadedImgUrl] = useState<string | undefined>(undefined);

const { data } = useSWRImmutable<{ shortLink: string; imgURL: string }>(
isSignedIn
Expand Down Expand Up @@ -93,10 +96,23 @@ export function ShareContent() {
<img
src={data.imgURL}
width={280}
height={147}
height={loadedImgUrl === data.imgURL ? 147 : 0}
alt="OpenTelemetry collector configuration on OTelBin"
className="grow-0"
onLoad={() => {
setLoadedImgUrl(data.imgURL);
}}
/>

{loadedImgUrl !== data.imgURL && (
<div
className="bg-default animate-pulse rounded"
style={{
width: 280,
height: 147,
}}
/>
)}
</div>
</>
)}
Expand Down

0 comments on commit b9ace45

Please sign in to comment.