Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Improve link card layout

Steven Teyc70483486971
diff --git a/app/ui/home/features.tsx b/app/ui/home/features.tsx
index 8b296e2901..bfc5f6b335 100644
--- a/app/ui/home/features.tsx
+++ b/app/ui/home/features.tsx
@@ -1,7 +1,7 @@
"use client";
import Link from "next/link";
-import { Airplay, Chart, QR, Users, Photo } from "@/components/shared/icons";
+import { Airplay, Chart, Users, Photo } from "@/components/shared/icons";
import MaxWidthWrapper from "@/components/shared/max-width-wrapper";
import { useState } from "react";
import {
@@ -14,7 +14,7 @@ import { AnimatePresence, motion } from "framer-motion";
import { useLinkQRModal } from "#/ui/modals/link-qr-modal";
import { DEFAULT_LINK_PROPS } from "#/lib/constants";
import { useAddEditLinkModal } from "#/ui/modals/add-edit-link-modal";
-import { Link2 } from "lucide-react";
+import { Link2, QrCode } from "lucide-react";
const featureList = [
{
@@ -73,7 +73,7 @@ const featureList = [
{
key: "qr",
title: "Free QR code generator",
- icon: <QR className="h-5 w-5 text-gray-600" />,
+ icon: <QrCode className="h-5 w-5 text-gray-600" />,
description:
"QR codes and short links are like peas in a pod. That's why we've built a QR code generator right into Dub.",
cta: "View demo", //custom cta
diff --git a/app/ui/home/link-card.tsx b/app/ui/home/link-card.tsx
index 939c1f676c..2eeff5cf50 100644
--- a/app/ui/home/link-card.tsx
+++ b/app/ui/home/link-card.tsx
@@ -7,7 +7,8 @@ import { useAddEditLinkModal } from "#/ui/modals/add-edit-link-modal";
import { useLinkQRModal } from "#/ui/modals/link-qr-modal";
import BlurImage from "#/ui/blur-image";
import CopyButton from "@/components/shared/copy-button";
-import { Chart, QR, ThreeDots } from "@/components/shared/icons";
+import { QrCode } from "lucide-react";
+import { Chart, ThreeDots } from "@/components/shared/icons";
import { LoadingDots } from "#/ui/icons";
import {
DEFAULT_LINK_PROPS,
@@ -167,7 +168,7 @@ export default function LinkCard({
className="group rounded-full bg-gray-100 p-1.5 transition-all duration-75 hover:scale-105 hover:bg-blue-100 active:scale-95"
>
<span className="sr-only">Copy</span>
- <QR className="text-gray-700 transition-all group-hover:text-blue-800" />
+ <QrCode className="text-gray-700 transition-all group-hover:text-blue-800" />
</button>
<Link
href={`/stats/${encodeURI(key)}`}
diff --git a/components/app/links/link-card.tsx b/components/app/links/link-card.tsx
index 94dccb1392..848d1ca967 100644
--- a/components/app/links/link-card.tsx
+++ b/components/app/links/link-card.tsx
@@ -9,7 +9,7 @@ import { useLinkQRModal } from "@/components/app/modals/link-qr-modal";
import IconMenu from "@/components/shared/icon-menu";
import BlurImage from "#/ui/blur-image";
import CopyButton from "@/components/shared/copy-button";
-import { Chart, Delete, QR, ThreeDots } from "@/components/shared/icons";
+import { Chart, Delete, ThreeDots } from "@/components/shared/icons";
import Popover from "@/components/shared/popover";
import Tooltip, { TooltipContent } from "#/ui/tooltip";
import useProject from "#/lib/swr/use-project";
@@ -24,7 +24,7 @@ import {
} from "#/lib/utils";
import useIntersectionObserver from "#/lib/hooks/use-intersection-observer";
import useDomains from "#/lib/swr/use-domains";
-import { Archive, CopyPlus, Edit3, Tag } from "lucide-react";
+import { Archive, CopyPlus, Edit3, QrCode, Tag } from "lucide-react";
import punycode from "punycode/";
import { GOOGLE_FAVICON_URL } from "#/lib/constants";
import useTags from "#/lib/swr/use-tags";
@@ -120,7 +120,6 @@ export default function LinkCard({ props }: { props: LinkProps }) {
};
}, [handlClickOnLinkCard]);
- const shortcuts = slug ? ["e", "d", "t", "a", "x"] : ["e", "d", "a", "x"];
const onKeyDown = (e: any) => {
// only run shortcut logic if:
// - usage is not exceeded
@@ -130,7 +129,7 @@ export default function LinkCard({ props }: { props: LinkProps }) {
if (
!exceededUsage &&
(selected || openPopover) &&
- shortcuts.includes(e.key)
+ ["e", "d", "q", "a", "x"].includes(e.key)
) {
setSelected(false);
e.preventDefault();
@@ -141,6 +140,9 @@ export default function LinkCard({ props }: { props: LinkProps }) {
case "d":
setShowDuplicateLinkModal(true);
break;
+ case "q":
+ setShowLinkQRModal(true);
+ break;
case "a":
setShowArchiveLinkModal(true);
break;
@@ -217,9 +219,9 @@ export default function LinkCard({ props }: { props: LinkProps }) {
onClick={(e) => {
e.stopPropagation();
}}
- className={`w-24 truncate text-sm font-semibold ${
+ className={`truncate text-sm font-semibold ${
archived ? "text-gray-500" : "text-blue-800"
- } sm:w-full sm:text-base`}
+ } w-full max-w-[200px] sm:text-base`}
href={linkConstructor({ key, domain })}
target="_blank"
rel="noreferrer"
@@ -232,59 +234,49 @@ export default function LinkCard({ props }: { props: LinkProps }) {
</a>
)}
<CopyButton url={linkConstructor({ key, domain })} />
- <button
- onClick={(e) => {
- e.stopPropagation();
- setShowLinkQRModal(true);
- }}
- className="group rounded-full bg-gray-100 p-1.5 transition-all duration-75 hover:scale-105 hover:bg-blue-100 active:scale-95"
- >
- <span className="sr-only">Download QR</span>
- <QR className="text-gray-700 transition-all group-hover:text-blue-800" />
- </button>
- <Link
- onClick={(e) => {
- e.stopPropagation();
- }}
- href={`/${
- slug ? `${slug}/${domain}` : "links"
- }/${encodeURIComponent(key)}`}
- className="flex items-center space-x-1 rounded-md bg-gray-100 px-2 py-0.5 transition-all duration-75 hover:scale-105 active:scale-100"
- >
- <Chart className="h-4 w-4" />
- <p className="whitespace-nowrap text-sm text-gray-500">
- {nFormatter(clicks)}
- <span className="ml-1 hidden sm:inline-block">clicks</span>
- </p>
- </Link>
{tag?.color && (
<button
onClick={(e) => {
e.stopPropagation();
setQueryString(router, "tagId", tag.id);
}}
- className="hidden transition-all duration-75 hover:scale-105 active:scale-100 sm:block"
+ className="transition-all duration-75 hover:scale-105 active:scale-100"
>
<TagBadge {...tag} withIcon />
</button>
)}
</div>
- <h3 className="max-w-[200px] truncate text-sm font-medium text-gray-700 md:max-w-md xl:max-w-lg">
- {url}
- </h3>
+ <div className="flex max-w-fit items-center space-x-1">
+ <p className="whitespace-nowrap text-sm text-gray-500">
+ {timeAgo(createdAt)}
+ </p>
+ <p>•</p>
+ <p className="max-w-[200px] truncate text-sm font-medium text-gray-700 md:max-w-md xl:max-w-[30rem]">
+ {url}
+ </p>
+ </div>
</div>
</div>
- <div className="flex items-center">
- <p className="mr-3 hidden whitespace-nowrap text-sm text-gray-500 sm:block">
- Added {timeAgo(createdAt)}
- </p>
- <p className="mr-1 whitespace-nowrap text-sm text-gray-500 sm:hidden">
- {timeAgo(createdAt, true)}
- </p>
+ <div className="flex items-center space-x-2">
+ <Link
+ onClick={(e) => {
+ e.stopPropagation();
+ }}
+ href={`/${
+ slug ? `${slug}/${domain}` : "links"
+ }/${encodeURIComponent(key)}`}
+ className="flex items-center space-x-1 rounded-md bg-gray-100 px-2 py-0.5 transition-all duration-75 hover:scale-105 active:scale-100"
+ >
+ <Chart className="h-4 w-4" />
+ <p className="whitespace-nowrap text-sm text-gray-500">
+ {nFormatter(clicks)}
+ <span className="ml-1 hidden sm:inline-block">clicks</span>
+ </p>
+ </Link>
<Popover
content={
- <div className="grid w-full gap-1 p-2 sm:w-48">
+ <div className="grid w-full gap-px p-2 sm:w-48">
{slug && exceededUsage ? (
<Tooltip
content={
@@ -359,6 +351,21 @@ export default function LinkCard({ props }: { props: LinkProps }) {
</kbd>
</button>
)}
+ <button
+ onClick={() => {
+ setOpenPopover(false);
+ setShowLinkQRModal(true);
+ }}
+ className="group flex w-full items-center justify-between rounded-md p-2 text-left text-sm font-medium text-gray-500 transition-all duration-75 hover:bg-gray-100"
+ >
+ <IconMenu
+ text="QR Code"
+ icon={<QrCode className="h-4 w-4" />}
+ />
+ <kbd className="hidden rounded bg-gray-100 px-2 py-0.5 text-xs font-light text-gray-500 transition-all duration-75 group-hover:bg-gray-200 sm:inline-block">
+ Q
+ </kbd>
+ </button>
<button
onClick={() => {
setOpenPopover(false);
diff --git a/lib/utils.ts b/lib/utils.ts
index c05befde6c..836c7bd6d0 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -138,11 +138,20 @@ export function linkConstructor({
return pretty ? link.replace(/^https?:\/\//, "") : link;
}
-export const timeAgo = (timestamp?: Date, timeOnly?: boolean): string => {
- if (!timestamp) return "never";
- return `${ms(Date.now() - new Date(timestamp).getTime())}${
- timeOnly ? "" : " ago"
- }`;
+export const timeAgo = (timestamp?: Date): string => {
+ if (!timestamp) return "Just now";
+ const diff = Date.now() - new Date(timestamp).getTime();
+ if (diff < 60000) {
+ // less than 1 second
+ return "Just now";
+ } else if (diff > 604800000) {
+ // more than 7 days
+ return new Date(timestamp).toLocaleDateString("en-US", {
+ month: "short",
+ day: "numeric",
+ });
+ }
+ return ms(diff);
};
export const getDateTimeLocal = (timestamp?: Date): string => {