Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 32 additions & 41 deletions apps/web/ui/links/link-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
linksDisplayProperties,
LinksViewMode,
} from "@/lib/links/links-display";
import useWorkspace from "@/lib/swr/use-workspace";
import {
Button,
Popover,
Expand Down Expand Up @@ -37,14 +36,10 @@ export default function LinkDisplay() {
reset,
} = useContext(LinksDisplayContext);

const { isMegaWorkspace } = useWorkspace();

const [openPopover, setOpenPopover] = useState(false);
const { queryParams } = useRouterStuff();

useKeyboardShortcut("a", () => setShowArchived((o) => !o), {
enabled: !isMegaWorkspace,
});
useKeyboardShortcut("a", () => setShowArchived((o) => !o));

return (
<Popover
Expand Down Expand Up @@ -79,44 +74,40 @@ export default function LinkDisplay() {
);
})}
</div>
{!isMegaWorkspace && (
<div className="flex h-16 items-center justify-between gap-2 px-4">
<span className="flex items-center gap-2">
<ArrowsOppositeDirectionY className="h-4 w-4 text-neutral-800" />
Ordering
</span>
<div>
<LinkSort />
</div>
<div className="flex h-16 items-center justify-between gap-2 px-4">
<span className="flex items-center gap-2">
<ArrowsOppositeDirectionY className="h-4 w-4 text-neutral-800" />
Ordering
</span>
<div>
<LinkSort />
</div>
)}
{!isMegaWorkspace && (
<div className="group flex h-16 items-center justify-between gap-2 px-4">
<div className="flex items-center gap-2">
<div className="flex w-6 items-center justify-center">
<BoxArchive className="size-4 text-neutral-800 group-hover:hidden" />
<kbd className="hidden rounded border border-neutral-200 bg-neutral-100 px-2 py-0.5 text-xs font-light text-neutral-500 group-hover:block">
A
</kbd>
</div>
Show archived links
</div>
<div>
<Switch
checked={showArchived}
fn={(checked) => {
setShowArchived(checked);
queryParams({
del: [
"showArchived", // Remove legacy query param
"page", // Reset pagination
],
});
}}
/>
</div>
<div className="group flex h-16 items-center justify-between gap-2 px-4">
<div className="flex items-center gap-2">
<div className="flex w-6 items-center justify-center">
<BoxArchive className="size-4 text-neutral-800 group-hover:hidden" />
<kbd className="hidden rounded border border-neutral-200 bg-neutral-100 px-2 py-0.5 text-xs font-light text-neutral-500 group-hover:block">
A
</kbd>
</div>
Show archived links
</div>
)}
<div>
<Switch
checked={showArchived}
fn={(checked) => {
setShowArchived(checked);
queryParams({
del: [
"showArchived", // Remove legacy query param
"page", // Reset pagination
],
});
}}
/>
</div>
</div>
<div className="p-4">
<span className="text-xs uppercase text-neutral-500">
Display Properties
Expand Down
56 changes: 32 additions & 24 deletions apps/web/ui/links/link-sort.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { linksSortOptions } from "@/lib/links/links-display";
import useWorkspace from "@/lib/swr/use-workspace";
import { IconMenu, Popover, Tick, useRouterStuff } from "@dub/ui";
import { cn } from "@dub/utils";
import { ChevronDown, SortDesc } from "lucide-react";
Expand All @@ -7,6 +8,7 @@ import { LinksDisplayContext } from "./links-display-provider";

export default function LinkSort() {
const { queryParams } = useRouterStuff();
const { isMegaWorkspace } = useWorkspace();

const [openPopover, setOpenPopover] = useState(false);

Expand All @@ -18,30 +20,36 @@ export default function LinkSort() {
<Popover
content={
<div className="w-full p-2 md:w-48">
{linksSortOptions.map(({ display, slug }) => (
<button
key={slug}
onClick={() => {
setSort(slug);
queryParams({
del: [
"sort", // Remove legacy query param
"page", // Reset pagination
],
});
setOpenPopover(false);
}}
className="flex w-full items-center justify-between space-x-2 rounded-md px-1 py-2 hover:bg-neutral-100 active:bg-neutral-200"
>
<IconMenu
text={display}
icon={<SortDesc className="h-4 w-4" />}
/>
{sortBy === slug && (
<Tick className="h-4 w-4" aria-hidden="true" />
)}
</button>
))}
{linksSortOptions
.filter(
({ slug }) =>
// for mega workspaces, we don't show the clicks and last clicked options
!isMegaWorkspace || !["clicks", "lastClicked"].includes(slug),
)
.map(({ display, slug }) => (
<button
key={slug}
onClick={() => {
setSort(slug);
queryParams({
del: [
"sort", // Remove legacy query param
"page", // Reset pagination
],
});
setOpenPopover(false);
}}
className="flex w-full items-center justify-between space-x-2 rounded-md px-1 py-2 hover:bg-neutral-100 active:bg-neutral-200"
>
<IconMenu
text={display}
icon={<SortDesc className="h-4 w-4" />}
/>
{sortBy === slug && (
<Tick className="h-4 w-4" aria-hidden="true" />
)}
</button>
))}
</div>
}
openPopover={openPopover}
Expand Down
1 change: 1 addition & 0 deletions packages/prisma/schema/link.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ model Link {
@@index([projectId, tenantId]) // for filtering by tenantId
@@index([projectId, url(length: 500)]) // for upserting a link by URL
@@index([projectId, folderId, archived, createdAt(sort: Desc)]) // most getLinksForWorkspace queries
@@index([projectId, folderId, archived, saleAmount(sort: Desc)]) // getLinksForWorkspace queries sorted by saleAmount
@@index([programId, partnerId]) // for getting a referral link (programId + partnerId)
@@index(partnerId) // for getting links by partnerId
@@index([domain, createdAt]) // for bulk link deletion workflows (by domain) + deleting old short-lived links
Expand Down
Loading