-
Notifications
You must be signed in to change notification settings - Fork 995
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RSC: Include routing in initial RSC example app (#9611)
- Loading branch information
Showing
13 changed files
with
271 additions
and
25 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
2 changes: 2 additions & 0 deletions
2
packages/cli/src/commands/experimental/templates/rsc/AboutPage.css.template
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,2 @@ | ||
.about-page { | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/cli/src/commands/experimental/templates/rsc/AboutPage.tsx.template
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,26 @@ | ||
import { Assets } from '@redwoodjs/vite/assets' | ||
import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal' | ||
|
||
import { Counter } from './Counter' | ||
|
||
import './AboutPage.css' | ||
|
||
// TODO (RSC) Something like this will probably be needed | ||
// const RwRscGlobal = import.meta.env.PROD ? ProdRwRscServerGlobal : DevRwRscServerGlobal; | ||
|
||
globalThis.rwRscGlobal = new ProdRwRscServerGlobal() | ||
|
||
const AboutPage = () => { | ||
return ( | ||
<div className="about-page"> | ||
{/* TODO (RSC) <Assets /> should be part of the router later */} | ||
<Assets /> | ||
<div style={{ border: '3px red dashed', margin: '1em', padding: '1em' }}> | ||
<h1>About Redwood</h1> | ||
<Counter /> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default AboutPage |
3 changes: 0 additions & 3 deletions
3
packages/cli/src/commands/experimental/templates/rsc/App.css.template
This file was deleted.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
packages/cli/src/commands/experimental/templates/rsc/HomePage.css.template
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,2 @@ | ||
.home-page { | ||
} |
File renamed without changes.
14 changes: 7 additions & 7 deletions
14
...perimental/templates/rsc/App.tsx.template → ...ental/templates/rsc/HomePage.tsx.template
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 |
---|---|---|
@@ -1,29 +1,29 @@ | ||
import { Assets } from '@redwoodjs/vite/assets' | ||
import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal' | ||
|
||
// @ts-expect-error no types | ||
import styles from './App.module.css' | ||
import { Counter } from './Counter' | ||
// @ts-expect-error no types | ||
import styles from './HomePage.module.css' | ||
|
||
import './App.css' | ||
import './HomePage.css' | ||
|
||
// TODO (RSC) Something like this will probably be needed | ||
// const RwRscGlobal = import.meta.env.PROD ? ProdRwRscServerGlobal : DevRwRscServerGlobal; | ||
|
||
globalThis.rwRscGlobal = new ProdRwRscServerGlobal() | ||
|
||
const App = ({ name = 'Anonymous' }) => { | ||
const HomePage = ({ name = 'Anonymous' }) => { | ||
return ( | ||
<> | ||
<div className="home-page"> | ||
{/* TODO (RSC) <Assets /> should be part of the router later */} | ||
<Assets /> | ||
<div style={{ border: '3px red dashed', margin: '1em', padding: '1em' }}> | ||
<h1 className={styles.title}>Hello {name}!!</h1> | ||
<h3>This is a server component.</h3> | ||
<Counter /> | ||
</div> | ||
</> | ||
</div> | ||
) | ||
} | ||
|
||
export default App | ||
export default HomePage |
32 changes: 32 additions & 0 deletions
32
packages/cli/src/commands/experimental/templates/rsc/NavigationLayout.css.template
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,32 @@ | ||
.navigation-layout { | ||
& nav { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 10px; | ||
background-color: color-mix(in srgb, yellow 50%, transparent); | ||
border-bottom: 2px dashed color-mix(in srgb, yellow 90%, black); | ||
} | ||
|
||
& ul { | ||
list-style: none; | ||
display: flex; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
& li { | ||
margin-right: 10px; | ||
} | ||
|
||
& a { | ||
text-decoration: none; | ||
color: #333; | ||
padding: 5px; | ||
border-bottom: 2px solid transparent; | ||
} | ||
|
||
& a:hover { | ||
border-bottom: 2px solid #333; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/cli/src/commands/experimental/templates/rsc/NavigationLayout.tsx.template
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,27 @@ | ||
import { Link, routes } from '@redwoodjs/router' | ||
|
||
import './NavigationLayout.css' | ||
|
||
type NavigationLayoutProps = { | ||
children?: React.ReactNode | ||
} | ||
|
||
const NavigationLayout = ({ children }: NavigationLayoutProps) => { | ||
return ( | ||
<div className="navigation-layout"> | ||
<nav> | ||
<ul> | ||
<li> | ||
<Link to={routes.home()}>Home</Link> | ||
</li> | ||
<li> | ||
<Link to={routes.about()}>About</Link> | ||
</li> | ||
</ul> | ||
</nav> | ||
<main>{children}</main> | ||
</div> | ||
) | ||
} | ||
|
||
export default NavigationLayout |
22 changes: 22 additions & 0 deletions
22
packages/cli/src/commands/experimental/templates/rsc/Routes.tsx.template
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,22 @@ | ||
// In this file, all Page components from 'src/pages` are auto-imported. Nested | ||
// directories are supported, and should be uppercase. Each subdirectory will be | ||
// prepended onto the component name. | ||
// | ||
// Examples: | ||
// | ||
// 'src/pages/HomePage/HomePage.js' -> HomePage | ||
// 'src/pages/Admin/BooksPage/BooksPage.js' -> AdminBooksPage | ||
|
||
import { Router, Route } from '@redwoodjs/router' | ||
|
||
const Routes = () => { | ||
return ( | ||
<Router> | ||
<Route path="/about" page={AboutPage} name="about" /> | ||
<Route path="/" page={HomePage} name="home" /> | ||
<Route notfound page={NotFoundPage} /> | ||
</Router> | ||
) | ||
} | ||
|
||
export default Routes |
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
22 changes: 20 additions & 2 deletions
22
packages/cli/src/commands/experimental/templates/rsc/entry.client.tsx.template
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 |
---|---|---|
@@ -1,10 +1,28 @@ | ||
import { createRoot } from 'react-dom/client' | ||
|
||
import { Route, Router, Set } from '@redwoodjs/router' | ||
import { serve } from '@redwoodjs/vite/client' | ||
|
||
import NavigationLayout from './layouts/NavigationLayout/NavigationLayout' | ||
import NotFoundPage from './pages/NotFoundPage/NotFoundPage' | ||
|
||
const redwoodAppElement = document.getElementById('redwood-app') | ||
|
||
const App = serve('App') | ||
const AboutPage = serve('AboutPage') | ||
const HomePage = serve('HomePage') | ||
|
||
const root = createRoot(redwoodAppElement) | ||
root.render(<App name="Redwood RSCs" />) | ||
|
||
const App = () => { | ||
return ( | ||
<Router> | ||
<Set wrap={NavigationLayout}> | ||
<Route path="/" page={HomePage} name="home" /> | ||
<Route path="/about" page={AboutPage} name="about" /> | ||
</Set> | ||
<Route notfound page={NotFoundPage} /> | ||
</Router> | ||
) | ||
} | ||
|
||
root.render(<App />) |
4 changes: 4 additions & 0 deletions
4
packages/cli/src/commands/experimental/templates/rsc/index.css.template
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,4 @@ | ||
html, body { | ||
margin: 0; | ||
padding: 0; | ||
} |