Skip to content

Commit 8950830

Browse files
authored
chore(kitchensink): all of kitchensink should be under a single SanityApp (#375)
1 parent f13265a commit 8950830

File tree

11 files changed

+43
-295
lines changed

11 files changed

+43
-295
lines changed

apps/kitchensink-react/src/App.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
1+
import {SanityConfig} from '@sanity/sdk'
2+
import {SanityApp} from '@sanity/sdk-react'
13
import {Spinner, ThemeProvider} from '@sanity/ui'
24
import {buildTheme} from '@sanity/ui/theme'
3-
import {type JSX, Suspense} from 'react'
5+
import {type JSX} from 'react'
46
import {BrowserRouter} from 'react-router'
57

68
import {AppRoutes} from './AppRoutes'
79

810
const theme = buildTheme({})
911

12+
const sanityConfigs: SanityConfig[] = [
13+
{
14+
projectId: 'ppsg7ml5',
15+
dataset: 'test',
16+
},
17+
{
18+
projectId: 'ezwd8xes',
19+
dataset: 'production',
20+
},
21+
]
22+
1023
export function App(): JSX.Element {
1124
return (
1225
<ThemeProvider theme={theme}>
13-
<Suspense fallback={<Spinner />}>
26+
<SanityApp sanityConfigs={sanityConfigs} fallback={<Spinner />}>
1427
<BrowserRouter>
1528
<AppRoutes />
1629
</BrowserRouter>
17-
</Suspense>
30+
</SanityApp>
1831
</ThemeProvider>
1932
)
2033
}
Lines changed: 23 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import {SanityApp} from '@sanity/sdk-react'
2-
import {Spinner} from '@sanity/ui'
31
import {type JSX} from 'react'
42
import {Route, Routes} from 'react-router'
53

@@ -12,15 +10,11 @@ import {DocumentListRoute} from './DocumentCollection/DocumentListRoute'
1210
import {DocumentProjectionRoute} from './DocumentCollection/DocumentProjectionRoute'
1311
import {MultiResourceRoute} from './DocumentCollection/MultiResourceRoute'
1412
import {SearchRoute} from './DocumentCollection/SearchRoute'
15-
import Home from './Home'
1613
import {ProjectAuthHome} from './ProjectAuthentication/ProjectAuthHome'
17-
import {ProjectInstanceWrapper} from './ProjectAuthentication/ProjectInstanceWrapper'
1814
import {ProtectedRoute} from './ProtectedRoute'
1915
import {DashboardContextRoute} from './routes/DashboardContextRoute'
2016
import {DashboardWorkspacesRoute} from './routes/DashboardWorkspacesRoute'
2117
import {UsersRoute} from './routes/UsersRoute'
22-
import {UnauthenticatedHome} from './Unauthenticated/UnauthenticatedHome'
23-
import {UnauthenticatedInstanceWrapper} from './Unauthenticated/UnauthenticatedInstanceWrapper'
2418

2519
const documentCollectionRoutes = [
2620
{
@@ -76,60 +70,34 @@ const frameRoutes = [1, 2, 3].map((frameNum) => ({
7670
export function AppRoutes(): JSX.Element {
7771
return (
7872
<Routes>
79-
<Route path="/" element={<Home />} />
80-
81-
<Route path="/authenticated" element={<ProjectInstanceWrapper />}>
82-
<Route
83-
index
84-
element={
85-
<ProjectAuthHome
86-
routes={[...documentCollectionRoutes, ...dashboardInteractionRoutes]}
87-
/>
88-
}
89-
/>
90-
<Route element={<ProtectedRoute subPath="/authenticated" />}>
73+
<Route path="/">
74+
<Route element={<ProtectedRoute subPath="/" />}>
75+
<Route
76+
index
77+
element={
78+
<ProjectAuthHome
79+
routes={[
80+
...documentCollectionRoutes,
81+
...dashboardInteractionRoutes,
82+
{
83+
path: 'comlink-demo',
84+
element: <ParentApp />,
85+
},
86+
]}
87+
/>
88+
}
89+
/>
9190
{documentCollectionRoutes.map((route) => (
9291
<Route key={route.path} path={route.path} element={route.element} />
9392
))}
93+
<Route path="comlink-demo" element={<ParentApp />} />
94+
</Route>
95+
<Route path="comlink-demo">
96+
{frameRoutes.map((route) => (
97+
<Route key={route.path} path={route.path} element={route.element} />
98+
))}
9499
</Route>
95100
</Route>
96-
97-
<Route path="/comlink-demo" element={<ProjectInstanceWrapper />}>
98-
<Route index element={<ParentApp />} />
99-
{frameRoutes.map((route) => (
100-
<Route key={route.path} path={route.path} element={route.element} />
101-
))}
102-
</Route>
103-
104-
<Route path="/unauthenticated" element={<UnauthenticatedInstanceWrapper />}>
105-
<Route
106-
index
107-
element={
108-
<UnauthenticatedHome
109-
routes={[...documentCollectionRoutes, ...dashboardInteractionRoutes]}
110-
/>
111-
}
112-
/>
113-
{documentCollectionRoutes.map((route) => (
114-
<Route key={route.path} path={route.path} element={route.element} />
115-
))}
116-
{dashboardInteractionRoutes.map((route) => (
117-
<Route key={route.path} path={route.path} element={route.element} />
118-
))}
119-
</Route>
120-
121-
<Route
122-
path="/sanity-app"
123-
index
124-
element={
125-
<SanityApp
126-
sanityConfigs={[{projectId: 'ppsg7ml5', dataset: 'test'}]}
127-
fallback={<Spinner />}
128-
>
129-
<div>Welcome to the Sanity App</div>
130-
</SanityApp>
131-
}
132-
/>
133101
</Routes>
134102
)
135103
}

apps/kitchensink-react/src/Comlink/ParentApp.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,7 @@ const ParentApp = (): ReactElement => {
8585
const frames = [1, 2, 3]
8686

8787
return (
88-
<PageLayout
89-
title="Comlink demo"
90-
subtitle="Explore comlink connections and fetch operations"
91-
homePath="/comlink-demo"
92-
homeText="Comlink Demo Home"
93-
>
88+
<PageLayout title="Comlink demo" subtitle="Explore comlink connections and fetch operations">
9489
<Stack space={4} height="fill">
9590
<Box flex={1}>
9691
<Box display="flex" height="fill">

apps/kitchensink-react/src/Home.tsx

Lines changed: 0 additions & 81 deletions
This file was deleted.

apps/kitchensink-react/src/ProjectAuthentication/ProjectAuthHome.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ export function ProjectAuthHome({
1111
routes: {path: string; element: JSX.Element}[]
1212
}): JSX.Element {
1313
return (
14-
<PageLayout
15-
title="Authenticated"
16-
subtitle="Explore authentication examples and components"
17-
homePath="/project-auth"
18-
homeText="Authenticated Home"
19-
>
14+
<PageLayout title="Authenticated" subtitle="Explore authentication examples and components">
2015
<AuthBoundary>
2116
<Flex direction="column" gap={3}>
2217
{routes.map((route) => (

apps/kitchensink-react/src/ProjectAuthentication/ProjectInstanceWrapper.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

apps/kitchensink-react/src/ProtectedRoute.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import {useAuthState, useCurrentUser, useLogOut} from '@sanity/sdk-react'
1+
import {useAuthState, useCurrentUser} from '@sanity/sdk-react'
22
import {Avatar, Box, Button, Card, Flex} from '@sanity/ui'
33
import {type JSX} from 'react'
44
import {Link, Navigate, Outlet} from 'react-router'
55

66
export function ProtectedRoute({subPath}: {subPath: string}): JSX.Element {
77
const authState = useAuthState()
88
const currentUser = useCurrentUser()
9-
const logout = useLogOut()
109

1110
if (authState.type !== 'logged-in') {
1211
return <Navigate to={subPath} replace />
@@ -20,17 +19,13 @@ export function ProtectedRoute({subPath}: {subPath: string}): JSX.Element {
2019
<Link to="/" style={{textDecoration: 'none'}}>
2120
<Button mode="ghost" tone="primary" text="← Kitchen Sink Home" />
2221
</Link>
23-
<Link to={subPath} style={{textDecoration: 'none'}}>
24-
<Button mode="ghost" tone="primary" text="Home" />
25-
</Link>
2622
</Flex>
2723

2824
<Flex align="center" gap={3}>
2925
<Avatar src={currentUser?.profileImage} size={1} />
3026
<Box as="span" style={{color: '#6e7683'}}>
3127
{currentUser?.name}
3228
</Box>
33-
<Button mode="ghost" tone="critical" onClick={() => logout()} text="Log out" />
3429
</Flex>
3530
</Flex>
3631
</Card>

apps/kitchensink-react/src/Unauthenticated/UnauthenticatedHome.tsx

Lines changed: 0 additions & 44 deletions
This file was deleted.

apps/kitchensink-react/src/Unauthenticated/UnauthenticatedInstanceWrapper.tsx

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)