Skip to content

Commit

Permalink
modals/UrlModal: reset clicked state on close
Browse files Browse the repository at this point in the history
  • Loading branch information
hom3mad3 committed Feb 12, 2025
1 parent 4e16f96 commit 48f1d94
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions adhocracy4/comments_async/static/modals/UrlModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ const translated = {
}

export const UrlModal = (props) => {
const [clicked, setClicked] = useState(false)
const [copied, setCopied] = useState(false)
const inputRef = useRef(null)

const copyUrl = (e) => {
e.preventDefault()
if (inputRef.current) {
navigator.clipboard.writeText(inputRef.current.value)
.then(() => {
setClicked(true)
setCopied(true)
return true
})
.catch((err) => {
Expand All @@ -27,6 +27,10 @@ export const UrlModal = (props) => {
}
}

const handleModalClose = () => {
setCopied(false)
}

const partials = {
hideHeader: true,
hideFooter: true,
Expand All @@ -43,11 +47,11 @@ export const UrlModal = (props) => {
/>
<button
className="a4-url-modal__button"
aria-pressed={clicked}
aria-pressed={copied}
autoComplete="off"
onClick={(e) => copyUrl(e)}
>
{clicked ? translated.buttonTextCopied : translated.buttonTextCopy}
{copied ? translated.buttonTextCopied : translated.buttonTextCopy}
</button>
</div>
)
Expand All @@ -59,6 +63,7 @@ export const UrlModal = (props) => {
partials={partials}
toggle={<><i className="fas fa-share" aria-hidden="true" /> {translated.share}</>}
keepOpenOnSubmit
onClose={handleModalClose}
/>
)
}

0 comments on commit 48f1d94

Please sign in to comment.