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(website): wiki/edit_detail #312

Merged
merged 62 commits into from
Jan 27, 2023
Merged

Conversation

FoundTheWOUT
Copy link
Contributor

@FoundTheWOUT FoundTheWOUT commented Jan 11, 2023

做得差不多了,各位大大可以点 https://pr-312-sites--bangumi-next.netlify.app/subject/363612/wiki/edit_detail 多测试测试哈,改动有点大 bgm38

ref #53

新增

  1. 新增 Radio 组件
  2. 新增 Select 组件
  3. 新增 Input.Group 组件
  4. 新增 Form 组件,只封装了样式,逻辑在 website 使用 react-hook-form 实现
  5. 新增 404 页面

修改

  1. Input 组件样式
  2. Nav 组件拆分成 Nav.GroupNav.ItemNav 保留原来的用法,只是现在可以更灵活的控制 active
  3. 关闭了 StrictMode,这功能会导致开发阶段 react-beadutify-dnd 异常

TODO

  • 切换类型时切换模板
  • 有的 subject 没有类型选择
  • from/toWikiElement 单元测试
  • 记忆入门模式和高级模式
  • 编辑权限问题
  • 路径错误 navigate 404
  • 当项键/值为空时按退格键删除该项
  • 禁用回车自动提交表单
  • 切换为二级项目时,把当前项目的值作为二级项目的初始值
  • Tab 快捷键问题
  • 移动端点击优化

一些问题

  • 确认下工作量,我这个 PR 是只做原站的 /subject/xx/edit_detail 页面吗。还是说把整个 wiki 编辑的所有页面都做了 @trim21
  • 路由是必须按照原站的写吗,原站的一些路由有些问题,比如 /subject/xx/edit 是历史记录等等。另外,由于 wiki 页面的路由和 subject 页面的路由混在一起了,也导致一些组件复用问题。如果不需要百分百复刻原站的话,使用 /subject/xxx/wiki/xxx 可能更好

@trim21
Copy link
Contributor

trim21 commented Jan 11, 2023

确认下工作量,我这个 PR 是只做原站的 /subject/xx/edit_detail 页面吗。还是说把整个 wiki 编辑的所有页面都做了

我觉得一个页面一个PR比较好,而且关联 投票啥的API都还没做…

路由是必须按照原站的写吗,原站的一些路由有些问题,比如 /subject/xx/edit 是历史记录等等。另外,由于 wiki 页面的路由和 subject 页面的路由混在一起了,也导致一些组件复用问题。如果不需要百分百复刻原站的话,使用 /subject/xxx/wiki/xxx 可能更好

不用完全复刻

@FoundTheWOUT FoundTheWOUT changed the title feat(website): wiki feat(website): wiki/edit_tail Jan 11, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jan 11, 2023

@trim21
Copy link
Contributor

trim21 commented Jan 11, 2023

Select 组件尚未设计

这里的 select 有设计吧?

@FoundTheWOUT
Copy link
Contributor Author

这里的 select 有设计吧?

你是指 Header 那个吗,那个只是导航栏是这样吧,通用的 Select 也按照那个吗

@trim21
Copy link
Contributor

trim21 commented Jan 11, 2023

不对,我傻了,把select和radio弄混了

那这里也 @vistaing

@vistaing
Copy link

这里的 select 有设计吧?

你是指 Header 那个吗,那个只是导航栏是这样吧,通用的 Select 也按照那个吗

目前建议先使用浏览器默认样式,若后续确有需要,再参照 Header 的 hover 菜单来设计一个,我个人是觉得浏览器默认的样式差不多够用

packages/utils/wiki.ts Outdated Show resolved Hide resolved
@trim21
Copy link
Contributor

trim21 commented Jan 14, 2023

还有个功能,如果觉得麻烦留成TODO也可以

  • 记忆入门模式和高级模式,如果用户切换到高级模式,下次进入编辑页面默认使用高级模式打开

@@ -2,6 +2,8 @@

@primary-color: #f09199;

@bg-gray-10: #fcfcfc;
Copy link
Contributor

Choose a reason for hiding this comment

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

这是设计稿里给的名字吗?我看给的是

Screenshot 2023-01-23 at 23 53 22

Copy link
Contributor Author

@FoundTheWOUT FoundTheWOUT Jan 24, 2023

Choose a reason for hiding this comment

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

我看错了,感觉有点迷,这里background好像没有色系,cc @vistaing
图里的是子项目输入框
image

packages/website/src/components/ErrorBoundary.tsx Outdated Show resolved Hide resolved
packages/website/src/components/Header/style.module.less Outdated Show resolved Hide resolved
packages/website/src/components/WikiEditor/WikiEditor.tsx Outdated Show resolved Hide resolved
packages/website/src/components/WikiEditor/WikiEditor.tsx Outdated Show resolved Hide resolved
2. remove wikItem when key ctrl+x|X down
3. use class instead of inline style
Comment on lines +519 to +543
<div
className={style.Tips}
style={{ display: editorType === EditorType.Beginner ? 'block' : 'none' }}
>
<div>Tips:</div>
<div>可拖拽改变行顺序</div>
<div>
按<kbd>Ctrl</kbd>+<kbd>Enter</kbd>切换为二级项目
</div>
<div>
按<kbd>Ctrl</kbd>+<kbd>X</kbd>可删除项目
</div>
</div>

