@@ -2,20 +2,24 @@ import { Box, IconButton, InputBase, Paper } from "@mui/material";
2
2
import { useTranslation } from "react-i18next" ;
3
3
import classes from "./styles.module.scss" ;
4
4
import { AddLink as AddLinkIcon } from "@mui/icons-material" ;
5
- import { ChangeEvent , FormEvent , useState } from "react" ;
5
+ import { ChangeEvent , FormEvent , useCallback , useRef , useState } from "react" ;
6
6
import { Link as ShortLink } from "../../../common/data.types" ;
7
7
import { linksRepository } from "../../../repositories" ;
8
+ import CopyToClipboard from "react-copy-to-clipboard" ;
8
9
9
10
type AddLinkProps = {
10
11
onAdd : ( l : ShortLink ) => void
11
12
} ;
12
13
13
14
const AddLink :React . FC < AddLinkProps > = ( { onAdd} ) => {
14
15
const [ url , setURL ] = useState ( "" ) ;
16
+ const [ shortURL , setShortURL ] = useState < string > ( "" ) ;
15
17
const [ isValid , setIsValid ] = useState ( false ) ;
16
18
const [ isLoading , setIsLoading ] = useState ( false ) ;
17
19
const { t} = useTranslation ( ) ;
18
20
21
+ const shortRef = useRef < any > ( ) ;
22
+
19
23
const handleChangeUrl = ( e :ChangeEvent < HTMLInputElement > ) => {
20
24
setURL ( e . target . value ) ;
21
25
setIsValid ( e . target . validity . valid ) ;
@@ -26,7 +30,9 @@ const AddLink:React.FC<AddLinkProps> = ({onAdd}) => {
26
30
27
31
setIsLoading ( true ) ;
28
32
29
- const link = await linksRepository . add ( { link : url } ) ;
33
+ const link = await linksRepository . add ( { link : url . trim ( ) } ) ;
34
+ setShortURL ( link . short_url ) ;
35
+
30
36
onAdd ( link ) ;
31
37
32
38
setURL ( "" ) ;
0 commit comments