@@ -2,20 +2,24 @@ import { Box, IconButton, InputBase, Paper } from "@mui/material";
22import { useTranslation } from "react-i18next" ;
33import classes from "./styles.module.scss" ;
44import { AddLink as AddLinkIcon } from "@mui/icons-material" ;
5- import { ChangeEvent , FormEvent , useState } from "react" ;
5+ import { ChangeEvent , FormEvent , useCallback , useRef , useState } from "react" ;
66import { Link as ShortLink } from "../../../common/data.types" ;
77import { linksRepository } from "../../../repositories" ;
8+ import CopyToClipboard from "react-copy-to-clipboard" ;
89
910type AddLinkProps = {
1011 onAdd : ( l : ShortLink ) => void
1112} ;
1213
1314const AddLink :React . FC < AddLinkProps > = ( { onAdd} ) => {
1415 const [ url , setURL ] = useState ( "" ) ;
16+ const [ shortURL , setShortURL ] = useState < string > ( "" ) ;
1517 const [ isValid , setIsValid ] = useState ( false ) ;
1618 const [ isLoading , setIsLoading ] = useState ( false ) ;
1719 const { t} = useTranslation ( ) ;
1820
21+ const shortRef = useRef < any > ( ) ;
22+
1923 const handleChangeUrl = ( e :ChangeEvent < HTMLInputElement > ) => {
2024 setURL ( e . target . value ) ;
2125 setIsValid ( e . target . validity . valid ) ;
@@ -26,7 +30,9 @@ const AddLink:React.FC<AddLinkProps> = ({onAdd}) => {
2630
2731 setIsLoading ( true ) ;
2832
29- const link = await linksRepository . add ( { link : url } ) ;
33+ const link = await linksRepository . add ( { link : url . trim ( ) } ) ;
34+ setShortURL ( link . short_url ) ;
35+
3036 onAdd ( link ) ;
3137
3238 setURL ( "" ) ;
0 commit comments