Skip to content

Commit

Permalink
Fix dumb clipboard bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zaydek committed Jan 12, 2023
1 parent d3bfab8 commit 0a874f0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/contents-sidebar-2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ function SectionClipboard() {
}
<TextareaButton
icon={DocumentDuplicateIcon}
onClick={e => {
if (clipboard === "") { return }
navigator.clipboard.writeText(clipboard)
}}
//// onClick={e => {
//// if (clipboard === "") { return }
//// navigator.clipboard.writeText(clipboard)
//// }}
>
COPY
</TextareaButton>
Expand Down
52 changes: 34 additions & 18 deletions src/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ export function StateProvider({ children }: PropsWithChildren) {
setSearch,
resetAll: resetAllSearch,
}), [resetAllSearch])}>
<RestoreSelectedSvgElementEffect />
<ClipboardEffect />
{/* <RestoreSelectedSvgElementEffect /> */}
<VisibilityChangeEffect />
<CastSizeAndStrokeWidthAsCSSVariablesEffect />
<URLSearchParamsEffect />
Expand All @@ -250,31 +251,46 @@ export function StateProvider({ children }: PropsWithChildren) {
</>
}

function RestoreSelectedSvgElementEffect() {
function ClipboardEffect() {
const searchConfig = useContext(SearchConfigContext)!
const setSearchConfig = useContext(SetSearchConfigContext)!
const search = useContext(SearchContext)!

const prevIconset = useRef(search.iconset)
const onceRef = useRef(false)
useEffect(() => {
queueMicrotask(() => prevIconset.current = search.iconset)

if (searchConfig.selectedName === "") { return }
if (prevIconset.current.slice(0, 2) === search.iconset.slice(0, 2)) {
const svgElement = document
?.getElementById(searchConfig.selectedName)
?.querySelector("svg")
if (svgElement === undefined || svgElement === null) { return }
setSearchConfig.setSelectedSvgElement(svgElement)
} else {
setSearchConfig.setSelectedName("")
setSearchConfig.setSelectedSvgElement(null)
if (!onceRef.current) {
onceRef.current = true
return
}
}, [search.iconset, searchConfig.selectedName, setSearchConfig])
navigator.clipboard.writeText(searchConfig.clipboard)
}, [searchConfig.clipboard])

return <></>
}

//// function RestoreSelectedSvgElementEffect() {
//// const searchConfig = useContext(SearchConfigContext)!
//// const setSearchConfig = useContext(SetSearchConfigContext)!
//// const search = useContext(SearchContext)!
////
//// const prevIconset = useRef(search.iconset)
//// useEffect(() => {
//// queueMicrotask(() => prevIconset.current = search.iconset)
////
//// if (searchConfig.selectedName === "") { return }
//// if (prevIconset.current.slice(0, 2) === search.iconset.slice(0, 2)) {
//// const svgElement = document
//// ?.getElementById(searchConfig.selectedName)
//// ?.querySelector("svg")
//// if (svgElement === undefined || svgElement === null) { return }
//// setSearchConfig.setSelectedSvgElement(svgElement)
//// } else {
//// setSearchConfig.setSelectedName("")
//// setSearchConfig.setSelectedSvgElement(null)
//// }
//// }, [search.iconset, searchConfig.selectedName, setSearchConfig])
////
//// return <></>
//// }

function VisibilityChangeEffect() {
const search = useContext(SearchContext)!

Expand Down

0 comments on commit 0a874f0

Please sign in to comment.