Skip to content

Commit

Permalink
Merge pull request #12 from nowscott/development
Browse files Browse the repository at this point in the history
展示更多内容、添加投稿通道
  • Loading branch information
nowscott authored Nov 28, 2024
2 parents f2686e8 + 6403117 commit 18b9a80
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 34 deletions.
14 changes: 14 additions & 0 deletions components/DataUpdateDisplay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// components/DataUpdateDisplay.js
import React from 'react';

const DataUpdateDisplay = ({ lastFetched }) => {
const formattedDate = new Date(lastFetched).toLocaleString();

return (
<div className="text-center text-sm text-gray-600 dark:text-gray-300 py-2">
数据更新时间:{formattedDate}
</div>
);
};

export default DataUpdateDisplay;
38 changes: 34 additions & 4 deletions components/Footer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
import { useEffect, useState } from 'react';

// components/Footer.js
const Footer = () => {
const [visitCount, setVisitCount] = useState(null);

useEffect(() => {
// 调用 API 获取访问量
const fetchVisitCount = async () => {
try {
const response = await fetch('/api/visit-count');
const data = await response.json();
setVisitCount(data.count);
} catch (error) {
console.error('获取访问量失败:', error);
}
};

fetchVisitCount();
}, []);

return (
<p className='text-xs whitespace-nowrap text-purple-900 dark:text-rose-200 py-4'>
Copyright © 2021 - NowScott
</p>
)
<div className='text-xs whitespace-nowrap text-purple-900 dark:text-rose-200 py-4'>
<a
href='https://nowscott.notion.site/134f941cf9b880e1b00ee5bdf55fd71d?pvs=105'
target='_blank'
rel='noopener noreferrer'
className='block mb-2 underline'
>
投稿网页
</a>
{visitCount !== null && (
<p className='mb-1'>访问量:{visitCount}</p>
)}
<p>Copyright © 2021 - NowScott</p>
</div>
);
};

export default Footer;
10 changes: 0 additions & 10 deletions components/Titles.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ const Titles = () => (
Individual Web Index.
</a>
</div>
<div className={`text-xl my-1 text-center font-normal title-2`}>
<a
className="underline hover:no-underline text-purple-700 dark:text-stone-100"
href="https://github.com/nowscott/IndWebIndex/blob/main/README.md"
target="_blank"
rel="noopener noreferrer"
>
如何部署
</a>
</div>
</div>
);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ind-web-index",
"version": "2.2.3",
"version": "2.2.4",
"scripts": {
"dev": "next dev",
"build": "next build",
Expand Down
29 changes: 10 additions & 19 deletions pages/mainPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Tags from '../components/Tags';
import WebList from '../components/WebList';
import Footer from '../components/Footer';
import FontMenu from '../components/FontMenu';
import DataUpdateDisplay from '../components/DataUpdateDisplay';
import { randomSort, unique, extractTags, filterPostsBySearch, toggleTagButton, updateResults } from '../lib/dataLoader';

const MainPage = ({ initialPosts, lastFetched }) => {
Expand All @@ -16,27 +17,10 @@ const MainPage = ({ initialPosts, lastFetched }) => {
const [tags, setTags] = useState([]);
const [onList, setOnList] = useState([]);
const [filteredPosts, setFilteredPosts] = useState(initialPosts || []);
const [visitCount, setVisitCount] = useState(null);

useEffect(() => {
console.log(`数据更新时间: ${new Date(lastFetched).toLocaleString()}`);
setPosts(initialPosts || []);

fetch('/api/visit-count')
.then(response => response.json())
.then(data => {
if (data.count) {
console.log(`本页面已被访问 ${data.count} 次`);
setVisitCount(data.count);
} else {
console.log('访问计数数据不可用:', data.message);
}
})
.catch(error => {
console.error('Error fetching visit count:', error);
});

}, [initialPosts, lastFetched]);
}, [initialPosts]);

useEffect(() => {
const filteredNormalPosts = (initialPosts || []).filter(post => post.state !== '隐藏');
Expand Down Expand Up @@ -68,8 +52,15 @@ const MainPage = ({ initialPosts, lastFetched }) => {

return (
<div className='bg-stone-50 dark:bg-slate-800 backdrop-blur-[15px] m-0 min-h-screen overflow-auto tracking-widest text-center flex flex-col'>
<div className="relative flex items-center py-2">
<span className="text-xs text-gray-500 dark:text-gray-400 mx-auto">
数据更新时间:{new Date(lastFetched).toLocaleString()}
</span>
<div className="absolute right-4">
<ThemeToggleButton />
</div>
</div>
<FontMenu />
<ThemeToggleButton />
<div className="flex-grow text-center mx-auto relative">
<Titles />
<SearchBox searchQuery={searchQuery} setSearchQuery={setSearchQuery} />
Expand Down

0 comments on commit 18b9a80

Please sign in to comment.