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.

Added feedback box

Steven Tey5fc5ee76af2d
diff --git a/app/dub.sh/help/article/[slug]/page.tsx b/app/dub.sh/help/article/[slug]/page.tsx
index e511a3832c..6463fc6e45 100644
--- a/app/dub.sh/help/article/[slug]/page.tsx
+++ b/app/dub.sh/help/article/[slug]/page.tsx
@@ -8,6 +8,7 @@ import Link from "next/link";
import Author from "#/ui/content/author";
import { MDX } from "#/ui/content/mdx";
import TableOfContents from "#/ui/content/table-of-contents";
+import Feedback from "#/ui/content/feedback";
export default function HelpArticle({
params,
@@ -67,6 +68,7 @@ export default function HelpArticle({
<Author username={data.author} updatedAt={data.updatedAt} />
</div>
<MDX code={data.body.code} />
+ <Feedback />
</div>
<TableOfContents items={data.tableOfContents} />
</MaxWidthWrapper>
diff --git a/app/sitemap.ts b/app/sitemap.ts
index 2041e19ad9..dfbf84d857 100644
--- a/app/sitemap.ts
+++ b/app/sitemap.ts
@@ -1,6 +1,10 @@
import prisma from "#/lib/prisma";
import { headers } from "next/headers";
-import { allChangelogPosts, allLegalPosts } from "contentlayer/generated";
+import {
+ allChangelogPosts,
+ allHelpPosts,
+ allLegalPosts,
+} from "contentlayer/generated";
import { isHomeHostname } from "#/lib/utils";
export default async function Sitemap() {
@@ -34,13 +38,21 @@ export default async function Sitemap() {
url: `https://${domain}/pricing`,
lastModified: new Date(),
},
+ {
+ url: `https://${domain}/help`,
+ lastModified: new Date(),
+ },
+ ...allHelpPosts.map((post) => ({
+ url: `https://${domain}/help/${post.slug}`,
+ lastModified: new Date(post.updatedAt),
+ })),
{
url: `https://${domain}/changelog`,
lastModified: new Date(),
},
...allChangelogPosts.map((post) => ({
url: `https://${domain}/changelog/${post.slug}`,
- lastModified: new Date(),
+ lastModified: new Date(post.publishedAt),
})),
{
url: `https://${domain}/metatags`,
@@ -48,7 +60,7 @@ export default async function Sitemap() {
},
...allLegalPosts.map((post) => ({
url: `https://${domain}/${post.slug}`,
- lastModified: new Date(),
+ lastModified: new Date(post.updatedAt),
})),
]
: []),
diff --git a/app/ui/content/feedback.tsx b/app/ui/content/feedback.tsx
new file mode 100644
index 0000000000..afd5765217
--- /dev/null
+++ b/app/ui/content/feedback.tsx
@@ -0,0 +1,63 @@
+"use client";
+
+import { useParams } from "next/navigation";
+import { toast } from "sonner";
+import Cookies from "js-cookie";
+import { useEffect, useState } from "react";
+import { cn } from "#/lib/utils";
+import va from "@vercel/analytics";
+
+const reactions = [
+ {
+ emoji: "😞",
+ label: "Not helpful",
+ },
+ {
+ emoji: "😐",
+ label: "Somewhat helpful",
+ },
+ {
+ emoji: "😀",
+ label: "Very helpful",
+ },
+];
+
+export default function Feedback() {
+ const { slug } = useParams() as { slug: string };
+
+ const [reaction, setReaction] = useState<string | null>(null);
+ useEffect(() => {
+ const reaction = Cookies.get(`feedback-help-${slug}`);
+ if (reaction) setReaction(reaction);
+ }, [slug, reaction]);
+
+ return (
+ <div className="my-10 flex flex-col items-center justify-center space-y-2 rounded-lg border border-y-gray-200 bg-white py-10">
+ <p className="text-gray-500 sm:text-lg">Did this answer your question?</p>
+ <div className="flex space-x-4">
+ {reactions.map(({ emoji, label }) => (
+ <button
+ key={label}
+ onClick={() => {
+ va.track(`Help Center Feedback: ${label}`, {
+ slug: `/help/article/${slug}`,
+ });
+ Cookies.set(`feedback-help-${slug}`, label);
+ setReaction(label);
+ toast.success("Feedback recorded – thank you!");
+ }}
+ className={cn(
+ "text-4xl transition-all duration-75 hover:scale-110 active:scale-100",
+ {
+ "scale-90 grayscale": reaction && reaction !== label,
+ "scale-110": reaction === label,
+ },
+ )}
+ >
+ {emoji}
+ </button>
+ ))}
+ </div>
+ </div>
+ );
+}
diff --git a/lib/hooks/use-scroll.ts b/lib/hooks/use-scroll.ts
index 3c8014e31d..511fb9984c 100644
--- a/lib/hooks/use-scroll.ts
+++ b/lib/hooks/use-scroll.ts
@@ -4,7 +4,7 @@ export default function useScroll(threshold: number) {
const [scrolled, setScrolled] = useState(false);
const onScroll = useCallback(() => {
- setScrolled(window.pageYOffset > threshold);
+ setScrolled(window.scrollY > threshold);
}, [threshold]);
useEffect(() => {
@@ -12,5 +12,10 @@ export default function useScroll(threshold: number) {
return () => window.removeEventListener("scroll", onScroll);
}, [onScroll]);
+ // also check on first load
+ useEffect(() => {
+ onScroll();
+ }, [onScroll]);
+
return scrolled;
}