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.

made it work on mobile

Steven Teyb8317f81fffe
diff --git a/components/app/links/link-card.tsx b/components/app/links/link-card.tsx
index 6816125e98..31d0b6f4cf 100644
--- a/components/app/links/link-card.tsx
+++ b/components/app/links/link-card.tsx
@@ -255,9 +255,9 @@ export default function LinkCard({ props }: { props: LinkProps }) {
{tag?.color && (
<button
onClick={() => setShowTagLinkModal(true)}
- className="transition-all duration-75 hover:scale-105 active:scale-100"
+ className="hidden transition-all duration-75 hover:scale-105 active:scale-100 sm:block"
>
- <Badge {...tag} />
+ <Badge {...tag} withIcon />
</button>
)}
</div>
@@ -353,8 +353,7 @@ export default function LinkCard({ props }: { props: LinkProps }) {
)}
{slug && (
<button
- onClick={(e) => {
- e.preventDefault();
+ onClick={() => {
setOpenPopover(false);
setShowTagLinkModal(true);
}}
@@ -367,8 +366,7 @@ export default function LinkCard({ props }: { props: LinkProps }) {
</button>
)}
<button
- onClick={(e) => {
- e.preventDefault();
+ onClick={() => {
setOpenPopover(false);
setShowArchiveLinkModal(true);
}}
diff --git a/components/app/links/link-filters.tsx b/components/app/links/link-filters.tsx
index ba80ee071d..a95db4ed7e 100644
--- a/components/app/links/link-filters.tsx
+++ b/components/app/links/link-filters.tsx
@@ -4,6 +4,7 @@ import {
useCallback,
useContext,
useEffect,
+ useMemo,
useRef,
useState,
} from "react";
@@ -23,6 +24,7 @@ import { useSession } from "next-auth/react";
import { toast } from "sonner";
import { ModalContext } from "#/ui/modal-provider";
import useTags from "@/lib/swr/use-tags";
+import Badge from "@/components/shared/badge";
export default function LinkFilters() {
const { primaryDomain } = useDomains();
@@ -41,9 +43,6 @@ export default function LinkFilters() {
};
const searchInputRef = useRef(); // this is a hack to clear the search input when the clear button is clicked
- const { setShowAddProjectModal } = useContext(ModalContext);
-
- // return domains && tags ? (
return domains ? (
<div className="grid w-full rounded-md bg-white px-5 lg:divide-y lg:divide-gray-300">
<div className="grid gap-3 py-6">
@@ -55,71 +54,10 @@ export default function LinkFilters() {
</div>
<SearchBox searchInputRef={searchInputRef} />
</div>
- <FilterGroup
- displayName="Domains"
- param="domain"
- options={
- domains.length === 0
- ? [
- {
- name: primaryDomain || "",
- value: primaryDomain || "",
- count: 0,
- },
- ]
- : domains.map(({ domain, _count }) => ({
- name: domain,
- value: domain,
- count: _count,
- }))
- }
- checkDefault={domains.length <= 1}
- cta={
- slug ? (
- <Link
- href={`/${slug}/domains`}
- className="rounded-md border border-gray-300 p-1 text-center text-sm"
- >
- Add a domain
- </Link>
- ) : (
- <button
- onClick={() => {
- setShowAddProjectModal(true);
- toast.error(
- "You can only add a domain to a custom project. Please create a new project or navigate to an existing one.",
- );
- }}
- className="rounded-md border border-gray-300 p-1 text-center text-sm"
- >
- Add a domain
- </button>
- )
- }
- />
+ <DomainsFilter domains={domains} primaryDomain={primaryDomain} />
{slug && (
<>
- {tagsCount && (
- <FilterGroup
- displayName="Tags"
- param="tagId"
- options={tagsCount.map(({ tagId, _count }) => ({
- name: tags?.find((tag) => tag.id === tagId)?.name || "",
- value: tagId,
- count: _count,
- }))}
- cta={
- <button
- onClick={() => {
- toast.success("add a tag to a project");
- }}
- className="rounded-md border border-gray-300 p-1 text-center text-sm"
- >
- Add a tag
- </button>
- }
- />
- )}
+ {tagsCount && <TagsFilter tags={tags} tagsCount={tagsCount} />}
<MyLinksFilter />
</>
)}
@@ -132,7 +70,27 @@ export default function LinkFilters() {
);
}
-const SearchBox = ({ searchInputRef }: { searchInputRef }) => {
+const ClearButton = ({ searchInputRef }) => {
+ const router = useRouter();
+ const { slug } = router.query;
+ return (
+ <button
+ onClick={() => {
+ router.replace(`/${slug || "links"}`).then(() => {
+ searchInputRef.current.value = "";
+ });
+ }}
+ className="group flex items-center justify-center space-x-1 rounded-md border border-gray-500 px-2 py-1 transition-all hover:border-black"
+ >
+ <XCircle className="h-4 w-4 text-gray-500 transition-all group-hover:text-black" />
+ <p className="text-sm text-gray-500 transition-all group-hover:text-black">
+ Clear
+ </p>
+ </button>
+ );
+};
+
+const SearchBox = ({ searchInputRef }) => {
const router = useRouter();
const debounced = useDebouncedCallback((value) => {
setQueryString(router, "search", value);
@@ -182,62 +140,28 @@ const SearchBox = ({ searchInputRef }: { searchInputRef }) => {
);
};
-const MyLinksFilter = () => {
+const DomainsFilter = ({ domains, primaryDomain }) => {
const router = useRouter();
- const { userId } = router.query as { userId?: string };
- const { data: session } = useSession();
+ const { slug } = router.query as { slug?: string };
- return (
- <div className="flex items-center justify-between py-6">
- <label className="text-sm font-medium text-gray-600">
- Show my links only
- </label>
- <Switch
- fn={() =>
- // @ts-ignore
- setQueryString(router, "userId", userId ? "" : session?.user.id)
- }
- checked={userId ? true : false}
- />
- </div>
- );
-};
+ const [collapsed, setCollapsed] = useState(false);
-const ArchiveFilter = () => {
- const router = useRouter();
- const { showArchived } = router.query as { showArchived?: string };
+ const options =
+ domains.length === 0
+ ? [
+ {
+ name: primaryDomain || "",
+ value: primaryDomain || "",
+ count: 0,
+ },
+ ]
+ : domains.map(({ domain, _count }) => ({
+ name: domain,
+ value: domain,
+ count: _count,
+ }));
- return (
- <div className="flex items-center justify-between py-6">
- <label className="text-sm font-medium text-gray-600">
- Include archived links
- </label>
- <Switch
- fn={() =>
- // @ts-ignore
- setQueryString(router, "showArchived", showArchived ? "" : "true")
- }
- checked={showArchived ? true : false}
- />
- </div>
- );
-};
-
-const FilterGroup = ({
- displayName,
- param,
- options,
- checkDefault = false,
- cta,
-}: {
- displayName: string;
- param: string;
- options: { name: string; value: string; count: number }[];
- checkDefault?: boolean;
- cta: ReactNode;
-}) => {
- const router = useRouter();
- const [collapsed, setCollapsed] = useState(false);
+ const { setShowAddProjectModal } = useContext(ModalContext);
return (
<fieldset className="overflow-hidden py-6">
@@ -251,7 +175,7 @@ const FilterGroup = ({
<ChevronRight
className={`${collapsed ? "" : "rotate-90"} h-5 w-5 transition-all`}
/>
- <h4 className="font-medium text-gray-900">{displayName}</h4>
+ <h4 className="font-medium text-gray-900">Domains</h4>
</button>
</div>
<AnimatePresence initial={false}>
@@ -268,9 +192,9 @@ const FilterGroup = ({
<input
id={value}
name={value}
- checked={router.query[param] === value || checkDefault}
+ checked={router.query.domain === value || domains.length <= 1}
onChange={() => {
- setQueryString(router, param, value);
+ setQueryString(router, "domain", value);
}}
type="radio"
className="ml-3 h-4 w-4 cursor-pointer rounded-full border-gray-300 text-black focus:outline-none focus:ring-0"
@@ -284,7 +208,26 @@ const FilterGroup = ({
</label>
</div>
))}
- {cta}
+ {slug ? (
+ <Link
+ href={`/${slug}/domains`}
+ className="rounded-md border border-gray-300 p-1 text-center text-sm"
+ >
+ Add a domain
+ </Link>
+ ) : (
+ <button
+ onClick={() => {
+ setShowAddProjectModal(true);
+ toast.error(
+ "You can only add a domain to a custom project. Please create a new project or navigate to an existing one.",
+ );
+ }}
+ className="rounded-md border border-gray-300 p-1 text-center text-sm"
+ >
+ Add a domain
+ </button>
+ )}
</motion.div>
)}
</AnimatePresence>
@@ -292,30 +235,138 @@ const FilterGroup = ({
);
};
-const ClearButton = ({ searchInputRef }: { searchInputRef }) => {
+const TagsFilter = ({ tags, tagsCount }) => {
const router = useRouter();
- const { slug } = router.query;
+ const [collapsed, setCollapsed] = useState(tagsCount.length === 0);
+ const [search, setSearch] = useState("");
+ const [showMore, setShowMore] = useState(false);
+
+ const options = useMemo(() => {
+ const initialOptions = tagsCount.map(({ tagId, _count }) => ({
+ id: tagId,
+ name: tags?.find((tag) => tag.id === tagId)?.name || "",
+ color: tags?.find((tag) => tag.id === tagId)?.color || "blue",
+ count: _count,
+ }));
+ if (search.length > 0) {
+ return initialOptions.filter(({ name }) =>
+ name.toLowerCase().includes(search.toLowerCase()),
+ );
+ }
+ return initialOptions;
+ }, [tagsCount, tags, search]);
+
return (
- <button
- onClick={() => {
- router.replace(`/${slug || "links"}`).then(() => {
- searchInputRef.current.value = "";
- });
- }}
- className="group flex items-center justify-center space-x-1 rounded-md border border-gray-500 px-2 py-1 transition-all hover:border-black"
- >
- <XCircle className="h-4 w-4 text-gray-500 transition-all group-hover:text-black" />
- <p className="text-sm text-gray-500 transition-all group-hover:text-black">
- Clear
- </p>
- </button>
+ <fieldset className="overflow-hidden py-6">
+ <div className="flex h-8 items-center justify-between">
+ <button
+ onClick={() => {
+ setCollapsed(!collapsed);
+ }}
+ className="flex items-center space-x-2"
+ >
+ <ChevronRight
+ className={`${collapsed ? "" : "rotate-90"} h-5 w-5 transition-all`}
+ />
+ <h4 className="font-medium text-gray-900">Tags</h4>
+ </button>
+ </div>
+ <AnimatePresence initial={false}>
+ {!collapsed && (
+ <motion.div
+ className="mt-4 grid gap-2"
+ {...SWIPE_REVEAL_ANIMATION_SETTINGS}
+ >
+ <div className="relative mb-1">
+ <div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
+ <Search className="h-4 w-4 text-gray-400" />
+ </div>
+ <input
+ type="text"
+ className="peer w-full rounded-md border border-gray-300 py-1.5 pl-10 text-sm text-black placeholder:text-gray-400 focus:border-black focus:ring-0"
+ placeholder="Filter tags"
+ value={search}
+ onChange={(e) => setSearch(e.target.value)}
+ />
+ </div>
+ {(showMore ? options : options.slice(0, 4)).map(
+ ({ id, name, color, count }) => (
+ <div
+ key={id}
+ className="relative flex cursor-pointer items-center space-x-3 rounded-md bg-gray-50 transition-all hover:bg-gray-100"
+ >
+ <input
+ id={id}
+ name={id}
+ checked={router.query.tagId === id}
+ onChange={() => {
+ setQueryString(router, "tagId", id);
+ }}
+ type="radio"
+ className="ml-3 h-4 w-4 cursor-pointer rounded-full border-gray-300 text-black focus:outline-none focus:ring-0"
+ />
+ <label
+ htmlFor={id}
+ className="flex w-full cursor-pointer justify-between px-3 py-1.5 pl-0 text-sm font-medium text-gray-700"
+ >
+ <Badge name={name} color={color} />
+ <p className="text-gray-500">{nFormatter(count)}</p>
+ </label>
+ </div>
+ ),
+ )}
+ {options.length > 4 && (
+ <button
+ onClick={() => setShowMore(!showMore)}
+ className="rounded-md border border-gray-300 p-1 text-center text-sm"
+ >
+ Show {showMore ? "less" : "more"}
+ </button>
+ )}
+ </motion.div>
+ )}
+ </AnimatePresence>
+ </fieldset>
);
};
-const FilterGroupPlaceholder = () => {
+const MyLinksFilter = () => {
+ const router = useRouter();
+ const { userId } = router.query as { userId?: string };
+ const { data: session } = useSession();
+
return (
- <div className="py-6">
- <div className="h-8 animate-pulse rounded-md bg-gray-100" />
+ <div className="flex items-center justify-between py-6">
+ <label className="text-sm font-medium text-gray-600">
+ Show my links only
+ </label>
+ <Switch
+ fn={() =>
+ // @ts-ignore
+ setQueryString(router, "userId", userId ? "" : session?.user.id)
+ }
+ checked={userId ? true : false}
+ />
+ </div>
+ );
+};
+
+const ArchiveFilter = () => {
+ const router = useRouter();
+ const { showArchived } = router.query as { showArchived?: string };
+
+ return (
+ <div className="flex items-center justify-between py-6">
+ <label className="text-sm font-medium text-gray-600">
+ Include archived links
+ </label>
+ <Switch
+ fn={() =>
+ // @ts-ignore
+ setQueryString(router, "showArchived", showArchived ? "" : "true")
+ }
+ checked={showArchived ? true : false}
+ />
</div>
);
};
diff --git a/components/app/modals/tag-link-modal.tsx b/components/app/modals/tag-link-modal.tsx
index 167b11f143..763137b2ae 100644
--- a/components/app/modals/tag-link-modal.tsx
+++ b/components/app/modals/tag-link-modal.tsx
@@ -16,11 +16,13 @@ import { LinkProps } from "@/lib/types";
import { getApexDomain, getQueryString, linkConstructor } from "@/lib/utils";
import { GOOGLE_FAVICON_URL } from "@/lib/constants";
import { toast } from "sonner";
-import { ChevronDown, Search, X } from "lucide-react";
+import { Check, ChevronDown, Search, X } from "lucide-react";
import { Command } from "cmdk";
import Button from "#/ui/button";
import useTags from "@/lib/swr/use-tags";
import Badge from "@/components/shared/badge";
+import va from "@vercel/analytics";
+import useWindowSize from "#/lib/hooks/use-window-size";
function TagLinkModal({
showTagLinkModal,
@@ -39,10 +41,9 @@ function TagLinkModal({
const { key, domain, tagId } = props;
const { tags } = useTags();
- const [selectedTag, setSelectedTag] = useState(
- tags?.find((t) => t.id === tagId),
+ const [tagValue, setTagValue] = useState(
+ tags?.find((t) => t.id === tagId)?.name || "",
);
- const [value, setValue] = useState(selectedTag?.name || "");
const shortlink = useMemo(() => {
return linkConstructor({
@@ -56,53 +57,57 @@ function TagLinkModal({
async (e?: SyntheticEvent) => {
e?.preventDefault();
setTagging(true);
- console.log(selectedTag, value);
fetch(
`/api/links/${encodeURIComponent(
props.key,
)}/tag?slug=${slug}&domain=${domain}`,
{
- method: "POST",
+ method: tagValue.length > 0 ? "POST" : "DELETE",
headers: {
"Content-Type": "application/json",
},
- body: JSON.stringify({
- tagId:
- selectedTag && value === selectedTag.name ? selectedTag.id : null,
+ ...(tagValue.length > 0 && {
+ body: JSON.stringify({ tag: tagValue }),
}),
},
).then(async (res) => {
setTagging(false);
if (res.status === 200) {
mutate(`/api/links${getQueryString(router)}`);
+ mutate(`/api/projects/${slug}/tags`);
mutate(
`/api/links/_count${getQueryString(router, {
groupBy: "tagId",
})}`,
);
setShowTagLinkModal(false);
- toast.success(`Successfully tagged shortlink!`);
+ toast.success(`Successfully updated shortlink!`);
+ tagValue.length > 0 && va.track("Tagged Link");
} else {
const error = await res.text();
toast.error(error);
}
});
},
- [props, selectedTag, slug, domain, router],
+ [props, tagValue, slug, domain, router],
);
- const ref = useRef<HTMLDivElement | null>(null);
+ const commandRef = useRef<HTMLDivElement | null>(null);
const [open, setOpen] = useState(false);
-
+ const { width } = useWindowSize();
useEffect(() => {
const handleClickOutside = (e) => {
- if (ref.current && !ref.current.contains(e.target)) {
+ if (commandRef.current && !commandRef.current.contains(e.target)) {
setOpen(false);
}
};
- document.addEventListener("mousedown", handleClickOutside);
- return () => document.removeEventListener("mousedown", handleClickOutside);
- }, [ref]);
+ // only for desktop
+ if (width > 768) {
+ document.addEventListener("mousedown", handleClickOutside);
+ return () =>
+ document.removeEventListener("mousedown", handleClickOutside);
+ }
+ }, [commandRef, width]);
return (
<Modal showModal={showTagLinkModal} setShowModal={setShowTagLinkModal}>
@@ -122,87 +127,100 @@ function TagLinkModal({
</div>
<form
- className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 text-left sm:px-16"
+ className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 text-left sm:rounded-b-2xl sm:px-16"
onSubmit={handleSubmit}
>
- <div>
- <label
- htmlFor="Tag Selection"
- className="block text-sm text-gray-700"
- >
- Tag
- </label>
- <Command ref={ref} className="relative" loop>
- <div className="relative mt-3 w-full rounded-md">
- <Search className="absolute inset-y-0 left-0 my-auto h-7 w-7 pl-3 text-gray-400" />
- <Command.Input
- placeholder="Choose tag"
- onFocus={() => setOpen(true)}
- value={value}
- onValueChange={setValue}
- onKeyDown={(e) => {
- if (e.key === "Escape") {
- e.stopPropagation();
+ <Command
+ ref={commandRef}
+ className="relative"
+ loop
+ shouldFilter={
+ tagValue.length > 0 && !tags?.find((t) => t.name === tagValue)
+ }
+ >
+ <div className="relative mt-1 w-full rounded-md">
+ <Search className="absolute inset-y-0 left-0 my-auto h-7 w-7 pl-3 text-gray-400" />
+ <Command.Input
+ placeholder="Choose tag"
+ onFocus={() => tags && tags.length > 0 && setOpen(true)}
+ value={tagValue}
+ onValueChange={setTagValue}
+ onKeyDown={(e) => {
+ if (e.key === "Escape") {
+ e.stopPropagation();
+ setOpen(false);
+ } else if (e.key === "Enter") {
+ if (open) {
+ // if dropdown is open, close it
setOpen(false);
- } else if (e.key === "Enter") {
- if (open) {
- // if dropdown is open, close it
- setOpen(false);
- } else {
- // if dropdown is already closed, submit form
- handleSubmit();
- }
} else {
- setOpen(true);
+ // if dropdown is already closed, submit form
+ handleSubmit();
}
+ } else {
+ setOpen(true);
+ }
+ }}
+ className="block w-full rounded-md border-gray-300 px-10 text-sm text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500"
+ />
+ {tagValue ? (
+ <button
+ onClick={() => {
+ setTagValue("");
+ setOpen(true);
}}
- className="block w-full rounded-md border-gray-300 px-10 text-sm text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500"
- />
- {value ? (
+ className="absolute inset-y-0 right-0 my-auto"
+ >
+ <X className="h-7 w-7 pr-3 text-gray-400" />
+ </button>
+ ) : (
+ <ChevronDown className="absolute inset-y-0 right-0 my-auto h-7 w-7 pr-3 text-gray-400" />
+ )}
+ </div>
+ {open && (
+ <Command.List
+ style={{
+ animationFillMode: "forwards", // to keep the last frame of the animation
+ }}
+ className="absolute z-10 h-[300px] w-full animate-input-select-slide-up overflow-auto rounded-md border border-gray-200 bg-white p-2 transition-all sm:h-auto sm:max-h-[300px] sm:animate-input-select-slide-down"
+ >
+ <Command.Empty>
<button
- onClick={() => {
- setValue("");
- setOpen(true);
- }}
- className="absolute inset-y-0 right-0 my-auto"
+ type="button"
+ onClick={() => setOpen(false)}
+ className="flex w-full cursor-pointer items-center rounded-md bg-gray-100 px-4 py-2 text-sm text-gray-900 hover:text-gray-900 aria-selected:bg-gray-100 aria-selected:text-gray-900"
>
- <X className="h-7 w-7 pr-3 text-gray-400" />
+ {tagValue.length > 0 ? (
+ <>
+ Create tag{" "}
+ <span className="ml-1.5 rounded-md bg-blue-100 px-2 py-0.5 text-blue-600">
+ {tagValue}
+ </span>
+ </>
+ ) : (
+ <p className="py-0.5">Start typing to create tag...</p>
+ )}
</button>
- ) : (
- <ChevronDown className="absolute inset-y-0 right-0 my-auto h-7 w-7 pr-3 text-gray-400" />
- )}
- </div>
- {open && (
- <Command.List className="absolute z-10 mt-2 max-h-[300px] w-full animate-slide-down overflow-auto rounded-md border border-gray-200 bg-white p-2 transition-all">
- <Command.Empty>
- <button
- type="button"
- className="flex w-full cursor-pointer items-center rounded-md px-4 py-2 text-sm text-gray-900 hover:bg-gray-100 hover:text-gray-900 aria-selected:bg-gray-100 aria-selected:text-gray-900"
- >
- Create tag{" "}
- <span className="ml-1.5 rounded-md bg-red-100 px-2 py-0.5 text-red-600">
- {value}
- </span>
- </button>
- </Command.Empty>
- {tags?.map((tag) => (
- <Command.Item
- key={tag.id}
- value={tag.name}
- onSelect={() => {
- setValue(tag.name);
- setSelectedTag(tag);
- setOpen(false);
- }}
- className="flex cursor-pointer items-center rounded-md px-4 py-2 text-sm text-gray-900 hover:bg-gray-100 hover:text-gray-900 active:bg-gray-200 aria-selected:bg-gray-100 aria-selected:text-gray-900"
- >
- <Badge {...tag} />
- </Command.Item>
- ))}
- </Command.List>
- )}
- </Command>
- </div>
+ </Command.Empty>
+ {tags?.map((tag) => (
+ <Command.Item
+ key={tag.id}
+ value={tag.name}
+ onSelect={() => {
+ setTagValue(tag.name);
+ setOpen(false);
+ }}
+ className="flex cursor-pointer items-center justify-between rounded-md px-4 py-2 text-sm text-gray-900 hover:bg-gray-100 hover:text-gray-900 active:bg-gray-200 aria-selected:bg-gray-100 aria-selected:text-gray-900"
+ >
+ <Badge {...tag} />
+ {tagValue === tag.name && (
+ <Check className="h-4 w-4 text-gray-500" />
+ )}
+ </Command.Item>
+ ))}
+ </Command.List>
+ )}
+ </Command>
<Button loading={tagging} text="Confirm selection" />
</form>
diff --git a/components/app/settings/plan-usage.tsx b/components/app/settings/plan-usage.tsx
index e7b1f18dc7..bf06a0b152 100644
--- a/components/app/settings/plan-usage.tsx
+++ b/components/app/settings/plan-usage.tsx
@@ -90,7 +90,7 @@ export default function PlanUsage() {
</div>
</Tooltip>
</div>
- {usage && usageLimit ? (
+ {usage !== undefined && usageLimit ? (
<p className="text-sm text-gray-600">
{nFormatter(usage)} / {nFormatter(usageLimit)} clicks (
{((usage / usageLimit) * 100).toFixed(1)}%)
@@ -103,7 +103,9 @@ export default function PlanUsage() {
initial={{ width: 0 }}
animate={{
width:
- usage && usageLimit ? (usage / usageLimit) * 100 + "%" : "0%",
+ usage !== undefined && usageLimit
+ ? (usage / usageLimit) * 100 + "%"
+ : "0%",
}}
transition={{ duration: 0.5, type: "spring" }}
className={`${
diff --git a/components/layout/app/index.tsx b/components/layout/app/index.tsx
index c0b95f3573..f4a874aced 100644
--- a/components/layout/app/index.tsx
+++ b/components/layout/app/index.tsx
@@ -31,43 +31,43 @@ export default function AppLayout({
key?: string;
};
- useEffect(() => {
- Crisp.configure("2c09b1ee-14c2-46d1-bf72-1dbb998a19e0");
- }, []);
+ // useEffect(() => {
+ // Crisp.configure("2c09b1ee-14c2-46d1-bf72-1dbb998a19e0");
+ // }, []);
- const { data: session } = useSession();
- useEffect(() => {
- if (session?.user?.email) {
- Crisp.user.setEmail(session.user.email);
- Crisp.user.setNickname(session.user.name || session.user.email);
- }
- }, [session]);
+ // const { data: session } = useSession();
+ // useEffect(() => {
+ // if (session?.user?.email) {
+ // Crisp.user.setEmail(session.user.email);
+ // Crisp.user.setNickname(session.user.name || session.user.email);
+ // }
+ // }, [session]);
- const { id, name, plan, stripeId } = useProject();
- const [showProBanner, setShowProBanner] = useState(false);
- useEffect(() => {
- if (plan) {
- Crisp.session.setData({
- projectId: id,
- projectName: name,
- projectSlug: slug,
- plan,
- ...(stripeId && { stripeId }),
- });
- if (plan === "free" && !Cookies.get("hideProBanner")) {
- Crisp.chat.hide();
- setShowProBanner(true);
- } else {
- Crisp.chat.show();
- setShowProBanner(false);
- }
- }
- }, [plan, id, name, slug, stripeId]);
+ // const { id, name, plan, stripeId } = useProject();
+ // const [showProBanner, setShowProBanner] = useState(false);
+ // useEffect(() => {
+ // if (plan) {
+ // Crisp.session.setData({
+ // projectId: id,
+ // projectName: name,
+ // projectSlug: slug,
+ // plan,
+ // ...(stripeId && { stripeId }),
+ // });
+ // if (plan === "free" && !Cookies.get("hideProBanner")) {
+ // Crisp.chat.hide();
+ // setShowProBanner(true);
+ // } else {
+ // Crisp.chat.show();
+ // setShowProBanner(false);
+ // }
+ // }
+ // }, [plan, id, name, slug, stripeId]);
return (
<div>
<Meta />
- {showProBanner && <ProBanner setShowProBanner={setShowProBanner} />}
+ {/* {showProBanner && <ProBanner setShowProBanner={setShowProBanner} />} */}
<div
className={`min-h-screen w-full ${bgWhite ? "bg-white" : "bg-gray-50"}`}
>
diff --git a/components/shared/badge.tsx b/components/shared/badge.tsx
index 2e0dd6b145..ff49923972 100644
--- a/components/shared/badge.tsx
+++ b/components/shared/badge.tsx
@@ -1,40 +1,46 @@
+import { TagColorProps } from "@/lib/types";
import { truncate } from "@/lib/utils";
import clsx from "clsx";
+import { Tag } from "lucide-react";
export default function Badge({
name,
color,
+ withIcon,
}: {
name: string;
- color: string;
+ color: TagColorProps;
+ withIcon?: boolean;
}) {
return (
<span
className={clsx(
"whitespace-nowrap rounded-md px-2 py-0.5 text-sm",
- color === "gray" && "bg-gray-100 text-gray-600",
+ withIcon && "flex items-center space-x-1.5",
color === "red" && "bg-red-100 text-red-600",
color === "yellow" && "bg-yellow-100 text-yellow-600",
color === "green" && "bg-green-100 text-green-600",
color === "blue" && "bg-blue-100 text-blue-600",
color === "purple" && "bg-purple-100 text-purple-600",
color === "pink" && "bg-pink-100 text-pink-600",
+ color === "brown" && "bg-brown-100 text-brown-600",
)}
>
- {truncate(name || "", 15)}
+ {withIcon && <Tag className="h-3 w-3" />}
+ <p>{truncate(name || "", 15)}</p>
</span>
);
}
export function randomBadgeColor() {
const colors = [
- "gray",
"red",
"yellow",
"green",
"blue",
"purple",
"pink",
+ "brown",
] as const;
return colors[Math.floor(Math.random() * colors.length)];
}
diff --git a/components/shared/modal.tsx b/components/shared/modal.tsx
index 2f617d3d5b..22047a1154 100644
--- a/components/shared/modal.tsx
+++ b/components/shared/modal.tsx
@@ -114,13 +114,10 @@ export default function Modal({
{children}
</motion.div>
{!mobileOnly && (
- <motion.div
+ <div
ref={desktopModalRef}
key="desktop-modal"
- className="fixed inset-0 z-40 hidden min-h-screen items-center justify-center sm:flex"
- initial={{ scale: 0.95 }}
- animate={{ scale: 1 }}
- exit={{ scale: 0.95 }}
+ className="fixed inset-0 z-40 hidden min-h-screen animate-scale-in items-center justify-center sm:flex"
onMouseDown={(e) => {
if (desktopModalRef.current === e.target) {
closeModal(closeWithX);
@@ -128,7 +125,7 @@ export default function Modal({
}}
>
{children}
- </motion.div>
+ </div>
)}
<motion.div
id="modal-backdrop"
diff --git a/lib/constants/index.ts b/lib/constants/index.ts
index 6f8132a52d..3edc450e89 100644
--- a/lib/constants/index.ts
+++ b/lib/constants/index.ts
@@ -69,6 +69,7 @@ export const APP_HOSTNAMES = new Set([
export const DEFAULT_REDIRECTS = {
home: "https://dub.sh",
+ dub: "https://dub.sh",
signin: "https://app.dub.sh/login",
login: "https://app.dub.sh/login",
register: "https://app.dub.sh/register",
diff --git a/lib/swr/use-tags.ts b/lib/swr/use-tags.ts
index f40b504fc7..1a33b636ed 100644
--- a/lib/swr/use-tags.ts
+++ b/lib/swr/use-tags.ts
@@ -8,7 +8,7 @@ export default function useTags() {
const { slug } = router.query as { slug?: string };
const { data: tags, isValidating } = useSWR<TagProps[]>(
- router.isReady && `/api/projects/${slug}/tags`,
+ slug && `/api/projects/${slug}/tags`,
fetcher,
{
dedupingInterval: 30000,
diff --git a/lib/types.ts b/lib/types.ts
index f564d86fb9..98f9466580 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -32,9 +32,18 @@ export interface LinkProps {
export interface TagProps {
id: string;
name: string;
- color: string;
+ color: TagColorProps;
}
+export type TagColorProps =
+ | "red"
+ | "yellow"
+ | "green"
+ | "blue"
+ | "purple"
+ | "pink"
+ | "brown";
+
export type PlanProps = "free" | "pro" | "enterprise";
export interface ProjectProps {
diff --git a/next.config.js b/next.config.js
index 951e78db42..7f65b37bd1 100644
--- a/next.config.js
+++ b/next.config.js
@@ -12,6 +12,7 @@ const nextConfig = {
"res.cloudinary.com",
"pbs.twimg.com",
"d2vwwcvoksz7ty.cloudfront.net",
+ "media.cleanshot.cloud",
],
},
async headers() {
diff --git a/pages/api/links/[key]/tag.ts b/pages/api/links/[key]/tag.ts
index 51400eb962..c7ebc3bb35 100644
--- a/pages/api/links/[key]/tag.ts
+++ b/pages/api/links/[key]/tag.ts
@@ -36,8 +36,21 @@ export default withLinksAuth(async (req, res, _session, project, domain) => {
},
});
return res.status(200).json(response);
+ } else if (req.method === "DELETE") {
+ const response = await prisma.link.update({
+ where: {
+ domain_key: {
+ domain: domain || "dub.sh",
+ key,
+ },
+ },
+ data: {
+ tagId: null,
+ },
+ });
+ return res.status(200).json(response);
} else {
- res.setHeader("Allow", ["POST"]);
+ res.setHeader("Allow", ["POST", "DELETE"]);
return res.status(405).end(`Method ${req.method} Not Allowed`);
}
});
diff --git a/pages/api/projects/[slug]/invite/index.tsx b/pages/api/projects/[slug]/invite/index.tsx
index 8a51c00ab5..a6517c2e21 100644
--- a/pages/api/projects/[slug]/invite/index.tsx
+++ b/pages/api/projects/[slug]/invite/index.tsx
@@ -71,7 +71,7 @@ export default withProjectAuth(async (req, res, project) => {
});
const params = new URLSearchParams({
- callbackUrl: `${process.env.NEXTAUTH_URL}/${slug}`,
+ callbackUrl: `${process.env.NEXTAUTH_URL}/${project.slug}`,
email,
token,
});
diff --git a/posts/changelog/introducing-tags.mdx b/posts/changelog/introducing-tags.mdx
new file mode 100644
index 0000000000..70992886a0
--- /dev/null
+++ b/posts/changelog/introducing-tags.mdx
@@ -0,0 +1,9 @@
+---
+title: Introducing Tags
+publishedAt: 2023-05-21
+summary: "Introducing Tags on Dub. With tags, you can now organize your links into categories, and filter your links by tags."
+image: "https://media.cleanshot.cloud/media/42580/ZotuXjFHBaeAcsTIP3j8cYNJi51F7k841VTxihnn.jpeg?Expires=1684728914&Signature=TTIm5To2eQxfdGexRMd4caUlpoY9859zfRjBX~l518OJmfQojXsPYyRm8Lu-y9Zlc-vvAff~mZAlBvPJuO1w9fui327LGf0QJ8ounnSh0S1ptYkyroMNKSp0QqzMo6mpHLflr3FoOCMylSKdtjr-lLpXNhl4nicy2yx8sm1cYczyQfWJ0lhYf3p3NKQq-TvCmI0d9NbMN2SQ6r0pBgqNnG8tLdf7oytSGytIPYr41PbnHU62mCt3uWgGVqZOvtkVTGmafeuYGUeAAlSPnMg2QvO2abo24cWP7ZsT6YFyYdHzloK4fXFSp~dyNl3sfV8WehkF~fDxYx98FZ8hrfpKYg__&Key-Pair-Id=K269JMAT9ZF4GZ"
+author: "steventey"
+---
+
+Introducing Tags on Dub. With tags, you can now organize your links into categories, and filter your links by tags.
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index ffca8b9c12..228cd166e3 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -214,7 +214,7 @@ model Link {
model Tag {
id String @id @default(cuid())
name String
- color String @default("gray")
+ color String @default("blue")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
project Project @relation(fields: [projectId], references: [id], onUpdate: Cascade, onDelete: Cascade)
diff --git a/tailwind.config.js b/tailwind.config.js
index 445540bb23..7f71522649 100644
--- a/tailwind.config.js
+++ b/tailwind.config.js
@@ -17,8 +17,13 @@ module.exports = {
default: ["var(--font-inter)", "system-ui", "sans-serif"],
},
animation: {
+ // Modal
+ "scale-in": "scale-in 0.2s cubic-bezier(0.16, 1, 0.3, 1)",
// Input Select
- "slide-down": "slide-down 0.2s cubic-bezier(0.16, 1, 0.3, 1)",
+ "input-select-slide-up":
+ "input-select-slide-up 0.2s cubic-bezier(0.16, 1, 0.3, 1)",
+ "input-select-slide-down":
+ "input-select-slide-down 0.2s cubic-bezier(0.16, 1, 0.3, 1)",
// Tooltip
"slide-up-fade": "slide-up-fade 0.4s cubic-bezier(0.16, 1, 0.3, 1)",
"slide-right-fade":
@@ -32,16 +37,23 @@ module.exports = {
"exit-to-left": "exit-to-left 0.25s ease",
"scale-in-content": "scale-in-content 0.2s ease",
"scale-out-content": "scale-out-content 0.2s ease",
- "fade-in": "fade-in 0.2s ease",
- "fade-out": "fade-out 0.2s ease",
// Custom wiggle animation
wiggle: "wiggle 0.75s infinite",
},
keyframes: {
+ // Modal
+ "scale-in": {
+ "0%": { transform: "scale(0.95)" },
+ "100%": { transform: "scale(1)" },
+ },
// Input Select
- "slide-down": {
- "0%": { transform: "translateY(-8px)" },
- "100%": { transform: "translateY(0)" },
+ "input-select-slide-up": {
+ "0%": { transform: "translateY(-342px)" },
+ "100%": { transform: "translateY(-350px)" },
+ },
+ "input-select-slide-down": {
+ "0%": { transform: "translateY(0px)" },
+ "100%": { transform: "translateY(8px)" },
},
// Tooltip
"slide-up-fade": {