-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moving outerbase router to dedicated outerbase route
- Loading branch information
Showing
26 changed files
with
379 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { getDatabaseIcon } from "@/components/resource-card/utils"; | ||
import { Button, buttonVariants } from "@/components/ui/button"; | ||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
} from "@/components/ui/popover"; | ||
import { cn } from "@/lib/utils"; | ||
import { useParams, useRouter } from "next/navigation"; | ||
import { useMemo, useState } from "react"; | ||
import { useWorkspaces } from "./workspace-provider"; | ||
|
||
function WorkspaceSelector() { | ||
const router = useRouter(); | ||
const { workspaces } = useWorkspaces(); | ||
const { workspaceId } = useParams<{ workspaceId: string }>(); | ||
const [selectedWorkspaceId, setSelectedWorkspaceId] = useState(workspaceId); | ||
|
||
const selectedWorkspace = workspaces.find( | ||
(w) => w.id === selectedWorkspaceId || w.short_name === selectedWorkspaceId | ||
); | ||
|
||
const bases = useMemo(() => { | ||
const currentBases = [...(selectedWorkspace?.bases ?? [])]; | ||
currentBases.sort((a, b) => a.name.localeCompare(b.name)); | ||
return currentBases; | ||
}, [selectedWorkspace]); | ||
|
||
return ( | ||
<div className="flex h-[400px] w-[500px]"> | ||
<div className="flex h-full w-1/2 flex-col gap-0.5 border-r p-1"> | ||
<label className="text-muted-foreground mt-1 px-3 py-1 text-xs font-bold"> | ||
WORKSPACES | ||
</label> | ||
{workspaces.map((workspace) => ( | ||
<div | ||
onClick={() => router.push(`/w/${workspace.short_name}`)} | ||
key={workspace.id} | ||
onMouseEnter={() => setSelectedWorkspaceId(workspace.short_name)} | ||
className={cn( | ||
buttonVariants({ variant: "ghost", size: "sm" }), | ||
"cursor-pointer justify-start py-0.5" | ||
)} | ||
> | ||
{workspace.name} | ||
</div> | ||
))} | ||
</div> | ||
<div className="flex h-full w-1/2 flex-col gap-0.5 overflow-y-auto p-1 text-sm"> | ||
<label className="text-muted-foreground mt-1 px-3 py-1 text-xs font-bold"> | ||
BASES | ||
</label> | ||
{bases.map((base) => { | ||
const IconComponent = getDatabaseIcon(base.sources[0]?.type); | ||
|
||
return ( | ||
<div | ||
onClick={() => | ||
router.push(`/w/${selectedWorkspaceId}/${base.short_name}`, {}) | ||
} | ||
key={base.id} | ||
className={cn( | ||
buttonVariants({ | ||
variant: "ghost", | ||
size: "sm", | ||
}), | ||
"cursor-pointer justify-start p-2" | ||
)} | ||
> | ||
<IconComponent className="mr-2 h-4 w-4" /> | ||
{base.name} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export function NavigationBar() { | ||
return ( | ||
<div className="p-1"> | ||
<Popover open> | ||
<PopoverTrigger asChild> | ||
<Button>Workspace</Button> | ||
</PopoverTrigger> | ||
<PopoverContent className="h-[400px] w-[500px] p-0"> | ||
<WorkspaceSelector /> | ||
</PopoverContent> | ||
</Popover> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use client"; | ||
import { useRouter } from "next/navigation"; | ||
import { createContext, PropsWithChildren, useContext } from "react"; | ||
import useSWR from "swr"; | ||
import { getOuterbaseSession } from "../../outerbase-cloud/api"; | ||
import { | ||
OuterbaseAPISession, | ||
OuterbaseAPIUser, | ||
} from "../../outerbase-cloud/api-type"; | ||
|
||
interface OuterebaseSessionContextProps { | ||
session: OuterbaseAPISession; | ||
user: OuterbaseAPIUser; | ||
} | ||
|
||
const OuterbaseSessionContext = createContext<{ | ||
session: OuterbaseAPISession; | ||
user: OuterbaseAPIUser; | ||
}>({} as OuterebaseSessionContextProps); | ||
|
||
export function useSession() { | ||
return useContext(OuterbaseSessionContext); | ||
} | ||
|
||
export function OuterbaseSessionProvider({ children }: PropsWithChildren) { | ||
const router = useRouter(); | ||
|
||
const { data, isLoading } = useSWR( | ||
"session", | ||
() => { | ||
return getOuterbaseSession(); | ||
}, | ||
{ | ||
revalidateIfStale: false, | ||
revalidateOnFocus: false, | ||
revalidateOnReconnect: false, | ||
} | ||
); | ||
|
||
if (isLoading) { | ||
return <div>Session Loading...</div>; | ||
} | ||
|
||
if (!data?.session || !data?.user) { | ||
router.push("/signin"); | ||
return <div>Redirecting...</div>; | ||
} | ||
|
||
return ( | ||
<OuterbaseSessionContext.Provider | ||
value={{ session: data?.session, user: data?.user }} | ||
> | ||
{children} | ||
</OuterbaseSessionContext.Provider> | ||
); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { OuterbaseSessionProvider } from "@/app/(outerbase)/session-provider"; | ||
import ThemeLayout from "../../../(theme)/theme_layout"; | ||
import { WorkspaceProvider } from "../../workspace-provider"; | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<ThemeLayout> | ||
<OuterbaseSessionProvider> | ||
<WorkspaceProvider>{children}</WorkspaceProvider> | ||
</OuterbaseSessionProvider> | ||
</ThemeLayout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use client"; | ||
import ClientOnly from "@/components/client-only"; | ||
import WorkspaceListPageClient from "./page-client"; | ||
|
||
export default function WorkspaceListPage() { | ||
return ( | ||
<ClientOnly> | ||
<WorkspaceListPageClient /> | ||
</ClientOnly> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"use client"; | ||
import { getOuterbaseWorkspace } from "@/outerbase-cloud/api"; | ||
import { OuterbaseAPIWorkspace } from "@/outerbase-cloud/api-type"; | ||
import { createContext, PropsWithChildren, useContext } from "react"; | ||
import useSWR from "swr"; | ||
|
||
const WorkspaceContext = createContext<{ | ||
workspaces: OuterbaseAPIWorkspace[]; | ||
loading: boolean; | ||
}>({ workspaces: [], loading: true }); | ||
|
||
export function useWorkspaces() { | ||
return useContext(WorkspaceContext); | ||
} | ||
|
||
export function WorkspaceProvider({ children }: PropsWithChildren) { | ||
const { data, isLoading } = useSWR( | ||
"workspaces", | ||
() => { | ||
return getOuterbaseWorkspace(); | ||
}, | ||
{ | ||
revalidateIfStale: false, | ||
revalidateOnFocus: false, | ||
revalidateOnReconnect: false, | ||
} | ||
); | ||
|
||
return ( | ||
<WorkspaceContext.Provider | ||
value={{ workspaces: data?.items || [], loading: isLoading }} | ||
> | ||
{children} | ||
</WorkspaceContext.Provider> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { BoardSourceDriver } from "@/drivers/board-source/base-source"; | ||
import { createContext, PropsWithChildren } from "react"; | ||
|
||
interface BoardContextProps { | ||
sources?: BoardSourceDriver; | ||
} | ||
|
||
const BoardContext = createContext<BoardContextProps>({}); | ||
|
||
export function BoardProvider({ | ||
children, | ||
sources, | ||
}: PropsWithChildren<BoardContextProps>) { | ||
return ( | ||
<BoardContext.Provider value={{ sources }}> | ||
{children} | ||
</BoardContext.Provider> | ||
); | ||
} |
Oops, something went wrong.