Skip to content

Commit

Permalink
fixed modal selected element
Browse files Browse the repository at this point in the history
  • Loading branch information
LiveDuo committed Mar 27, 2024
1 parent 7964499 commit 6603479
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/client/vanilla/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Dialog: React.FC<DialogProps> = ({ open, setOpen, selectedElement, baseUrl

useEffect(() => {
setUrl(selectedElement?.getAttribute('src') ?? '')
}, [open])
}, [selectedElement])

const onUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
e.preventDefault()
Expand Down
16 changes: 13 additions & 3 deletions lib/client/vanilla/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@ const Dialog: React.FC<DialogProps> = ({ open, setOpen, selectedElement }) => {
const [newTab, setNewTab] = useState(true)

useEffect(() => {
setLink(selectedElement?.href ?? '')
}, [open])
if (selectedElement) {
const url = new URL(selectedElement.href)
const linkNew = url.hostname === 'localhost' ? url.pathname.replace('/', '') + url.hash : selectedElement.href
setLink(linkNew)
console.log('changed', linkNew)
} else {
console.log('changed', null)

setLink('')
}
}, [selectedElement])

const onSave = () => {
setOpen(false)
setLink('')

selectedElement.href = link
selectedElement.target = newTab ? '_blank' : '_self'
Expand All @@ -48,7 +58,7 @@ const Dialog: React.FC<DialogProps> = ({ open, setOpen, selectedElement }) => {
type="text"
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg block w-full p-2.5 mb-4"
placeholder="Eg. https://github.com/LiveDuo/destack"
defaultValue={link as string}
value={link as string}
onChange={(e) => setLink(e.target.value)}
/>
<div className="flex items-center ml-4">
Expand Down
4 changes: 2 additions & 2 deletions lib/client/vanilla/svg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Dialog: React.FC<DialogProps> = ({ open, setOpen, selectedElement }) => {
const [path, setPath] = useState('')

useEffect(() => {
if (open) {
if (selectedElement) {
if (selectedElement.tagName === 'path') {
setPath(selectedElement?.getAttribute('d') ?? '')
} else if (selectedElement.tagName === 'svg') {
Expand All @@ -28,7 +28,7 @@ const Dialog: React.FC<DialogProps> = ({ open, setOpen, selectedElement }) => {
} else {
setPath('')
}
}, [open])
}, [selectedElement])

const onSave = () => {
setOpen(false)
Expand Down

0 comments on commit 6603479

Please sign in to comment.