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.

improved linkConstructor, fixed TS error

Steven Tey6ef869be2047
diff --git a/components/app/edit-link-modal.tsx b/components/app/edit-link-modal.tsx
index d0802bbe56..aadf8fa3c8 100644
--- a/components/app/edit-link-modal.tsx
+++ b/components/app/edit-link-modal.tsx
@@ -66,7 +66,7 @@ function EditLinkModalHelper({
height={20}
/>
<h3 className="font-medium text-lg">
- Edit {linkConstructor(props.key, true)}
+ Edit {linkConstructor({ key: props.key, domain, pretty: true })}
</h3>
<p className="text-sm text-gray-500">Added {timeAgo(timestamp)}</p>
</div>
diff --git a/components/app/link-card.tsx b/components/app/link-card.tsx
index 3237bdc547..3489c2287b 100644
--- a/components/app/link-card.tsx
+++ b/components/app/link-card.tsx
@@ -49,13 +49,13 @@ export default function LinkCard({
<div className="flex items-center space-x-2">
<a
className="text-blue-800 dark:text-blue-400 font-semibold"
- href={linkConstructor(key)}
+ href={linkConstructor({ key, domain })}
target="_blank"
rel="noreferrer"
>
- {linkConstructor(key, true)}
+ {linkConstructor({ key, domain, pretty: true })}
</a>
- <CopyButton url={linkConstructor(key)} />
+ <CopyButton url={linkConstructor({ key, domain })} />
<Link href={`${router.asPath}/${encodeURI(key)}`}>
<a className="rounded-md bg-gray-100 dark:bg-gray-800 px-2 py-0.5 hover:scale-105 active:scale-95 transition-all duration-75">
<p className="text-sm text-gray-500 dark:text-white">
diff --git a/components/home/link-card.tsx b/components/home/link-card.tsx
index e45b393083..4c8c300654 100644
--- a/components/home/link-card.tsx
+++ b/components/home/link-card.tsx
@@ -64,13 +64,13 @@ export default function LinkCard({
<div className="flex items-center space-x-2 mb-1">
<a
className="text-blue-800 dark:text-blue-400 font-semibold"
- href={linkConstructor(key)}
+ href={linkConstructor({ key })}
target="_blank"
rel="noreferrer"
>
- {linkConstructor(key, true)}
+ {linkConstructor({ key, pretty: true })}
</a>
- <CopyButton url={linkConstructor(key)} />
+ <CopyButton url={linkConstructor({ key })} />
<Link
href={{ pathname: "/", query: { key } }}
as={`/stats/${encodeURI(key)}`}
diff --git a/components/stats/toggle.tsx b/components/stats/toggle.tsx
index af3f3353ac..5092b5adc1 100644
--- a/components/stats/toggle.tsx
+++ b/components/stats/toggle.tsx
@@ -29,11 +29,11 @@ export default function Toggle({
<div className="group flex">
<a
className="text-xl text-gray-800 dark:text-gray-200 font-semibold"
- href={linkConstructor(key)}
+ href={linkConstructor({ key })}
target="_blank"
rel="noreferrer"
>
- {linkConstructor(key, true)}
+ {linkConstructor({ key, pretty: true })}
</a>
<ExpandingArrow className="w-5 h-5" />
</div>
diff --git a/lib/stats.ts b/lib/stats.ts
index aa3c09684d..5bd56a8fcb 100644
--- a/lib/stats.ts
+++ b/lib/stats.ts
@@ -225,6 +225,7 @@ export const processDeviceData = (
export const dummyData: StatsProps = {
key: "test",
+ interval: "7d",
totalClicks: 0,
clicksData: getTimeIntervals("7d").timeIntervals.map((interval) => ({
...interval,
diff --git a/lib/utils.ts b/lib/utils.ts
index 0fa784531f..d67565365a 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -45,14 +45,19 @@ export function nFormatter(num: number, digits?: number) {
: "0";
}
-export function linkConstructor(key: string, pretty?: boolean) {
- // if you're self-hosting you can just replace this with your own domain
+export function linkConstructor({
+ key,
+ domain = "dub.sh",
+ localhost,
+ pretty,
+}: {
+ key: string;
+ domain?: string;
+ localhost?: boolean;
+ pretty?: boolean;
+}) {
const link = `${
- process.env.NEXT_PUBLIC_DEMO_APP === "1"
- ? "https://dub.sh"
- : process.env.NEXT_PUBLIC_VERCEL === "1"
- ? process.env.NEXT_PUBLIC_VERCEL_URL
- : "http://localhost:3000"
+ localhost ? "http://localhost:3000" : `https://${domain}`
}/${key}`;
return pretty ? link.replace(/^https?:\/\//, "") : link;