Skip to content

Commit ace7737

Browse files
author
521xueweihan
committed
perf: sponsor style
1 parent 6cc44a6 commit ace7737

File tree

16 files changed

+173
-72
lines changed

16 files changed

+173
-72
lines changed

public/locales/en/common.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@
105105
"limit": "Word limit: 1-1000 characters",
106106
"contact_placeholder": "Contact information: WeChat/Phone number/Email",
107107
"submit": "Submit",
108+
"contact_info": "You can also contact me directly: ",
109+
"contact_info_desc": "[email protected]",
108110
"options": {
109111
"feedback": {
110112
"name": "Suggestions",

public/locales/en/periodical.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"title": "HelloGitHub Monthly",
3-
"description": "Discover engaging and beginner-friendly open-source projects on GitHub, with the latest updates published on the 28th of each month. Spanning development tools, open-source books, tutorials, and enterprise-level projects, we aim to make you fall in love with open source.",
3+
"description": "Sharing interesting, beginner-friendly open-source projects from GitHub. Updated monthly on the 28th, covering developer tools, open-source books, tutorials, and enterprise-grade projects to help you fall in love with open source.",
44
"nav": "HelloGitHub Monthly",
5-
"p_text": "<strong>HelloGitHub Monthly</strong> shares interesting and beginner-friendly open source projects on GitHub. Published on the 28th of each month, it includes development tools, open source books, tutorials, and enterprise-level projects, helping you enjoying programming and fall in love with open source!",
5+
"p_text": "<strong>'HelloGitHub Monthly'</strong> has been carefully curating interesting, beginner-friendly open-source projects from GitHub every month since 2016, updated on the 28th. It covers developer tools, open-source books, tutorials, enterprise-grade projects, and more, enabling you to quickly discover the charm and spark your interest in open source.",
66
"read_button": "Read",
77
"submit_button": "Submit",
88
"detail_button": "Detail",
@@ -32,7 +32,7 @@
3232
"title": "HelloGitHub Monthly Vol.{{num}}",
3333
"nav": "Volume",
3434
"h2_text": "HelloGitHub Vol.{{num}}",
35-
"p_text": "<p>HelloGitHub shares interesting and beginner-friendly open source projects on GitHub, updated on the <strong>28th of each month</strong>. Here you will find fun and beginner-level open source projects, open source books, practical projects, and enterprise-level projects, allowing you to quickly appreciate the charm of open source and develop an interest in it.</p>",
35+
"p_text": "<p>HelloGitHub shares interesting, beginner-friendly open-source projects from GitHub, updated <strong>every month on the 28th</strong>. Discover fun beginner projects, open-source books, practical tutorials, and enterprise-grade projects, helping you quickly experience and become interested in the charm of open source.</p>",
3636
"catalog": "Catalog",
3737
"catalog2": "Catalog"
3838
}

public/locales/en/profile.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"featured": "Featured",
8989
"failed": "Failed",
9090
"review": "Under Review",
91-
"feedback": "Feedback"
91+
"feedback": "Feedback",
92+
"appeal": "Appeal"
9293
}
9394
}

public/locales/zh/common.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@
105105
"limit": "字数限制 1-1000 字符",
106106
"contact_placeholder": "联系方式:微信/手机号/邮箱",
107107
"submit": "提交",
108+
"contact_info": "您也可以直接联系我:",
109+
"contact_info_desc": "xueweihan(微信)",
108110
"options": {
109111
"feedback": { "name": "建议", "title": "建议改善" },
110112
"bug": { "title": "问题反馈" },

public/locales/zh/periodical.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"title": "HelloGitHub 月刊",
3-
"description": "分享 GitHub 上有趣的入门级开源项目,每月 28 日发布最新内容涵盖开发工具、开源书籍、教程及企业级的开源项目,让你爱上开源。",
3+
"description": "分享 GitHub 上有趣的入门级开源项目,每月 28 日发布最新内容涵盖开发工具、开源书籍、教程及企业级的开源项目,让你爱上开源。",
44
"nav": "HelloGitHub 月刊",
5-
"p_text": "<strong>「HelloGitHub 月刊」</strong>分享 GitHub 上有趣、入门级的开源项目,每月 28 号发布最新一期。内容包括开发利器、开源书籍、教程、企业级项目等,让你发现编程的乐趣、爱上开源!",
5+
"p_text": "<strong>「HelloGitHub 月刊」</strong>自 2016 年起,每月 28 号精选发布 GitHub 上有趣、入门级的开源项目。内容包括开发利器、开源书籍、教程、企业级项目等,帮助你快速发现开源的魅力,对开源产生兴趣。",
66
"read_button": "查看",
77
"submit_button": "推荐",
88
"detail_button": "详情",
@@ -32,7 +32,7 @@
3232
"title": "《HelloGitHub 月刊》第 {{num}} 期",
3333
"nav": "期数",
3434
"h2_text": "《HelloGitHub》第 {{num}} 期",
35-
"p_text": "<p>HelloGitHub 分享 GitHub 上有趣、入门级的开源项目,<strong>每月 28 号</strong>更新一期。这里有好玩和入门级的开源项目、开源书籍、实战项目、企业级项目,让你用极短的时间感受到开源的魅力,对开源产生兴趣。</p>",
35+
"p_text": "<p>HelloGitHub 分享 GitHub 上有趣、入门级的开源项目,<strong>每月 28 号</strong>更新一期。这里有好玩和入门级的开源项目、开源书籍、实战项目、企业级项目,帮助你快速发现开源的魅力,对开源产生兴趣。</p>",
3636
"catalog": "本期目录",
3737
"catalog2": "目录"
3838
}

