-
Notifications
You must be signed in to change notification settings - Fork 7
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: add package of text-selector #171
Conversation
packages/text-selector/package.json
Outdated
"react-dom": "^18.1.0", | ||
"serialize-javascript": "^6.0.0", | ||
"styled-components": "5.3.5", | ||
"uuid": "^8.3.2" |
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.
dependency 需要調整一下。
可以參考其他 pkg 的寫法。
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.
已於 2abcaad 修改。
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.
nitpick:
styled-components
忘記移除了?
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.
question:
uuid
是忘記移除嗎?
還是我們程式碼哪裡有用到 uuid
?
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.
感謝提醒,已於 994c2c7 修改。
packages/text-selector/yarn.lock
Outdated
@@ -0,0 +1,2281 @@ | |||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. |
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.
text-selector 屬於 monorepo 的管理範圍,所以我們只需要保留 root 的 yarn.lock,不需要有 subpkg 的 yarn.lock。
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.
已於 2abcaad 修改,感謝提醒!
想請教 @nickhsine 一個 bug: |
package.json
Outdated
@@ -12,6 +12,7 @@ | |||
"packages/share-button", | |||
"packages/three-story-points", | |||
"packages/dual-slides", | |||
"packages/text-selector" |
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.
少了逗點
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.
請問是指後面的逗號嗎?我的 Prettier 好像會自動拿掉,這個會有影響嗎?
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.
沒事,不用理會這個訊息。目前的版本是對的。
package.json
Outdated
@@ -12,6 +12,7 @@ | |||
"packages/share-button", | |||
"packages/three-story-points", | |||
"packages/dual-slides", | |||
"packages/text-selector" |
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.
沒事,不用理會這個訊息。目前的版本是對的。
packages/text-selector/README.md
Outdated
@@ -0,0 +1,46 @@ | |||
# [@readr-media/text-selector](https://www.npmjs.com/package/@readr-media/text-selector) · ![npm version](https://img.shields.io/npm/v/@readr-media/react-karaoke.svg?style=flat) |
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.
question:
是不是要 follow convention,把 text-selector
改成 react-text-selector
呢?
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.
另外,有空的話,是不是補個 demo 的影片/gif 呢?
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.
好哇,是不是可以順便補上 props 建議使用方法,還是 jsDoc 都會 cover 這部分?
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.
好像可以補上怎麼使用 TextSelector
component ?
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.
已於 b840ddc 修改,再麻煩幫忙看看,感謝!
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.
是想說要不要統一 pkg 命名的方式,在前方加上 react-
prefix?
packages/text-selector/package.json
Outdated
"react-dom": "^18.1.0", | ||
"serialize-javascript": "^6.0.0", | ||
"styled-components": "5.3.5", | ||
"uuid": "^8.3.2" |
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.
nitpick:
styled-components
忘記移除了?
}) | ||
} | ||
// Add event listener | ||
window.addEventListener('resize', handleResize) |
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.
suggestion:
handleResize
看要不要用 throttle 降低被觸發的頻率?
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.
對齁,感謝提醒,已於 6f8711b 修改。
version "1.1.5" | ||
resolved "https://registry.yarnpkg.com/default-import/-/default-import-1.1.5.tgz#6ba81645f79fa2e122bbac09651f30b55a8d9d5d" | ||
integrity sha512-aaJ6uzZlmaEcN1U8yvtiyV7MG3/zZQf1XtGSW5dTfAVvfk0VZuriJelXxVL9a0ni42vMkhjWcztFfpIhwFcfOQ== | ||
|
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.
nitpick:
麻煩確認一下 default-import 是哪裡來的?
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.
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.
</ControllerBtn> | ||
)} | ||
{jsonFileIndex < jsonLength - 1 && ( | ||
<ControllerBtn onClick={() => setJsonFileIndex((prev) => prev + 1)}> |
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.
question:
可否直接寫成 setJsonFileIndex(prev+1)
就好?
想請問這邊用 updater function 有什麼特殊用意嗎?
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.
這裡應該沒有 prev
的 variable,所以是指直接寫 setJsonFileIndex(jsonFileIndex+1)
嗎?
我自己的理解是因為 useState
是非同步的,為了防止真的重新更新 state 之前,使用者又重複點擊,才會用 function 確保真的是拿到已經改變過後的值。
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.
這邊應該是寫 setJsonFileIndex(jsonFileIndex+1)
就好?
如果你想要在一個 click 中,連續 +1 兩次的話,
就要改用 setJsonFileIndex((prev) => prev + 1)
,
但是我們目前應該沒有這個需求。
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.
了解,感謝說明,已於 6f8711b 修改。
/** | ||
* @param {Object} opts | ||
* @param {string} [opts.className] | ||
* @param {string[]} [opts.jsonUrls] |
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.
nitpick:
有default value 的話,麻煩也加在 JSDoc 中
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.
感謝提醒,已於 a8a8c43 修改。
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.
const renderedData = useMemo(() => { | ||
const returnArr = [] | ||
data.forEach((item) => { | ||
console.log(item) |
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.
nitpick:
console.log
記得移除?
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.
感謝提醒,已於 994c2c7 修改。
width: calc(100vw - 40px); | ||
padding-inline-start: 20px; | ||
max-width: 712px; | ||
font-family: 'Noto Sans TC'; |
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.
suggestion:
字型可以考慮使用 inherit ,讓使用 embed code 的 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.
感謝提醒,已於 05842ac 修改。
// mounted 後,才變動 highlightIndex | ||
useEffect(() => { | ||
setHighlightIndex(0) | ||
}, []) |
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.
question:
想知道為何要 mounted 後才把 highlightIndex
設定成 0
?
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.
因為遇到太多 render 完後第一則的位置跑掉的問題,想說這樣改會不會一勞永逸或多加一層保險(?)不過確實不太直覺?
setHighlightIndex((prev) => prev + 1) | ||
if (highlightIndex > dataLength - 2) { | ||
setHighlightIndex(1) | ||
} |
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.
question:
這邊邏輯是不是要改成
if (highlightIndex > dataLength - 2) {
setHighlightIndex(1)
} else {
setHighlightIndex(highlightIndex + 1)
}
?
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.
感謝提醒,已於 fdc370b 修正。
return { | ||
content: item, | ||
order, | ||
} |
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.
nitpick:
fetchData
function 這段可以加註解嗎?
有點不是很懂資料處理的邏輯。
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.
確實有點複雜,我先在 e837d5e 試寫一版,再麻煩幫忙看看,感謝🙏
這部分是參考 nick 之前 tsp 改寫的,目前加上 2023/5/10 更新 |
nowHeight < prevHeight * 0.6 || | ||
nowHeight === prevHeight | ||
) { | ||
prevHeight = window.innerHeight |
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.
question:
prevHeight
和 windowSize.height
有什麼不同嗎?
if ( | ||
nowHeight > prevHeight * 1.4 || | ||
nowHeight < prevHeight * 0.6 || | ||
nowHeight === prevHeight |
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.
question:
為何要特別判斷 nowHeight === prevHeight
?
如果兩個相等,不是代表不需要處理 resize 嗎?
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.
因為 resize 是偵測長寬,如果等於的話就表示其實變動的是螢幕寬,因此還是要處理。
關於偵測螢幕尺寸的 hooks,因為有一些預料之外的行為(像是 safari 和 in-app 的工具列出現離開都會導致畫面閃現),考慮後已於 814100e 拔除。
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.
LGTM 👍
BTW, 如果可以的話,請 build 出 cjs 和 esm 的版本。
可以參考 0d2f4eb
描述
Demo
待優化處
EmpasizedCircle
也抓不到新的translateToParagraph
。