diff --git a/src/app/u/[handle]/creator/page.js b/src/app/u/[handle]/creator/page.js new file mode 100644 index 0000000..ce2605c --- /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 599195f..8591bff 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 9e2494d..df6d77f 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 && (