Skip to content

Commit d005281

Browse files
committed
add resource search and filter by resource type
1 parent 6234f58 commit d005281

File tree

3 files changed

+75
-36
lines changed

3 files changed

+75
-36
lines changed

src/app/(outerbase)/auth-provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function AuthProvider({ children }: PropsWithChildren) {
1313
if (isLoading) return;
1414
if (!session?.session || !session?.user) {
1515
localStorage.setItem("continue-redirect", pathname);
16-
router.push("/signin");
16+
router.replace("/signin");
1717
}
1818
}, [isLoading, session, pathname, router]);
1919

src/app/(outerbase)/nav.tsx

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,36 @@ import {
1414
SquaresFour,
1515
} from "@phosphor-icons/react";
1616
import Link from "next/link";
17-
import { useParams, useRouter } from "next/navigation";
17+
import { useParams, usePathname, useRouter } from "next/navigation";
1818
import { useMemo, useState } from "react";
1919
import NavigationProfile from "./nav-profile";
20+
import { useSession } from "./session-provider";
2021
import { useWorkspaces } from "./workspace-provider";
2122

2223
export function NavigationBar() {
2324
const { currentWorkspace } = useWorkspaces();
2425
const { workspaceId } = useParams<{ workspaceId: string }>();
26+
const pathname = usePathname();
27+
const { session } = useSession();
2528

2629
return (
2730
<div className="dark:bg-background relative sticky top-0 z-20 flex h-14 items-center justify-center gap-2 bg-neutral-50 px-2">
2831
<div className="text-primary absolute left-0 flex h-14 items-center pl-2">
29-
<Link href={`/w/${workspaceId}`}>
32+
<Link
33+
href={
34+
pathname !== "/w/local-workspace"
35+
? `/w/${workspaceId}`
36+
: "/w/local-workspace"
37+
}
38+
>
3039
<OuterbaseIcon className="h-8 w-8" />
3140
</Link>
3241

3342
<Popover>
3443
<PopoverTrigger asChild>
3544
<Button variant="ghost">
36-
{currentWorkspace?.name} <CaretUpDown className="ml-2" />
45+
{currentWorkspace?.name ?? "Local"}
46+
<CaretUpDown className="ml-2" />
3747
</Button>
3848
</PopoverTrigger>
3949
<PopoverContent className="h-[400px] w-[500px] p-0" align="start">
@@ -42,42 +52,51 @@ export function NavigationBar() {
4252
</Popover>
4353
</div>
4454

45-
<div className="flex gap-4 text-base">
46-
<Link
47-
href={`/w/${workspaceId}`}
48-
className="flex cursor-pointer items-center gap-1"
49-
>
50-
<GlobeHemisphereEast weight="fill" className="size-5" /> Home
51-
</Link>
52-
<Link
53-
href={`/w/${workspaceId}/settings`}
54-
className="flex cursor-pointer items-center gap-1"
55-
>
56-
<Gear className="size-5" />
57-
Settings
58-
</Link>
59-
<Link
60-
href={`/w/${workspaceId}/billing`}
61-
className="flex cursor-pointer items-center gap-1"
62-
>
63-
<Gear className="size-5" />
64-
Billing
65-
</Link>
66-
</div>
55+
{workspaceId && workspaceId !== "local-workspace" && (
56+
<div className="flex gap-4 text-base">
57+
<Link
58+
href={`/w/${workspaceId}`}
59+
className="flex cursor-pointer items-center gap-1"
60+
>
61+
<GlobeHemisphereEast weight="fill" className="size-5" /> Home
62+
</Link>
63+
<Link
64+
href={`/w/${workspaceId}/settings`}
65+
className="flex cursor-pointer items-center gap-1"
66+
>
67+
<Gear className="size-5" />
68+
Settings
69+
</Link>
70+
<Link
71+
href={`/w/${workspaceId}/billing`}
72+
className="flex cursor-pointer items-center gap-1"
73+
>
74+
<Gear className="size-5" />
75+
Billing
76+
</Link>
77+
</div>
78+
)}
6779

6880
<div className="absolute right-0 flex gap-2 pr-2">
6981
<div className="bg-secondary text-secondary-foreground flex h-9 items-center justify-center rounded-lg border px-4 text-base font-semibold">
7082
Feedback
7183
</div>
7284

7385
<NavigationProfile />
86+
87+
{!session && (
88+
<Button href="/signin" size="lg" as="link">
89+
Sign In
90+
</Button>
91+
)}
7492
</div>
7593
</div>
7694
);
7795
}
7896

7997
function WorkspaceSelector() {
8098
const router = useRouter();
99+
const { session } = useSession();
81100
const { workspaces, currentWorkspace } = useWorkspaces();
82101
const { workspaceId } = useParams<{ workspaceId: string }>();
83102
const [selectedWorkspaceId, setSelectedWorkspaceId] = useState(workspaceId);
@@ -128,7 +147,7 @@ function WorkspaceSelector() {
128147
className="p-4 font-normal"
129148
size="sm"
130149
as="link"
131-
href="/new-workspace"
150+
href={session ? "/new-workspace" : "/signin"}
132151
>
133152
<SquaresFour size={16} /> New Workspace
134153
</Button>

src/app/(outerbase)/w/[workspaceId]/page.tsx

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ export default function WorkspaceListPageClient() {
4848
const router = useRouter();
4949
const { currentWorkspace, refreshWorkspace } = useWorkspaces();
5050
const { workspaceId } = useParams<{ workspaceId: string }>();
51-
const [typeFilter, setTypeFilter] = useState("all");
51+
52+
const [filterType, setFilterType] = useState("all");
53+
const [filterName, setFilterName] = useState("");
5254

5355
useRedirectValidWorkspace();
5456

@@ -85,37 +87,55 @@ export default function WorkspaceListPageClient() {
8587
status: `Last updated ${timeSince(new Date(board?.updated_at ?? ""))} ago`,
8688
}));
8789

88-
const allResources = [...baseResources, ...boardResources];
90+
let allResources = [...baseResources, ...boardResources];
91+
92+
// Apply filters
93+
if (filterName) {
94+
allResources = allResources.filter((resource) =>
95+
resource.name?.toLowerCase().includes(filterName.toLowerCase())
96+
);
97+
}
98+
99+
if (filterType === "base") {
100+
allResources = allResources.filter(
101+
(resource) => resource.type !== "board"
102+
);
103+
} else if (filterType === "board") {
104+
allResources = allResources.filter(
105+
(resource) => resource.type === "board"
106+
);
107+
}
89108

90109
return allResources.sort((a, b) =>
91110
(a.name ?? "").localeCompare(b.name ?? "")
92111
);
93-
}, [currentWorkspace, boards]);
112+
}, [currentWorkspace, boards, filterName, filterType]);
94113

95114
return (
96115
<div className="min-h-screen bg-neutral-50 dark:bg-neutral-950">
97116
<NavigationBar />
98117

99118
<div className="container mx-auto mt-10 p-4">
100-
<div className="mb-12 flex gap-4">
119+
<div className="sticky top-14 z-20 mb-12 flex gap-4 bg-neutral-50 pb-2 dark:bg-neutral-950">
101120
<div className="flex-1">
102121
<Input
103122
preText={<MagnifyingGlass size={16} className="mr-2" />}
104123
size="lg"
105124
placeholder="Search resources..."
106-
onValueChange={() => {}}
125+
onValueChange={setFilterName}
126+
value={filterName}
107127
/>
108128
</div>
109129

110130
<MenuBar
111131
size="lg"
112132
items={[
113133
{ value: "all", content: "All" },
114-
{ value: "bases", content: "Bases" },
115-
{ value: "boards", content: "Boards" },
134+
{ value: "base", content: "Bases" },
135+
{ value: "board", content: "Boards" },
116136
]}
117-
onChange={setTypeFilter}
118-
value={typeFilter}
137+
onChange={setFilterType}
138+
value={filterType}
119139
/>
120140

121141
<MenuBar

0 commit comments

Comments
 (0)