1
Fork 0
mirror of https://github.com/diced/zipline.git synced 2025-03-28 23:11:22 -05:00

feat: new ui for shortened urls

This commit is contained in:
diced 2023-03-04 18:04:22 -08:00
parent 4fe4faa202
commit 0adc07ac38
No known key found for this signature in database
GPG key ID: 370BD1BA142842D1

View file

@ -10,10 +10,14 @@ import {
Skeleton,
TextInput,
Title,
Tooltip,
} from '@mantine/core';
import { useForm } from '@mantine/form';
import { useClipboard } from '@mantine/hooks';
import { useModals } from '@mantine/modals';
import { showNotification } from '@mantine/notifications';
import { CrossIcon, LinkIcon, PlusIcon } from 'components/icons';
import { CopyIcon, CrossIcon, LinkIcon, PlusIcon } from 'components/icons';
import Link from 'components/Link';
import MutedText from 'components/MutedText';
import { useURLs } from 'lib/queries/url';
import { userSelector } from 'lib/recoil/user';
@ -24,6 +28,9 @@ import URLCard from './URLCard';
export default function Urls() {
const user = useRecoilValue(userSelector);
const modals = useModals();
const clipboard = useClipboard();
const urls = useURLs();
const [createOpen, setCreateOpen] = useState(false);
@ -37,6 +44,16 @@ export default function Urls() {
},
});
const copy = (url) => {
clipboard.copy(url);
showNotification({
title: 'Copied to clipboard',
message: <Link href={url}>{url}</Link>,
color: 'green',
icon: <CopyIcon />,
});
};
const onSubmit = async (values) => {
const cleanURL = values.url.trim();
const cleanVanity = values.vanity.trim();
@ -81,11 +98,28 @@ export default function Urls() {
icon: <CrossIcon />,
});
} else {
showNotification({
title: 'URL shortened',
message: json.url,
color: 'green',
icon: <LinkIcon />,
modals.openModal({
title: <Title>Shortened URL!</Title>,
size: 'auto',
children: (
<Group position='apart'>
<Group position='left'>
<Link href={json.url}>{data.vanity ?? json.url}</Link>
</Group>
<Group position='right'>
<Tooltip label='Open link in a new tab'>
<ActionIcon onClick={() => window.open(json.url, '_blank')} variant='filled' color='primary'>
<LinkIcon />
</ActionIcon>
</Tooltip>
<Tooltip label='Copy link to clipboard'>
<ActionIcon onClick={() => copy(json.url)} variant='filled' color='primary'>
<CopyIcon />
</ActionIcon>
</Tooltip>
</Group>
</Group>
),
});
}