public/locales/zh/profile.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"featured": "已推荐",
8989
"failed": "未通过",
9090
"review": "审核中",
91-
"feedback": "反馈"
91+
"feedback": "反馈",
92+
"appeal": "申诉"
9293
}
9394
}

src/components/dialog/Feedback.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { useTranslation } from 'next-i18next';
22
import { useCallback, useEffect, useState } from 'react';
3-
import { IoIosArrowRoundForward } from 'react-icons/io';
3+
import {
4+
IoIosArrowRoundForward,
5+
IoMdInformationCircleOutline,
6+
} from 'react-icons/io';
47

58
import { useLoginContext } from '@/hooks/useLoginContext';
69

@@ -129,6 +132,22 @@ export function CreateFeedback({
129132
))}
130133
</div>
131134

135+
<div className='rounded-md bg-blue-50 p-3 dark:bg-blue-900/30'>
136+
<div className='flex'>
137+
<div className='flex-shrink-0'>
138+
<IoMdInformationCircleOutline className='h-5 w-5 text-blue-400' />
139+
</div>
140+
<div className='ml-2 flex-1 text-sm'>
141+
<p className='text-blue-700 dark:text-blue-300'>
142+
{t('feedback.contact_info')}
143+
<span className='font-medium'>
144+
{t('feedback.contact_info_desc')}
145+
</span>
146+
</p>
147+
</div>
148+
</div>
149+
</div>
150+
132151
<div>
133152
<textarea
134153
className='focus:ring-shadow-1 w-full rounded border-gray-200 p-3 text-sm focus:border-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-800 dark:placeholder:text-gray-400'

src/components/layout/Header.tsx

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useEffect, useState } from 'react';
55
import { AiOutlineGithub } from 'react-icons/ai';
66

77
import { useLoginContext } from '@/hooks/useLoginContext';
8+
import { useSponsor } from '@/hooks/useSponsor';
89

910
import HeaderBtn from '@/components/buttons/HeaderBtn';
1011
import LanguageSwitcher from '@/components/buttons/LanguageSwitcher';
@@ -13,14 +14,10 @@ import ThemeSwitcher from '@/components/buttons/ThemeSwitcher';
1314
import { RepoModal } from '@/components/dialog/RepoModal';
1415
import AvatarWithDropdown from '@/components/dropdown/AvatarWithDropdown';
1516

16-
import { getHeaderAd } from '@/services/home';
17-
1817
import TopBanner from './TopBanner';
1918
import { LoginButton } from '../buttons/LoginButton';
2019
import SearchInput from '../search/SearchInput';
2120

