Skip to content

Commit

Permalink
feat(issue118): 个人主页展示按创作者、普通用户分割
Browse files Browse the repository at this point in the history
1. 删除注释
  • Loading branch information
perserve2013 committed Feb 13, 2025
1 parent 4cea2a0 commit 97efabb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 98 deletions.
11 changes: 0 additions & 11 deletions src/app/u/[handle]/creator/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,16 @@
* limitations under the License.
*/

//20250212 modify begin
import { get } from '@/utils/request';

import ProjectOwner from '../ProjectOwner';

export default async function CreatorProfile({ params }) {
const config = { isServer: true };
const { data } = await get(`ts/v1/user/info/handle/${params.handle}`, config);
//钱包信息不再需要了,因为后面这个data被覆盖了
// if (data?.social.user_wallet && data?.base.user_show_wallet) {
// data.web3Bio = await get(`https://api.web3.bio/profile/${data?.social.user_wallet}`, {
// ...config,
// headers: {
// 'X-API-KEY': process.env.NEXT_PUBLIC_WEB3BIO,
// },
// });
// }
if (!data?.base?.user_project_owner) {
return <div>you do not have authority</div>;
}
const { data: activityData } = await get(`ts/v1/user/info/${data?.base.user_id}/creator/activity`, config);
return <ProjectOwner data={data} activities={activityData?.list || []} />;
}
//20250212 modify end
11 changes: 0 additions & 11 deletions src/app/u/[handle]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { get } from '@/utils/request';

import ProjectOwner from './ProjectOwner';
import ProjectPersonal from './ProjectPersonal';

export default async function UserProfile({ params }) {
Expand All @@ -31,15 +30,5 @@ export default async function UserProfile({ params }) {
},
});
}

//20250212 modify begin
// if (!data?.base?.user_project_owner) {
// return <ProjectPersonal data={data} />;
// }

// const { data: activityData } = await get(`ts/v1/user/info/${data?.base.user_id}/creator/activity`, config);

// return <ProjectOwner data={data} activities={activityData?.list || []} />;
return <ProjectPersonal data={data} />;
//20250212 modify end
}
102 changes: 26 additions & 76 deletions src/domain/profile/views/team-profile/TeamProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,25 @@
* limitations under the License.
*/

import React from 'react';
import { useState } from 'react';
import { useDebouncedCallback } from 'use-debounce';

import { isBlockDataValid } from '@/components/block-editor';
import useAppConfig from '@/hooks/useAppConfig';
import useMounted from '@/hooks/useMounted';
import { isBlockDataValid } from '@/components/block-editor';

import { useViewingSelf } from '../../../auth/hooks';
import PublishedCourseListView from '../../../course/views/published-course-list';
import PublishedChallengeListView from '../../../challenge/views/published-challenge-list';
import PublishedBountyListView from '../../../bounty/views/published-bounty-list';
import PublishedChallengeListView from '../../../challenge/views/published-challenge-list';
import PublishedCourseListView from '../../../course/views/published-course-list';
import PublishedQuizListView from '../../../quiz/views/published-quiz-list';

import { fetchBlockContent, updateBlockContent } from '../../repository';
import TabBarWidget from '../../widgets/tab-bar';
import SocialInfoWidget from '../../widgets/social-info';
import ActivityTabListWidget from '../../widgets/activity-tab-list';

import SocialInfoWidget from '../../widgets/social-info';
import TabBarWidget from '../../widgets/tab-bar';
import CustomContent from './CustomContent';
import LatestActivityList from './LatestActivityList';
import React from 'react';
import { useEffect, useState, useRef } from 'react';

