Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
seadfeng committed Aug 27, 2024
1 parent eb2af45 commit deb1ea0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
8 changes: 3 additions & 5 deletions src/components/frontend/page/home/results.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import { Button } from '@/components/ui/button';
import { downloadBase64Image, getBase64MimeType, getImageMimeType } from '@/lib/utils';
import { downloadBase64Image, getBase64MimeType, getImageMimeType, isBrowser } from '@/lib/utils';
import { ResponseInfo } from '@/types';
import { saveAs } from 'file-saver';
import JSZip from 'jszip';
Expand Down Expand Up @@ -51,9 +51,7 @@ 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 }) => {
if (!isBrowser()) {
return null;
Expand All @@ -62,7 +60,7 @@ const IconImage = ({ icon, index, onLoad, domain }: { icon: any; index: number;
const imgRef = useRef<HTMLImageElement>(null);
const t = useTranslations();
useEffect(() => {
if (isBrowser() && imgRef.current) {
if (imgRef.current) {
const img = imgRef.current;
const handleImageLoad = () => {
setSizes(`${img.naturalWidth}x${img.naturalHeight}`);
Expand Down
8 changes: 5 additions & 3 deletions src/components/frontend/shared/image-code.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"use client";
import Image from "next/image";

import CodeCopyBtn from "@/components/shared/CodeCopyBtn";
import { Skeleton } from "@/components/ui/skeleton";
import dynamic from 'next/dynamic';
import Image from "next/image";
import { useEffect, useState } from "react";

const CodeCopyBtn = dynamic(() => import('@/components/shared/CodeCopyBtn'), { ssr: false })


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);
useEffect(() => {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

export function isBrowser() {
return typeof window !== 'undefined' && window.navigator != null;
}
export const getOrigin = ({ headers }: { headers: Headers }) => {
const url = new URL(headers.get("x-request-url")!);
return `${url.protocol}//${url.host}`;
Expand Down

0 comments on commit deb1ea0

Please # to comment.