diff --git a/README.md b/README.md index bc41976..20bdb15 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ Your web browser should open on `http://localhost:3000`. The app is configured t - [x] allow user to set the public url for shortened content - [x] move from sqlite3 to modernc.org/sqlite to compile without CGO (and use scratch, lighter image) - [x] display status with version +- [ ] reduce duplicate code to display links - [ ] allow user to change language - [ ] add all options in front when create a new text - [ ] error handling (on add and delete) diff --git a/front/src/pages/files/files_list_item/index.tsx b/front/src/pages/files/files_list_item/index.tsx index a4b023b..74bc53c 100644 --- a/front/src/pages/files/files_list_item/index.tsx +++ b/front/src/pages/files/files_list_item/index.tsx @@ -38,7 +38,7 @@ const TextsListItem:React.FC = ({file, onDelete, onShortened - + diff --git a/front/src/pages/files/index.tsx b/front/src/pages/files/index.tsx index f3ddf23..7410206 100644 --- a/front/src/pages/files/index.tsx +++ b/front/src/pages/files/index.tsx @@ -23,8 +23,6 @@ const Links:React.FC = () => { const handleFileAdded = (f:ShortFile) => { setFiles({...files, [f.id]: f}); - copy(f.short_url); - setDisplayCopySnack(true); }; const handleFileDeleted = (id:string) => { diff --git a/front/src/pages/links/add_link/index.tsx b/front/src/pages/links/add_link/index.tsx index 045f4f1..5a85dea 100644 --- a/front/src/pages/links/add_link/index.tsx +++ b/front/src/pages/links/add_link/index.tsx @@ -2,9 +2,10 @@ import { Box, IconButton, InputBase, Paper } from "@mui/material"; import { useTranslation } from "react-i18next"; import classes from "./styles.module.scss"; import {AddLink as AddLinkIcon} from "@mui/icons-material"; -import { ChangeEvent, FormEvent, useState } from "react"; +import { ChangeEvent, FormEvent, useCallback, useRef, useState } from "react"; import { Link as ShortLink } from "../../../common/data.types"; import { linksRepository } from "../../../repositories"; +import CopyToClipboard from "react-copy-to-clipboard"; type AddLinkProps = { onAdd: (l: ShortLink) => void @@ -12,10 +13,13 @@ type AddLinkProps = { const AddLink:React.FC = ({onAdd}) => { const [url, setURL] = useState(""); + const [shortURL, setShortURL] = useState(""); const [isValid, setIsValid] = useState(false); const [isLoading, setIsLoading] = useState(false); const {t} = useTranslation(); + const shortRef = useRef(); + const handleChangeUrl = (e:ChangeEvent) => { setURL(e.target.value); setIsValid(e.target.validity.valid); @@ -26,7 +30,9 @@ const AddLink:React.FC = ({onAdd}) => { setIsLoading(true); - const link = await linksRepository.add({link: url}); + const link = await linksRepository.add({link: url.trim()}); + setShortURL(link.short_url); + onAdd(link); setURL(""); diff --git a/front/src/pages/links/index.tsx b/front/src/pages/links/index.tsx index bd8c6b8..6aec3bf 100644 --- a/front/src/pages/links/index.tsx +++ b/front/src/pages/links/index.tsx @@ -23,8 +23,6 @@ const Links:React.FC = () => { const handleLinkAdded = (l:ShortLink) => { setLinks({...links, [l.id]: l}); - copy(l.short_url); - setDisplayCopySnack(true); }; const handleLinkDeleted = (id:string) => { diff --git a/front/src/pages/links/links_list_item/index.tsx b/front/src/pages/links/links_list_item/index.tsx index 32c3f83..b2219e0 100644 --- a/front/src/pages/links/links_list_item/index.tsx +++ b/front/src/pages/links/links_list_item/index.tsx @@ -38,7 +38,7 @@ const LinksListItem:React.FC = ({link, onDelete, onShortened - + diff --git a/front/src/pages/texts/index.tsx b/front/src/pages/texts/index.tsx index 77c8a2c..5ac785a 100644 --- a/front/src/pages/texts/index.tsx +++ b/front/src/pages/texts/index.tsx @@ -23,8 +23,6 @@ const Links:React.FC = () => { const handleTextAdded = (t:ShortText) => { setTexts({...texts, [t.id]: t}); - copy(t.short_url); - setDisplayCopySnack(true); }; const handleTextDeleted = (id:string) => { diff --git a/front/src/pages/texts/texts_list_item/index.tsx b/front/src/pages/texts/texts_list_item/index.tsx index 48442e1..a176bb3 100644 --- a/front/src/pages/texts/texts_list_item/index.tsx +++ b/front/src/pages/texts/texts_list_item/index.tsx @@ -38,7 +38,7 @@ const TextsListItem:React.FC = ({text, onDelete, onShortened - +