From 4cea2a006c3162e97335404d99a809854e123e2a Mon Sep 17 00:00:00 2001 From: perserve2013 <836716623@qq.com> Date: Wed, 12 Feb 2025 19:45:17 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat(issue118):=20=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E4=B8=BB=E9=A1=B5=E5=B1=95=E7=A4=BA=E6=8C=89=E5=88=9B=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E3=80=81=E6=99=AE=E9=80=9A=E7=94=A8=E6=88=B7=E5=88=86?= =?UTF-8?q?=E5=89=B2=201.=20=E5=B0=86=E5=BD=93=E5=89=8D=E5=88=9B=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E9=A1=B5=E9=9D=A2=E5=B7=A6=E4=BE=A7=E7=9A=84=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E7=AD=89=E6=95=B0=E9=87=8F=E6=98=BE=E7=A4=BA=E5=9C=A8?= =?UTF-8?q?=E5=8F=B3=E4=BE=A7=E7=9B=B8=E5=BA=94=E7=9A=84=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E5=8D=A1=E4=B8=8A=EF=BC=8C=E6=A0=BC=E5=BC=8F=E4=B8=BA=E3=80=8C?= =?UTF-8?q?Open=20Course=20(15)=E3=80=8D=E8=BF=99=E7=A7=8D=EF=BC=9B=202.?= =?UTF-8?q?=20=E5=B0=86=E5=BD=93=E5=89=8D=E5=88=9B=E4=BD=9C=E8=80=85?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=8F=B3=E4=BE=A7=E5=B1=95=E7=A4=BA=E7=9A=84?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E9=80=9A=E8=BF=87=E5=8F=A6=E5=A4=96=E7=9A=84?= =?UTF-8?q?=20URL=20=E8=BF=9B=E8=A1=8C=E8=AE=BF=E9=97=AE=EF=BC=88=E6=9A=82?= =?UTF-8?q?=E5=AE=9A=E4=B8=BA=20/u/:slug/creator=EF=BC=89=203.=20=E6=97=A0?= =?UTF-8?q?=E8=AE=BA=E6=98=AF=E6=99=AE=E9=80=9A=E7=94=A8=E6=88=B7=E8=BF=98?= =?UTF-8?q?=E6=98=AF=E5=88=9B=E4=BD=9C=E8=80=85=EF=BC=8C=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=20/u/:slug=20=E6=97=B6=EF=BC=8C=E6=98=BE=E7=A4=BA=E7=9A=84?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E4=B8=8E=E6=99=AE=E9=80=9A=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=9C=8B=E5=88=B0=E7=9A=84=E9=A1=B5=E9=9D=A2=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/u/[handle]/creator/page.js | 40 +++++++ src/app/u/[handle]/page.js | 15 +-- .../profile/views/team-profile/TeamProfile.js | 101 ++++++++++++++++-- 3 files changed, 139 insertions(+), 17 deletions(-) create mode 100644 src/app/u/[handle]/creator/page.js diff --git a/src/app/u/[handle]/creator/page.js b/src/app/u/[handle]/creator/page.js new file mode 100644 index 00000000..ce2605c0 --- /dev/null +++ b/src/app/u/[handle]/creator/page.js @@ -0,0 +1,40 @@ +/** + * Copyright 2024 OpenBuild + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * 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
you do not have authority
; + } + const { data: activityData } = await get(`ts/v1/user/info/${data?.base.user_id}/creator/activity`, config); + return ; +} +//20250212 modify end diff --git a/src/app/u/[handle]/page.js b/src/app/u/[handle]/page.js index 599195ff..8591bfff 100644 --- a/src/app/u/[handle]/page.js +++ b/src/app/u/[handle]/page.js @@ -19,7 +19,7 @@ import { get } from '@/utils/request'; import ProjectOwner from './ProjectOwner'; import ProjectPersonal from './ProjectPersonal'; -export default async function UserProfile({params}) { +export default async function UserProfile({ params }) { const config = { isServer: true }; const { data } = await get(`ts/v1/user/info/handle/${params.handle}`, config); @@ -32,11 +32,14 @@ export default async function UserProfile({params}) { }); } - if (!data?.base?.user_project_owner) { - return ; - } + //20250212 modify begin + // if (!data?.base?.user_project_owner) { + // return ; + // } - const { data: activityData } = await get(`ts/v1/user/info/${data?.base.user_id}/creator/activity`, config); + // const { data: activityData } = await get(`ts/v1/user/info/${data?.base.user_id}/creator/activity`, config); - return ; + // return ; + return ; + //20250212 modify end } diff --git a/src/domain/profile/views/team-profile/TeamProfile.js b/src/domain/profile/views/team-profile/TeamProfile.js index 9e2494d6..df6d77f0 100644 --- a/src/domain/profile/views/team-profile/TeamProfile.js +++ b/src/domain/profile/views/team-profile/TeamProfile.js @@ -14,24 +14,27 @@ * limitations under the License. */ -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 PublishedBountyListView from '../../../bounty/views/published-bounty-list'; -import PublishedChallengeListView from '../../../challenge/views/published-challenge-list'; 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 PublishedQuizListView from '../../../quiz/views/published-quiz-list'; + import { fetchBlockContent, updateBlockContent } from '../../repository'; -import ActivityTabListWidget from '../../widgets/activity-tab-list'; -import SocialInfoWidget from '../../widgets/social-info'; import TabBarWidget from '../../widgets/tab-bar'; +import SocialInfoWidget from '../../widgets/social-info'; +import ActivityTabListWidget from '../../widgets/activity-tab-list'; + import CustomContent from './CustomContent'; import LatestActivityList from './LatestActivityList'; +import React from 'react'; +import { useEffect, useState, useRef } from 'react'; const tabs = [ { @@ -77,17 +80,20 @@ 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); const devPlazaEnabled = useAppConfig('devPlaza.enabled'); useMounted(() => { - devPlazaEnabled && fetchBlockContent(data?.base.user_id).then(res => { - if (res.success) { - setBlockContent(res.data); - } - }); + devPlazaEnabled && + fetchBlockContent(data?.base.user_id).then(res => { + if (res.success) { + setBlockContent(res.data); + } + }); }); const handleBlockChange = useDebouncedCallback(updateBlockContent, 3000); @@ -103,6 +109,79 @@ 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 = ( + <> + {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; + })} + + ); + }); + 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]]; + // } + // ); + + //20250211 modify end: return (
{devPlazaEnabled && ( From 97efabbd0876e9816f4aeb82d8705355726d3331 Mon Sep 17 00:00:00 2001 From: perserve2013 <836716623@qq.com> Date: Thu, 13 Feb 2025 22:16:52 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(issue118):=20=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E4=B8=BB=E9=A1=B5=E5=B1=95=E7=A4=BA=E6=8C=89=E5=88=9B=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E3=80=81=E6=99=AE=E9=80=9A=E7=94=A8=E6=88=B7=E5=88=86?= =?UTF-8?q?=E5=89=B2=201.=20=E5=88=A0=E9=99=A4=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/u/[handle]/creator/page.js | 11 -- src/app/u/[handle]/page.js | 11 -- .../profile/views/team-profile/TeamProfile.js | 102 +++++------------- 3 files changed, 26 insertions(+), 98 deletions(-) diff --git a/src/app/u/[handle]/creator/page.js b/src/app/u/[handle]/creator/page.js index ce2605c0..caf638a8 100644 --- a/src/app/u/[handle]/creator/page.js +++ b/src/app/u/[handle]/creator/page.js @@ -14,7 +14,6 @@ * limitations under the License. */ -//20250212 modify begin import { get } from '@/utils/request'; import ProjectOwner from '../ProjectOwner'; @@ -22,19 +21,9 @@ 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
you do not have authority
; } const { data: activityData } = await get(`ts/v1/user/info/${data?.base.user_id}/creator/activity`, config); return ; } -//20250212 modify end diff --git a/src/app/u/[handle]/page.js b/src/app/u/[handle]/page.js index 8591bfff..df7708c6 100644 --- a/src/app/u/[handle]/page.js +++ b/src/app/u/[handle]/page.js @@ -16,7 +16,6 @@ import { get } from '@/utils/request'; -import ProjectOwner from './ProjectOwner'; import ProjectPersonal from './ProjectPersonal'; export default async function UserProfile({ params }) { @@ -31,15 +30,5 @@ export default async function UserProfile({ params }) { }, }); } - - //20250212 modify begin - // if (!data?.base?.user_project_owner) { - // return ; - // } - - // const { data: activityData } = await get(`ts/v1/user/info/${data?.base.user_id}/creator/activity`, config); - - // return ; return ; - //20250212 modify end } diff --git a/src/domain/profile/views/team-profile/TeamProfile.js b/src/domain/profile/views/team-profile/TeamProfile.js index df6d77f0..132ecf92 100644 --- a/src/domain/profile/views/team-profile/TeamProfile.js +++ b/src/domain/profile/views/team-profile/TeamProfile.js @@ -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 = [ { @@ -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); @@ -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; - })} + {newText} + {newText} - ); - }); - 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]); - //20250211 modify end: return (
{devPlazaEnabled && ( @@ -200,7 +149,8 @@ function TeamProfileView({ data, activities }) { onChange={setTabActive} /> {tabContent[tabActive]} - + {/* 将更新后的 tabs 数组传递 */} +
); } From 5d7d3b9cd0196ce2616c4fa26aa9487552410ae9 Mon Sep 17 00:00:00 2001 From: perserve2013 <836716623@qq.com> Date: Fri, 14 Feb 2025 16:45:33 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat(issue118):=20=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E4=B8=BB=E9=A1=B5=E5=B1=95=E7=A4=BA=E6=8C=89=E5=88=9B=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E3=80=81=E6=99=AE=E9=80=9A=E7=94=A8=E6=88=B7=E5=88=86?= =?UTF-8?q?=E5=89=B2=201.=20=E6=8C=89=E7=85=A7=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E8=BF=9B=E8=A1=8C=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/u/[handle]/creator/page.js | 10 +- .../profile/views/team-profile/TeamProfile.js | 139 +++++++++--------- .../widgets/social-info/PublishedCountList.js | 37 ----- .../profile/widgets/social-info/SocialInfo.js | 30 ++-- 4 files changed, 94 insertions(+), 122 deletions(-) delete mode 100644 src/domain/profile/widgets/social-info/PublishedCountList.js diff --git a/src/app/u/[handle]/creator/page.js b/src/app/u/[handle]/creator/page.js index caf638a8..a6c8c4e4 100644 --- a/src/app/u/[handle]/creator/page.js +++ b/src/app/u/[handle]/creator/page.js @@ -21,8 +21,16 @@ 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); + 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
you do not have authority
; + return
This user is not a creator.
; } const { data: activityData } = await get(`ts/v1/user/info/${data?.base.user_id}/creator/activity`, config); return ; diff --git a/src/domain/profile/views/team-profile/TeamProfile.js b/src/domain/profile/views/team-profile/TeamProfile.js index 132ecf92..59286650 100644 --- a/src/domain/profile/views/team-profile/TeamProfile.js +++ b/src/domain/profile/views/team-profile/TeamProfile.js @@ -14,7 +14,6 @@ * limitations under the License. */ -import React from 'react'; import { useState } from 'react'; import { useDebouncedCallback } from 'use-debounce'; @@ -34,48 +33,73 @@ import TabBarWidget from '../../widgets/tab-bar'; import CustomContent from './CustomContent'; import LatestActivityList from './LatestActivityList'; -const tabs = [ - { - text: 'Open Course', - node: ( - <> - Courses - Open Course - - ), - view: PublishedCourseListView, - }, - { - text: 'Challenges', - node: ( - <> - Challenge - Challenges - - ), - view: PublishedChallengeListView, - }, - { - text: 'Bounty', - node: ( - <> - Bounty - Bounty - - ), - view: PublishedBountyListView, - }, - { - text: 'Quiz', - node: ( - <> - Quiz - Quiz - - ), - view: PublishedQuizListView, - }, -]; +const resolveTabs = published => { + const tabs = [ + { + text: 'Open Course', + node: ( + <> + Courses + Open Course + + ), + view: PublishedCourseListView, + }, + { + text: 'Challenges', + node: ( + <> + Challenge + Challenges + + ), + view: PublishedChallengeListView, + }, + { + text: 'Bounty', + node: ( + <> + Bounty + Bounty + + ), + view: PublishedBountyListView, + }, + { + text: 'Quiz', + node: ( + <> + Quiz + Quiz + + ), + view: PublishedQuizListView, + }, + ]; + + const publishedTypes_b = { + 'Open Course': 'open_course_num', + Bounty: 'bounty_num', + Challenges: 'challenge_num', + Quiz: 'quiz_num', + }; + return tabs.map(tab => { + const tab_text = tab.node.props.children[1].props.children; + const count = published && publishedTypes_b[tab_text] ? published[publishedTypes_b[tab_text]] : 0; + return { + ...tab, + // 同时更新 node 中展示的内容 + node: ( + <> + {tab.node.props.children[0]} + + {tab_text} ({count}) + + + ), + }; + }); +}; function TeamProfileView({ data, activities }) { const [tabActive, setTabActive] = useState(1); @@ -105,32 +129,6 @@ function TeamProfileView({ data, activities }) { isBlockDataValid(blockContent), ].join('-'); - const publishedTypes_b = { - 'Open Course': 'open_course_num', - Bounty: 'bounty_num', - Challenges: 'challenge_num', - Quiz: 'quiz_num', - }; - // 根据 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: ( - <> - {newText} - {newText} - - ), - }; - }); - }, [data?.num]); - return (
{devPlazaEnabled && ( @@ -149,8 +147,7 @@ function TeamProfileView({ data, activities }) { onChange={setTabActive} /> {tabContent[tabActive]} - {/* 将更新后的 tabs 数组传递 */} - +
); } diff --git a/src/domain/profile/widgets/social-info/PublishedCountList.js b/src/domain/profile/widgets/social-info/PublishedCountList.js deleted file mode 100644 index 17f70ae4..00000000 --- a/src/domain/profile/widgets/social-info/PublishedCountList.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2024 OpenBuild - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -const publishedTypes = [ - { key: 'open_course_num', text: 'Open Course' }, - { key: 'bounty_num', text: 'Bounty' }, - { key: 'challenge_num', text: 'Challange' }, - { key: 'quiz_num', text: 'Quiz' }, -]; - -function PublishedCountList({ published }) { - return published ? ( -
- {publishedTypes.map((t, i) => ( -

- {t.text} - {published[t.key]} -

- ))} -
- ) : null; -} - -export default PublishedCountList; diff --git a/src/domain/profile/widgets/social-info/SocialInfo.js b/src/domain/profile/widgets/social-info/SocialInfo.js index 0ff7eb8a..effdc09b 100644 --- a/src/domain/profile/widgets/social-info/SocialInfo.js +++ b/src/domain/profile/widgets/social-info/SocialInfo.js @@ -18,12 +18,11 @@ import { useMemo } from 'react'; import { SvgIcon } from '@/components/Image'; -import PublishedCountList from './PublishedCountList'; import SocialLink from './SocialLink'; import Web3BioProfile from './Web3BioProfile'; function socialsInfo(type, link) { - switch(type) { + switch (type) { case 'user_github': return { name: 'GitHub', @@ -51,15 +50,21 @@ function socialsInfo(type, link) { } function SocialInfoWidget({ className, data }) { - const socials = useMemo(() => Object.keys(data.social).map(i => socialsInfo(i, data.social[i])).filter(s => { - if (!s) { - return false; - } + const socials = useMemo( + () => + Object.keys(data.social) + .map(i => socialsInfo(i, data.social[i])) + .filter(s => { + if (!s) { + return false; + } - const enabled = s.enableKey ? data.base[s.enableKey] : true; + const enabled = s.enableKey ? data.base[s.enableKey] : true; - return enabled && !!s.link; - }), [data]); + return enabled && !!s.link; + }), + [data], + ); return (
@@ -68,15 +73,14 @@ function SocialInfoWidget({ className, data }) {

Social Profiles

{socials.map(i => ( - {i.name} + + {i.name} + ))}
)} - {data.base?.user_project_owner && ( - - )} {data.base?.user_show_email && data?.social?.user_email !== '' && ( <>
From df9450103ea373904594dc15c7cece3b06f8bbbf Mon Sep 17 00:00:00 2001 From: perserve2013 <836716623@qq.com> Date: Sat, 15 Feb 2025 19:50:40 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat(issue118):=20=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E4=B8=BB=E9=A1=B5=E5=B1=95=E7=A4=BA=E6=8C=89=E5=88=9B=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E3=80=81=E6=99=AE=E9=80=9A=E7=94=A8=E6=88=B7=E5=88=86?= =?UTF-8?q?=E5=89=B2=201.=20=E5=9C=A8=E2=80=9Ctabs=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E2=80=9D=E7=9A=84=E7=9B=B8=E5=BA=94=E4=BD=8D=E7=BD=AE=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E6=8B=BC=E6=8E=A5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../profile/views/team-profile/TeamProfile.js | 33 +++---------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/src/domain/profile/views/team-profile/TeamProfile.js b/src/domain/profile/views/team-profile/TeamProfile.js index 59286650..5d1950d6 100644 --- a/src/domain/profile/views/team-profile/TeamProfile.js +++ b/src/domain/profile/views/team-profile/TeamProfile.js @@ -34,13 +34,13 @@ import CustomContent from './CustomContent'; import LatestActivityList from './LatestActivityList'; const resolveTabs = published => { - const tabs = [ + return [ { text: 'Open Course', node: ( <> Courses - Open Course + Open Course({published?.['open_course_num'] ?? 0}) ), view: PublishedCourseListView, @@ -50,7 +50,7 @@ const resolveTabs = published => { node: ( <> Challenge - Challenges + Challenges({published?.['challenge_num'] ?? 0}) ), view: PublishedChallengeListView, @@ -60,7 +60,7 @@ const resolveTabs = published => { node: ( <> Bounty - Bounty + Bounty({published?.['bounty_num'] ?? 0}) ), view: PublishedBountyListView, @@ -70,35 +70,12 @@ const resolveTabs = published => { node: ( <> Quiz - Quiz + Quiz({published?.['quiz_num'] ?? 0}) ), view: PublishedQuizListView, }, ]; - - const publishedTypes_b = { - 'Open Course': 'open_course_num', - Bounty: 'bounty_num', - Challenges: 'challenge_num', - Quiz: 'quiz_num', - }; - return tabs.map(tab => { - const tab_text = tab.node.props.children[1].props.children; - const count = published && publishedTypes_b[tab_text] ? published[publishedTypes_b[tab_text]] : 0; - return { - ...tab, - // 同时更新 node 中展示的内容 - node: ( - <> - {tab.node.props.children[0]} - - {tab_text} ({count}) - - - ), - }; - }); }; function TeamProfileView({ data, activities }) {