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.

♻️ Refactor same code to separate component

Max Programming69aba2d9734f
diff --git a/components/app/links/link-card.tsx b/components/app/links/link-card.tsx
index 58c43c8553..fcc9c093ae 100644
--- a/components/app/links/link-card.tsx
+++ b/components/app/links/link-card.tsx
@@ -6,6 +6,7 @@ import { useAddEditLinkModal } from "@/components/app/modals/add-edit-link-modal
import { useArchiveLinkModal } from "@/components/app/modals/archive-link-modal";
import { useDeleteLinkModal } from "@/components/app/modals/delete-link-modal";
import { useLinkQRModal } from "@/components/app/modals/link-qr-modal";
+import MenuIcon from "@/components/layout/app/menu-icon";
import BlurImage from "@/components/shared/blur-image";
import CopyButton from "@/components/shared/copy-button";
import {
@@ -176,10 +177,7 @@ export default function LinkCard({ props }: { props: LinkProps }) {
}}
className="w-full font-medium text-sm text-gray-500 p-2 text-left rounded-md hover:bg-gray-100 transition-all duration-75"
>
- <div className="flex items-center justify-start space-x-2">
- <Edit className="w-4 h-4" />
- <p className="text-sm">Edit</p>
- </div>
+ <MenuIcon text="Edit" icon={<Edit className="h-4 w-4" />} />
</button>
)}
<button
@@ -189,10 +187,10 @@ export default function LinkCard({ props }: { props: LinkProps }) {
}}
className="w-full font-medium text-sm text-gray-500 p-2 text-left rounded-md hover:bg-gray-100 transition-all duration-75"
>
- <div className="flex items-center justify-start space-x-2">
- <Archive className="w-4 h-4" />
- <p className="text-sm">Archive</p>
- </div>
+ <MenuIcon
+ text="Archive"
+ icon={<Archive className="h-4 w-4" />}
+ />
</button>
<button
onClick={() => {
@@ -201,10 +199,10 @@ export default function LinkCard({ props }: { props: LinkProps }) {
}}
className="w-full font-medium text-sm text-red-600 hover:bg-red-600 hover:text-white p-2 text-left rounded-md transition-all duration-75"
>
- <div className="flex items-center justify-start space-x-2">
- <Delete className="w-4 h-4" />
- <p className="text-sm">Delete</p>
- </div>
+ <MenuIcon
+ text="Delete"
+ icon={<Delete className="h-4 w-4" />}
+ />
</button>
</div>
}
diff --git a/components/app/links/link-filters/link-sort.tsx b/components/app/links/link-filters/link-sort.tsx
index 445177ea56..ca6083b76f 100644
--- a/components/app/links/link-filters/link-sort.tsx
+++ b/components/app/links/link-filters/link-sort.tsx
@@ -1,5 +1,6 @@
import { useRouter } from "next/router";
import { useMemo, useState } from "react";
+import MenuIcon from "@/components/layout/app/menu-icon";
import BlurImage from "@/components/shared/blur-image";
import {
ChevronDown,
@@ -54,10 +55,10 @@ export default function LinkSort() {
}}
className="flex items-center justify-between space-x-2 px-1 py-2 w-full rounded-md hover:bg-gray-100 active:bg-gray-200"
>
- <div className="flex items-center justify-start space-x-2">
- <SortDesc className="w-4 h-4" />
- <p className="text-sm text-gray-700">{display}</p>
- </div>
+ <MenuIcon
+ text={display}
+ icon={<SortDesc className="w-4 h-4" />}
+ />
{selectedSort.slug === slug && (
<Tick className="h-4 w-4" aria-hidden="true" />
)}
@@ -72,10 +73,7 @@ export default function LinkSort() {
onClick={() => setOpenPopover(!openPopover)}
className="flex justify-between items-center space-x-2 bg-white w-full sm:w-48 px-3 py-2.5 rounded-md shadow hover:shadow-md active:scale-95 transition-all duration-75"
>
- <div className="flex items-center space-x-2 text-gray-700">
- <Sort className="h-4 w-4 shrink-0" />
- <p className="text-sm">Sort by</p>
- </div>
+ <MenuIcon text="Sort by" icon={<Sort className="h-4 w-4 shrink-0" />} />
<ChevronDown
className={`w-5 h-5 text-gray-400 ${
openPopover ? "transform rotate-180" : ""
diff --git a/components/app/links/link-filters/status-filter.tsx b/components/app/links/link-filters/status-filter.tsx
index 752b3c1976..6a85bbf2de 100644
--- a/components/app/links/link-filters/status-filter.tsx
+++ b/components/app/links/link-filters/status-filter.tsx
@@ -1,5 +1,6 @@
import { useRouter } from "next/router";
import { useMemo, useState } from "react";
+import MenuIcon from "@/components/layout/app/menu-icon";
import { ChevronDown, Tick } from "@/components/shared/icons";
import Popover from "@/components/shared/popover";
@@ -85,10 +86,10 @@ export default function StatusFilter() {
}}
className="flex items-center justify-between p-2 w-full rounded-md hover:bg-gray-100 active:bg-gray-200"
>
- <div className="flex items-center justify-start space-x-2">
- <div className={`rounded-full w-2 h-2 ${color}`} />
- <p className="text-sm text-gray-700">{display}</p>
- </div>
+ <MenuIcon
+ text={display}
+ icon={<div className={`rounded-full w-2 h-2 ${color}`} />}
+ />
{(status === "all" ||
(selectedStatus.includes(slug) && status !== "none")) && (
<Tick className="h-4 w-4" aria-hidden="true" />
diff --git a/components/layout/app/menu-icon.tsx b/components/layout/app/menu-icon.tsx
new file mode 100644
index 0000000000..38843cf01c
--- /dev/null
+++ b/components/layout/app/menu-icon.tsx
@@ -0,0 +1,15 @@
+import { ReactNode } from "react";
+
+interface MenuIconProps {
+ icon: ReactNode;
+ text: string;
+}
+
+export default function MenuIcon({ icon, text }: MenuIconProps) {
+ return (
+ <div className="flex items-center justify-start space-x-2">
+ {icon}
+ <p className="text-sm">{text}</p>
+ </div>
+ );
+}
diff --git a/components/layout/app/user-dropdown.tsx b/components/layout/app/user-dropdown.tsx
index 7b426612a1..e9d2ee2e90 100644
--- a/components/layout/app/user-dropdown.tsx
+++ b/components/layout/app/user-dropdown.tsx
@@ -2,6 +2,7 @@ import { useState } from "react";
import { signOut, useSession } from "next-auth/react";
import { Logout } from "@/components/shared/icons";
import Popover from "@/components/shared/popover";
+import MenuIcon from "./menu-icon";
export default function UserDropdown() {
const { data: session } = useSession();
@@ -16,10 +17,7 @@ export default function UserDropdown() {
className="relative p-2 rounded-md w-full hover:bg-gray-100 transition-all duration-75 text-sm text-left"
onClick={() => signOut()}
>
- <div className="flex items-center justify-start space-x-2">
- <Logout className="w-4 h-4" />
- <p className="text-sm">Logout</p>
- </div>
+ <MenuIcon text="Logout" icon={<Logout className="h-4 w-4" />} />
</button>
</div>
}