mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: prevent duplicated copy file buttons
This commit is contained in:
parent
4b96e01845
commit
48d2053851
2 changed files with 11 additions and 7 deletions
|
|
@ -43,7 +43,7 @@ export function CopyFileButton(props: React.PropsWithChildren<Props>) {
|
|||
}, [])
|
||||
|
||||
return (
|
||||
<a ref={elementRef} className={cx('btn btn-sm BtnGroup-item copy-file-btn', className)}>
|
||||
<a ref={elementRef} className={cx('btn btn-sm BtnGroup-item', className)}>
|
||||
{content}
|
||||
</a>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -139,6 +139,13 @@ export function getCodeElement() {
|
|||
* click these buttons will copy file content to clipboard
|
||||
*/
|
||||
export function attachCopyFileBtn() {
|
||||
const removeButtons = () => {
|
||||
const buttons = document.querySelectorAll(`.${copyFileButtonClassName}`)
|
||||
buttons.forEach(button => {
|
||||
button.parentElement?.removeChild(button)
|
||||
})
|
||||
}
|
||||
|
||||
if (getCurrentPageType() === PAGE_TYPES.RAW_TEXT) {
|
||||
// the button group in file content header
|
||||
const buttonGroupSelector = '.repository-content .Box-header .BtnGroup'
|
||||
|
|
@ -148,6 +155,8 @@ export function attachCopyFileBtn() {
|
|||
raiseError(new Error(`No button groups found`))
|
||||
}
|
||||
|
||||
removeButtons() // prevent duplicated buttons
|
||||
|
||||
buttonGroups.forEach(async buttonGroup => {
|
||||
if (!buttonGroup.lastElementChild) return
|
||||
const button = await renderReact(React.createElement(CopyFileButton))
|
||||
|
|
@ -158,12 +167,7 @@ export function attachCopyFileBtn() {
|
|||
}
|
||||
|
||||
// return callback so that disabling after redirecting from file page to non-page works properly
|
||||
return () => {
|
||||
const buttons = document.querySelectorAll(`.${copyFileButtonClassName}`)
|
||||
buttons.forEach(button => {
|
||||
button.parentElement?.removeChild(button)
|
||||
})
|
||||
}
|
||||
return removeButtons
|
||||
}
|
||||
|
||||
export function attachCopySnippet() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue