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

chore: update lazyload dependency #10

Merged
merged 1 commit into from
Jun 14, 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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"@docusaurus/theme-mermaid": "^3.4.0",
"@docusaurus/theme-search-algolia": "^3.4.0",
"@mdx-js/react": "^3.0.0",
"@parrotjs/react-lazyload": "^0.0.5",
"@radix-ui/react-avatar": "^1.0.4",
"autoprefixer": "^10.4.19",
"class-variance-authority": "^0.7.0",
Expand All @@ -32,6 +31,7 @@
"prism-react-renderer": "^2.3.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-lazyload": "^3.2.1",
"shadcn-ui": "^0.8.0",
"tailwind-merge": "^2.3.0",
"tailwindcss": "^3.4.3",
Expand All @@ -41,6 +41,7 @@
"@docusaurus/module-type-aliases": "3.4.0",
"@docusaurus/tsconfig": "3.4.0",
"@docusaurus/types": "3.4.0",
"@types/react-lazyload": "^3.2.3",
"typescript": "~5.2.2"
},
"browserslist": {
Expand Down
34 changes: 11 additions & 23 deletions src/components/Member/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Avatar } from "@/components/ui/avatar"
import { memberData, imgPrefix, githubPrefix, visibleYearsCount, compareMembers } from "@/components/Member/memberData";
import GithubIcon from '@site/static/img/github.svg';
import { useEffect, useMemo, useState } from 'react';
import LazyLoad from 'react-lazyload';

import { compareMembers, githubPrefix, imgPrefix, memberData, visibleYearsCount } from "@/components/Member/memberData";
import { Avatar } from "@/components/ui/avatar";
import BlogIcon from '@site/static/img/blog.svg';
import React, { useState, useMemo, useEffect } from 'react';
import GithubIcon from '@site/static/img/github.svg';

import './styles.module.css';

export default function Component() {
Expand All @@ -15,17 +18,6 @@ export default function Component() {

const displayedYears = isExpanded ? sortedYears : sortedYears.slice(0, visibleYearsCount);

// 我们创建一个 state 来存储 LazyLoad 组件
const [LazyLoad, setLazyLoad] = useState(null);

useEffect(() => {
// 动态导入 LazyLoad 组件,并在客户端代码执行时设置 state
import('@parrotjs/react-lazyload').then(LazyLoadModule => {
setLazyLoad(() => LazyLoadModule.default);
});
}, []);


// 当 activeYear 改变时,检查 focus 是否存在于新的年份中
useEffect(() => {
const focuses = new Set(data[activeYear].map(member => member.focus));
Expand Down Expand Up @@ -104,21 +96,17 @@ export default function Component() {
className="flex flex-col items-center gap-1 bg-white dark:bg-gray-950 p-2 rounded-lg shadow-md" // 添加 max-w-xs 和 mx-auto 以限制卡片宽度并在其父容器中居中
>
<Avatar>
{LazyLoad ? (
<LazyLoad>
<img src={imgPrefix + member.avatar} alt={member.name} className="w-20 h-20 rounded-full" />
</LazyLoad>
) : (
<div>Loading...</div>
)}
<LazyLoad offset={200}>
<img src={imgPrefix + member.avatar} alt={member.name} className="w-20 h-20 rounded-full" />
</LazyLoad>
</Avatar>
<div className="text-center">
{/* name */}
<h3 className="font-semibold text-lg mb-1">{member.name}</h3>
{/* major */}
<p className="text-gray-500 dark:text-gray-400 text-xs mb-1">{member.major}</p>
{/* Github link */}
{member.github !== undefined && (
{member.github && (
<a
href={githubPrefix + member.github}
target="_blank"
Expand Down
Loading