Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: skill refactor #152

Open
wants to merge 3 commits into
base: test
Choose a base branch
from
Open

Conversation

Coooder-Crypto
Copy link
Contributor

This pull request addresses the changes required for adapting the user-side skill-related code to the new directory structure and data request method as outlined in Issue #133

Copy link

vercel bot commented Mar 2, 2025

@Coooder-Crypto is attempting to deploy a commit to the OpenBuild Team on Vercel.

A member of the Team first needs to authorize it.

@ourai ourai self-requested a review March 7, 2025 21:21
@ourai ourai self-assigned this Mar 7, 2025
@ourai ourai added the enhancement New feature or request label Mar 7, 2025
@ourai ourai added this to the 2025W10 milestone Mar 7, 2025

import { baseInputStyles } from '#/domain/profile/widgets/blocks';
import { useConfig } from '#/state/application/hooks';
const selectedOptions = selectedSkills?.map(id =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selectedOptions 的长度跟 selectedSkills 是一样的,应该是过滤出符合要求的子集。下一行的用法也不对。

selectedOptions 重命名为 resolvedOptions 语义更准确


import { classNames, arrRemove } from '@/utils';
export default function SelectSkills({ selectedSkills, onChange, limit = Infinity, className = 'no-bg hauto' }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

组件名和文件名都重命名为 SkillSelect

这个组件实际上是个字段类的,这类组件代表值的属性统一用 value,也就是把 selectedSkills 改名,且在这里赋上默认值,下面代码中不需要做 fallback 处理。

加上 placeholder 属性,默认值为 'Select skills'

limit 不需要默认值,ReactSelect 中已经进行了处理。

className 不需要默认值,用的地方指定。

import { Transition } from '../control/headlessui';
import { CheckIcon, XMarkIcon } from '../icon/solid';
const handleChange = selectedOptions => {
const limitedOptions = selectedOptions.slice(0, limit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个逻辑多余吧?ReactSelect 如果传入 limit 属性,那么它返回的选项数量应该就是已经处理好的。

const handleChange = selectedOptions => {
const limitedOptions = selectedOptions.slice(0, limit);
const selectedIds = limitedOptions.map(option => option.value);
onChange(selectedIds);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接 onChange(selectedOptions.map(option => option.value)),并且要用 isFunction 判断 onChange 是否为一个函数

@@ -15,112 +15,32 @@
*/

'use client';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

去掉


import useMounted from '#/shared/hooks/useMounted';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'#/shared/hooks/useMounted' => '@/hooks/useMounted'

import SkillInsight from '../../widgets/skill-insight';
import SkillCircle from './SkillCircle';

function SkillOverviewView({ userId }) {
const skills = useAllSkills();
const { data } = useSWR(userId ? `ts/v1/hub/general/skills/${userId}` : null, fetcher);
const userSkills = data?.skill_datas || [];
const [data, setData] = useState([]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

从下面逻辑看,data 不是数组而是对象,这里改成 userSkillssetUserSkills;下面的请求那块就是 setUserSkills(res.data?.skill_datas || [])


import httpClient from '@/utils/http';

async function getUserSkills({ userId }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改为 fetchUserSkills(userId)

  • 远程获取数据时用 fetch 替代 get
  • 只有一个参数时不要用对象

import httpClient from '@/utils/http';

async function getUserSkills({ userId }) {
return await httpClient.get(`hub/general/skills/${userId}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. await 多余
  2. URL 前加上斜杠

))}
</div>
</div>
<SkillOverviewView userId={params.id} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不能直接用 SkillOverviewView,把它里面的下图部分代码拆成单独的 widget:

image

然后在 SkillOverviewView 和这里复用那个新 widget。

@ourai ourai modified the milestones: 2025W10, 2025W11 Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

用户侧技能相关代码适配新目录结构并采用新的数据请求方式
2 participants