Skip to content

Commit

Permalink
add isBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
seadfeng committed Aug 27, 2024
1 parent 40dba40 commit bb39233
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/components/frontend/page/home/results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ const downloadImagesAsZip = async (icons: { href: string, sizes?: string }[], do
});
});
}

function isBrowser() {
return typeof window !== 'undefined' && typeof navigator !== 'undefined';
}
const IconImage = ({ icon, index, onLoad, domain }: { icon: any; index: number; domain: string; onLoad?: (sizes: string)=> void }) => {
const [sizes, setSizes] = useState<string>(icon.sizes);
const imgRef = useRef<HTMLImageElement>(null);
const t = useTranslations();
useEffect(() => {
if (imgRef.current) {
if (isBrowser() &&imgRef.current) {
const img = imgRef.current;
const handleImageLoad = () => {
setSizes(`${img.naturalWidth}x${img.naturalHeight}`);
Expand Down
2 changes: 0 additions & 2 deletions src/components/frontend/shared/image-code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import Image from "next/image";

import CodeCopyBtn from "@/components/shared/CodeCopyBtn";
import { Skeleton } from "@/components/ui/skeleton";
import { useTranslations } from "next-intl";
import { useEffect, useState } from "react";

const ImageCode = ({ alt, title, src, codeStr, className}: { src: string; codeStr: string; title: string; alt: string; className?: string; }) => {
const [dimensions, setDimensions] = useState<{ width: number; height: number } | null>(null);
const t = useTranslations();
useEffect(() => {
if (src) {
const img = new window.Image();
Expand Down

0 comments on commit bb39233

Please sign in to comment.