const tabs = [
{
Expand Down Expand Up @@ -80,8 +78,6 @@ const tabs = [
];

function TeamProfileView({ data, activities }) {
const hasUpdated = useRef(false);
debugger;
const [tabActive, setTabActive] = useState(1);
const [blockContent, setBlockContent] = useState(null);
const viewingSelf = useViewingSelf(data?.base.user_id);
Expand Down Expand Up @@ -109,79 +105,32 @@ function TeamProfileView({ data, activities }) {
isBlockDataValid(blockContent),
].join('-');

//20250211 modify begin:
const publishedTypes_b = {
'Open Course': 'open_course_num',
Bounty: 'bounty_num',
Challenges: 'challenge_num',
Quiz: 'quiz_num',
};
// const appendTextToNode = (node, appendText) => {
// return React.Children.map(node, child => {
// if (React.isValidElement(child)) {
// return React.cloneElement(child, {},
// typeof child.props.children === 'string'
// ? child.props.children + appendText
// : appendTextToNode(child.props.children, appendText)
// );
// }
// return child;
// });
// };
useEffect(() => {
if (!hasUpdated.current) {
console.log('首次加载时执行的代码');
tabs.forEach(obj => {
const num = data?.num[publishedTypes_b[obj.text]];
obj.node = (
// 根据 data?.num 生成更新后的 tabs 数组
const updatedTabs = useMemo(() => {
return tabs.map(tab => {
const count = data?.num && publishedTypes_b[tab.text] ? data.num[publishedTypes_b[tab.text]] : 0;
// 修改 text 属性,添加上 count
const newText = `${tab.text} (${count})`;
return {
...tab,
text: newText,
// 同时更新 node 中展示的内容
node: (
<>
{obj.node.props.children.map((span, index) => {
if (React.isValidElement(span) && typeof span.props.children === 'string') {
return React.cloneElement(span, { key: index }, span.props.children + '(' + num + ')');
}
return span;
})}
<span className="inline md:hidden">{newText}</span>
<span className="hidden md:inline">{newText}</span>
</>
);
});
hasUpdated.current = true; // 只执行一次
}
}, []); // 依赖项是 hasUpdated,确保只执行一次
// useEffect(() => {
// // 先确保 window 存在,证明当前代码运行在客户端
// if (typeof window !== 'undefined') {
// // 这里访问 sessionStorage 就不会报错了
// const codeExecuted = sessionStorage.getItem('codeExecuted');
// if (!codeExecuted) {
// console.log('首次加载时执行的代码');
// tabs.forEach(obj => {
// const num = data?.num[publishedTypes_b[obj.text]];
// obj.node = (
// <>
// {obj.node.props.children.map((span, index) => {
// if (React.isValidElement(span) && typeof span.props.children === 'string') {
// return React.cloneElement(span, { key: index }, span.props.children + '(' + num + ')');
// }
// return span;
// })}
// </>
// );
// });
// sessionStorage.setItem('codeExecuted', 'true');
// }
// }
// }, []);

//console.log(t.text+'='+data?.num[publishedTypes_b[t.text]]);
//t.text = (t.text + '(' + data?.num[publishedTypes_b[t.text]] + ')');
//t.node = appendTextToNode(t.node, data?.num[publishedTypes_b[t.text]]);
// t.node.props.children.map(
// (t,i)=>{
// t.children = t.children+data?.num[publishedTypes_b[t.text]];
// }
// );
),
};
});
}, [data?.num]);

Check warning on line 132 in src/domain/profile/views/team-profile/TeamProfile.js

View workflow job for this annotation

GitHub Actions / lint

React Hook useMemo has a missing dependency: 'publishedTypes_b'. Either include it or remove the dependency array

//20250211 modify end:
return (
<div className="md:pl-[410px] md:pb-14 md:pr-14">
{devPlazaEnabled && (
Expand All @@ -200,7 +149,8 @@ function TeamProfileView({ data, activities }) {
onChange={setTabActive}
/>
{tabContent[tabActive]}
<ActivityTabListWidget userId={data?.base.user_id} tabs={tabs} />
{/* 将更新后的 tabs 数组传递 */}
<ActivityTabListWidget userId={data?.base.user_id} tabs={updatedTabs} />
</div>
);
}
Expand Down

0 comments on commit 97efabb

Please sign in to comment.