Skip to content

Commit

Permalink
feat: Add copy URL functionality to GraphGenerator component
Browse files Browse the repository at this point in the history
  • Loading branch information
PikiLee committed Aug 17, 2024
1 parent 6ecddc4 commit b8eee29
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions components/GraphGenerator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { useForm } from 'react-hook-form'
import { Image, Tooltip } from '@nextui-org/react'
import { LuImagePlus } from 'react-icons/lu'
import { useEffect, useState } from 'react'
import { IoCopyOutline } from 'react-icons/io5'
import AppCheckBox from './AppCheckBox'
import GraphColorSelector from './GraphColorSelector'
import AppButton from './AppButton'
import { toast } from './ui/use-toast'
import type { Tone } from '~/utils/colors'

interface Form {
Expand Down Expand Up @@ -39,10 +41,12 @@ export default function GraphGenerator() {
setImageURL(url.toString())
}

useEffect(() => {
const url = new URL(`/v2/username/PikiLee`, window.location.origin)
setImageURL(url.toString())
}, [])
function copyURL() {
navigator.clipboard.writeText(imageURL)
toast({
title: 'The URL has been copied to your clipboard.',
})
}

return (
<div className="relative overflow-hidden">
Expand Down Expand Up @@ -77,6 +81,11 @@ export default function GraphGenerator() {
<Tooltip content="Generate">
<AppButton type="submit" isLoading={isLoading}><LuImagePlus size={24} /></AppButton>
</Tooltip>
{imageURL && (
<Tooltip content="Copy URL">
<AppButton type="button" onClick={copyURL}><IoCopyOutline size={24} /></AppButton>
</Tooltip>
)}
</div>
</div>
</form>
Expand Down

0 comments on commit b8eee29

Please sign in to comment.