-
Notifications
You must be signed in to change notification settings - Fork 32
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
base: test
Are you sure you want to change the base?
feat: skill refactor #152
Conversation
@Coooder-Crypto is attempting to deploy a commit to the OpenBuild Team on Vercel. A member of the Team first needs to authorize it. |
|
||
import { baseInputStyles } from '#/domain/profile/widgets/blocks'; | ||
import { useConfig } from '#/state/application/hooks'; | ||
const selectedOptions = selectedSkills?.map(id => |
There was a problem hiding this comment.
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' }) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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([]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
从下面逻辑看,data
不是数组而是对象,这里改成 userSkills
和 setUserSkills
;下面的请求那块就是 setUserSkills(res.data?.skill_datas || [])
|
||
import httpClient from '@/utils/http'; | ||
|
||
async function getUserSkills({ userId }) { |
There was a problem hiding this comment.
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}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await
多余- URL 前加上斜杠
))} | ||
</div> | ||
</div> | ||
<SkillOverviewView userId={params.id} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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