Skip to content

Commit 86d8082

Browse files
authored
feat(links): do not copy shorten link by default (#8)
1 parent a389940 commit 86d8082

File tree

8 files changed

+12
-11
lines changed

8 files changed

+12
-11
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Your web browser should open on `http://localhost:3000`. The app is configured t
142142
- [x] allow user to set the public url for shortened content
143143
- [x] move from sqlite3 to modernc.org/sqlite to compile without CGO (and use scratch, lighter image)
144144
- [x] display status with version
145+
- [ ] reduce duplicate code to display links
145146
- [ ] allow user to change language
146147
- [ ] add all options in front when create a new text
147148
- [ ] error handling (on add and delete)

front/src/pages/files/files_list_item/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const TextsListItem:React.FC<TextsListItemProps> = ({file, onDelete, onShortened
3838
<Grid alignItems="center" container direction="row" flexWrap="nowrap">
3939
<Grid className={classes.primary_info} container direction="column">
4040
<Grid>
41-
<CopyToClipboard text={file.short_url} onCopy={onShortenedURLCopied}>
41+
<CopyToClipboard text={file.short_url} onCopy={onShortenedURLCopied} options={{format: "text/plain"}}>
4242
<IconButton className={classes.copy_button} aria-label={t("files.copy_button_aria_label")} disabled={isDisabled}>
4343
<ContentCopyIcon />
4444
</IconButton>

front/src/pages/files/index.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ const Links:React.FC = () => {
2323

2424
const handleFileAdded = (f:ShortFile) => {
2525
setFiles({...files, [f.id]: f});
26-
copy(f.short_url);
27-
setDisplayCopySnack(true);
2826
};
2927

3028
const handleFileDeleted = (id:string) => {

front/src/pages/links/add_link/index.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@ import { Box, IconButton, InputBase, Paper } from "@mui/material";
22
import { useTranslation } from "react-i18next";
33
import classes from "./styles.module.scss";
44
import {AddLink as AddLinkIcon} from "@mui/icons-material";
5-
import { ChangeEvent, FormEvent, useState } from "react";
5+
import { ChangeEvent, FormEvent, useCallback, useRef, useState } from "react";
66
import { Link as ShortLink } from "../../../common/data.types";
77
import { linksRepository } from "../../../repositories";
8+
import CopyToClipboard from "react-copy-to-clipboard";
89

910
type AddLinkProps = {
1011
onAdd: (l: ShortLink) => void
1112
};
1213

1314
const 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("");

front/src/pages/links/index.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ const Links:React.FC = () => {
2323

2424
const handleLinkAdded = (l:ShortLink) => {
2525
setLinks({...links, [l.id]: l});
26-
copy(l.short_url);
27-
setDisplayCopySnack(true);
2826
};
2927

3028
const handleLinkDeleted = (id:string) => {

front/src/pages/links/links_list_item/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const LinksListItem:React.FC<LinksListItemProps> = ({link, onDelete, onShortened
3838
<Grid alignItems="center" container direction="row" flexWrap="nowrap">
3939
<Grid className={classes.primary_info} container direction="column">
4040
<Grid>
41-
<CopyToClipboard text={link.short_url} onCopy={onShortenedURLCopied}>
41+
<CopyToClipboard text={link.short_url} onCopy={onShortenedURLCopied} options={{format: "text/plain"}}>
4242
<IconButton className={classes.copy_button} aria-label={t("links.copy_button_aria_label")} disabled={isDisabled}>
4343
<ContentCopyIcon />
4444
</IconButton>

front/src/pages/texts/index.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ const Links:React.FC = () => {
2323

2424
const handleTextAdded = (t:ShortText) => {
2525
setTexts({...texts, [t.id]: t});
26-
copy(t.short_url);
27-
setDisplayCopySnack(true);
2826
};
2927

3028
const handleTextDeleted = (id:string) => {

front/src/pages/texts/texts_list_item/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const TextsListItem:React.FC<TextsListItemProps> = ({text, onDelete, onShortened
3838
<Grid alignItems="center" container direction="row" flexWrap="nowrap">
3939
<Grid className={classes.primary_info} container direction="column">
4040
<Grid>
41-
<CopyToClipboard text={text.short_url} onCopy={onShortenedURLCopied}>
41+
<CopyToClipboard text={text.short_url} onCopy={onShortenedURLCopied} options={{format: "text/plain"}}>
4242
<IconButton className={classes.copy_button} aria-label={t("texts.copy_button_aria_label")} disabled={isDisabled}>
4343
<ContentCopyIcon />
4444
</IconButton>

0 commit comments

Comments
 (0)