22-
import { AdvertItem } from '@/types/home';
23-
2421
interface Props {
2522
hiddenAd: () => void;
2623
showAd: () => void;
@@ -31,34 +28,26 @@ const Header = ({ hiddenAd, showAd }: Props) => {
3128
const { isLogin } = useLoginContext();
3229
const [curPath, setCurPath] = useState('');
3330
const { t, i18n } = useTranslation('common');
34-
const [adData, setAdData] = useState<AdvertItem | null>(null);
3531
const [_, setHasHeaderAd] = useState(false);
32+
const { topAd } = useSponsor();
3633

3734
const handleCloseAd = () => {
3835
hiddenAd();
3936
setHasHeaderAd(false);
4037
};
4138

42-
const initHeaderAd = async () => {
43-
const res = await getHeaderAd();
44-
if (res.success) {
45-
if (res.data.length > 0) {
46-
if (localStorage.adClosed === res.data[0].aid) {
47-
setHasHeaderAd(false);
48-
} else {
49-
showAd();
50-
setHasHeaderAd(true);
51-
setAdData(res.data[0]);
52-
}
53-
} else {
39+
useEffect(() => {
40+
if (topAd) {
41+
if (localStorage.adClosed === topAd.aid) {
5442
setHasHeaderAd(false);
43+
} else {
44+
showAd();
45+
setHasHeaderAd(true);
5546
}
47+
} else {
48+
setHasHeaderAd(false);
5649
}
57-
};
58-
59-
useEffect(() => {
60-
initHeaderAd();
61-
}, []);
50+
}, [topAd, showAd]);
6251

6352
useEffect(() => {
6453
setCurPath(router.pathname);
@@ -79,10 +68,10 @@ const Header = ({ hiddenAd, showAd }: Props) => {
7968

8069
return (
8170
<div className='fixed z-10 w-full bg-white shadow-sm backdrop-blur dark:border dark:border-gray-50/[0.06] dark:bg-transparent'>
82-
{adData && (
71+
{topAd && (
8372
<TopBanner
8473
i18n_lang={i18n.language}
85-
data={adData}
74+
data={topAd}
8675
onClose={handleCloseAd}
8776
/>
8877
)}

src/components/respository/Info.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import classNames from 'classnames';
22
import copy from 'copy-to-clipboard';
33
import ReactECharts from 'echarts-for-react';
4+
import { useRouter } from 'next/router';
45
import { useEffect, useRef, useState } from 'react';
56
import {
67
AiFillCaretUp,
@@ -103,6 +104,7 @@ const Info = ({ repo, t, i18n_lang }: RepositoryProps) => {
103104
const [favoriteOptions, setFavoriteOptions] = useState<option[]>([]);
104105
const [showDropdown, setShowDropdown] = useState(false);
105106
const dropdownRef = useRef<any>();
107+
const router = useRouter();
106108

107109
const urlOptions = useURLOptions({ repo, t });
108110

@@ -327,7 +329,10 @@ const Info = ({ repo, t, i18n_lang }: RepositoryProps) => {
327329
</h1>
328330
</CustomLink>
329331
{repo.is_claimed && (
330-
<div className=' group relative ml-0.5 flex cursor-pointer items-center'>
332+
<div
333+
className='group relative ml-0.5 flex cursor-pointer items-center'
334+
onClick={() => router.push('/badge')}
335+
>
331336
<GoVerified className='ml-0.5 text-xl text-blue-500 group-hover:text-blue-600' />
332337
<div className='absolute hidden flex-row transition-opacity duration-300 group-hover:flex'>
333338
<div className='relative left-6 w-0 rounded-md bg-gray-300 p-1 text-xs font-medium text-white group-hover:w-max dark:bg-gray-700 dark:text-gray-200'>

src/components/side/Side.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import { useTranslation } from 'next-i18next';
22
import { useEffect, useRef, useState } from 'react';
3-
import useSWRImmutable from 'swr/immutable';
3+
4+
import { useSponsor } from '@/hooks/useSponsor';
45

56
import Footer from '@/components/layout/Footer';
67
import { SideAd, SideFixAd } from '@/components/side/SideAd';
78
import SiteStats from '@/components/side/Stats';
89

9-
import { fetcher } from '@/services/base';
10-
import { makeUrl } from '@/utils/api';
11-
1210
import Recommend from './Recommend';
1311
import UserStatus from './UserStatus';
1412

15-
import { AdvertItems } from '@/types/home';
16-
1713
interface Props {
1814
isHome: boolean;
1915
topValue: string;
@@ -23,12 +19,7 @@ export const Side = ({ isHome, topValue }: Props) => {
2319
const { t, i18n } = useTranslation('common');
2420
const [displayAdOnly, setDisplayAdOnly] = useState(false);
2521
const containerRef = useRef<HTMLDivElement>(null);
26-
const { data, isValidating } = useSWRImmutable<AdvertItems>(
27-
makeUrl('/sponsor/', { position: 'side' }),
28-
fetcher
29-
);
30-
31-
const adverts = data?.success ? data.data : [];
22+
const { sideAds, isValidating } = useSponsor();
3223

3324
useEffect(() => {
3425
const handleScroll = () => {
@@ -52,7 +43,7 @@ export const Side = ({ isHome, topValue }: Props) => {
5243
<UserStatus t={t} i18n_lang={i18n.language} />
5344
</div>
5445
{!isValidating && (
55-
<SideAd data={adverts} t={t} i18n_lang={i18n.language} />
46+
<SideAd data={sideAds} t={t} i18n_lang={i18n.language} />
5647
)}
5748
{isHome ? <SiteStats t={t} /> : <Recommend t={t} />}
5849
</div>
@@ -63,9 +54,9 @@ export const Side = ({ isHome, topValue }: Props) => {
6354
)}
6455
</div>
6556
</div>
66-
{adverts && (
57+
{sideAds && (
6758
<SideFixAd
68-
data={adverts}
59+
data={sideAds}
6960
displayAdOnly={displayAdOnly}
7061
t={t}
7162
i18n_lang={i18n.language}

0 commit comments

Comments
 (0)