{/* 入门编辑模式 */}
<div hidden={editorType !== EditorType.Beginner}>
<WikiInfoContext.Provider
value={{
els: wikiElement,
addOneWikiElement,
removeOneWikiElement,
editOneWikiElement,
switchWikiElementToArray,
}}
>
Copy link
Contributor

Choose a reason for hiding this comment

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

{editorType === EditorType.Biginner && <>{// 里面的内容 }</>}

直接不渲染,不用 display: none 可以吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

当时是想有可能切换得比较频繁,但具体我也不清楚维基人的日常操作(,如果切换得比较少,可以直接不渲染。

wikiRef.current = parseWiki(subjectWikiInfo.infobox);
monoEditorInstanceRef.current?.setValue(subjectWikiInfo.infobox);
setWikiElement(toWikiElement(wikiRef.current));
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

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

lint 的 deps 补一下吧

Copy link
Contributor Author

@FoundTheWOUT FoundTheWOUT Jan 25, 2023

Choose a reason for hiding this comment

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

这个 effect 只有第一次跑,如果 subjectWikiInfo.infobox (api 来的数据) 变了也不应该重新跑的吧,感觉涉及到编辑冲突的一些问题。另外就是 WikiEditor 那边的 effect 也是,编辑器应该实例化一次就好了,defaultValue 只影响初始状态,如果 defaultValue 变了不应该重新实例化编辑器,应该是没反应。若需要修改编辑器的值,应该通过 api,而不是更新 defaultValue。

Copy link
Contributor

@Ayase-252 Ayase-252 Jan 25, 2023

Choose a reason for hiding this comment

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

不会多次请求 subjectWikiInfo 吧?对于接口请求这类,请求之前是个 undefined,请求后才有数据是很常见的场合

Copy link
Contributor Author

Choose a reason for hiding this comment

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

确实不会,只是想表达这个 effect 应该只运行一次,无论什么情况 re-render,都不应该重新跑(

if (isEmpty(el.value) && isEmpty(el.key)) continue;
const value = el.value;
const initWikiItemValue = typeof value === 'string' ? value : '';
const item = new WikiItem(el.key ?? '', initWikiItemValue, 'object');
Copy link
Contributor

Choose a reason for hiding this comment

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

value 是数组的时候,可以用 WikiItem 的 type 参数吧?手动写 item.array 有点依赖 wiki-parser 的内部实现了?

Copy link
Contributor

Choose a reason for hiding this comment

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

wiki-parser也是我们写的,需要的话可以改…(

Copy link
Contributor

Choose a reason for hiding this comment

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

写成现在这个样主要为了照顾静态语言的JSON序列化和反序列化…

Copy link
Contributor

@Ayase-252 Ayase-252 Jan 25, 2023

Choose a reason for hiding this comment

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

我在想有没有可能这里写成 const item = isArray(values) ? new WikiItem(..,.., 'array') : new WikiItem(..,.., 'object')... 如果上游能够分开最好(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我在想有没有可能这里写成 const item = isArray(values) ? new WikiItem(..,.., 'array') : new WikiItem(..,.., 'object')...

不太行,WikiItem 构造函数签名问题。估计 server 那边也有依赖 wiki-parser 吧。

写成现在这个样主要为了照顾静态语言的JSON序列化和反序列化…

没有太理解这个🤔,静态语言是指?

Copy link
Contributor

Choose a reason for hiding this comment

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

这是按着之前go版本的写的(

packages/utils/wiki.ts Outdated Show resolved Hide resolved
packages/utils/wiki.ts Outdated Show resolved Hide resolved
@trim21
Copy link
Contributor

trim21 commented Jan 25, 2023

Screenshot_2023-01-25-20-01-13-562_com brave browser-edit

这种转高级模式的时候是不是考虑合并一下?

@trim21
Copy link
Contributor

trim21 commented Jan 25, 2023

还是先保持原样吧,后面再说了(


export const WikiEditTabsItemsByKey = keyBy(WikiEditTabsItems, 'key');

export const getWikiTemplate = (subjectType: number, targetTemplate: string | undefined) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

这个函数能注释下吗?targetTemplate 是干啥的?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

不知道有没有写清楚,写得稍微有点绕。

Copy link
Contributor

@Ayase-252 Ayase-252 left a comment

Choose a reason for hiding this comment

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

上面的注释后没啥问题了

@trim21 trim21 merged commit 3c3fd34 into bangumi:master Jan 27, 2023
@FoundTheWOUT FoundTheWOUT deleted the wiki-edit branch January 28, 2023 08:45
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants