Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not copy shorten link #8

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion front/src/pages/files/files_list_item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const TextsListItem:React.FC<TextsListItemProps> = ({file, onDelete, onShortened
<Grid alignItems="center" container direction="row" flexWrap="nowrap">
<Grid className={classes.primary_info} container direction="column">
<Grid>
<CopyToClipboard text={file.short_url} onCopy={onShortenedURLCopied}>
<CopyToClipboard text={file.short_url} onCopy={onShortenedURLCopied} options={{format: "text/plain"}}>
<IconButton className={classes.copy_button} aria-label={t("files.copy_button_aria_label")} disabled={isDisabled}>
<ContentCopyIcon />
</IconButton>
Expand Down
2 changes: 0 additions & 2 deletions front/src/pages/files/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
10 changes: 8 additions & 2 deletions front/src/pages/links/add_link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ 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
};

const AddLink:React.FC<AddLinkProps> = ({onAdd}) => {
const [url, setURL] = useState("");
const [shortURL, setShortURL] = useState<string>("");
const [isValid, setIsValid] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const {t} = useTranslation();

const shortRef = useRef<any>();

const handleChangeUrl = (e:ChangeEvent<HTMLInputElement>) => {
setURL(e.target.value);
setIsValid(e.target.validity.valid);
Expand All @@ -26,7 +30,9 @@ const AddLink:React.FC<AddLinkProps> = ({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("");
Expand Down
2 changes: 0 additions & 2 deletions front/src/pages/links/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion front/src/pages/links/links_list_item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const LinksListItem:React.FC<LinksListItemProps> = ({link, onDelete, onShortened
<Grid alignItems="center" container direction="row" flexWrap="nowrap">
<Grid className={classes.primary_info} container direction="column">
<Grid>
<CopyToClipboard text={link.short_url} onCopy={onShortenedURLCopied}>
<CopyToClipboard text={link.short_url} onCopy={onShortenedURLCopied} options={{format: "text/plain"}}>
<IconButton className={classes.copy_button} aria-label={t("links.copy_button_aria_label")} disabled={isDisabled}>
<ContentCopyIcon />
</IconButton>
Expand Down
2 changes: 0 additions & 2 deletions front/src/pages/texts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion front/src/pages/texts/texts_list_item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const TextsListItem:React.FC<TextsListItemProps> = ({text, onDelete, onShortened
<Grid alignItems="center" container direction="row" flexWrap="nowrap">
<Grid className={classes.primary_info} container direction="column">
<Grid>
<CopyToClipboard text={text.short_url} onCopy={onShortenedURLCopied}>
<CopyToClipboard text={text.short_url} onCopy={onShortenedURLCopied} options={{format: "text/plain"}}>
<IconButton className={classes.copy_button} aria-label={t("texts.copy_button_aria_label")} disabled={isDisabled}>
<ContentCopyIcon />
</IconButton>
Expand Down