Skip to content

Commit

Permalink
fix(ranking): 周赛时会去替换错误图标
Browse files Browse the repository at this point in the history
  • Loading branch information
XYShaoKang committed Feb 8, 2023
1 parent 0e4f052 commit 80bdaee
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/content/pages/ranking/LanguageIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,17 @@ function setDisplay(el: Element | undefined, display: string) {
el.style.display = display
}
}

function isShow(parent: HTMLElement) {
if (!parent.childElementCount) return false
const [child] = parent.childNodes
return (
child instanceof HTMLAnchorElement &&
child.children[0] instanceof HTMLSpanElement
)
}
const LanguageIcon: FC<ItmeType> = ({ parent, row, col, hasMyRank }) => {
const [param] = useUrlChange()
const [show, setShow] = useState(!!parent.childElementCount)
const [show, setShow] = useState(isShow(parent))

const params: ParamType = { ...param }
if (hasMyRank) {
Expand All @@ -95,16 +102,20 @@ const LanguageIcon: FC<ItmeType> = ({ parent, row, col, hasMyRank }) => {
const iconFile = items?.[row]?.[col]?.iconFile

useEffect(() => {
if (!show) return
setDisplay(parent.children[0]?.children[0], 'none')

return () => {
setDisplay(parent.children[0]?.children[0], '')
}
}, [])
}, [show])
useEffect(() => {
const handleChange = debounce(() => {
setShow(!!parent.childElementCount)
setDisplay(parent.children[0]?.children[0], 'none')
const show = isShow(parent)
setShow(show)
if (show) {
setDisplay(parent.children[0]?.children[0], 'none')
}
}, 10)
handleChange()
const observer = new MutationObserver(handleChange)
Expand Down

0 comments on commit 80bdaee

Please sign in to comment.