Skip to content

Commit

Permalink
优化图片相关
Browse files Browse the repository at this point in the history
  • Loading branch information
electh committed Dec 16, 2024
1 parent a684cc9 commit 3439871
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/components/ArticleList/components/ArticleCardCover.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useEffect, useRef, useState } from "react";
import { Image } from "@nextui-org/react";
import { cn } from "@/lib/utils.js";
import { getReferrerPolicy } from "@/lib/utils";

export default function ArticleCardCover({ imageUrl }) {
const [error, setError] = useState(false);
const [isVisible, setIsVisible] = useState(false);
const [loading, setLoading] = useState(true);
const imgRef = useRef(null);
const referrerPolicy = getReferrerPolicy(imageUrl);

useEffect(() => {
const imgElement = imgRef.current;
Expand Down Expand Up @@ -68,6 +70,7 @@ export default function ArticleCardCover({ imageUrl }) {
onError={() => setError(true)}
radius="none"
loading="lazy"
referrerPolicy={referrerPolicy}
removeWrapper
classNames={{
img: "object-cover w-full aspect-video",
Expand Down
8 changes: 5 additions & 3 deletions src/components/ArticleView/components/ArticleImage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default function ArticleImage({ imgNode }) {

const { src, alt = "" } = imgNode.attribs;

const referrerPolicy = getReferrerPolicy(src);

const handleImageClick = (e) => {
e.preventDefault();

Expand Down Expand Up @@ -48,8 +50,8 @@ export default function ArticleImage({ imgNode }) {

if (error) {
return (
<div className="w-full h-full min-h-[200px] bg-content2 flex items-center justify-center">
<div className="flex flex-col items-center gap-2 text-content2-foreground">
<div className="!max-w-[calc(100%+40px)] -mx-5 h-full min-h-[200px] bg-content2 flex items-center justify-center">
<div className="flex flex-col items-center gap-2 text-default-500">
<ImageOff className="size-5" />
<span className="text-sm">图片加载失败</span>
</div>
Expand All @@ -69,7 +71,7 @@ export default function ArticleImage({ imgNode }) {
src={src}
alt={alt}
loading="lazy"
referrerPolicy={getReferrerPolicy(src)}
referrerPolicy={referrerPolicy}
onError={() => setError(true)}
onClick={handleImageClick}
/>
Expand Down

0 comments on commit 3439871

Please sign in to comment.