-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RSC: Add MultiCellPage to test fixture (#10029)
- Loading branch information
Showing
9 changed files
with
121 additions
and
0 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
4 changes: 4 additions & 0 deletions
4
...l-packages-and-cells/web/src/components/RandomNumberServerCell/RandomNumberServerCell.css
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 @@ | ||
.random-number-server-cell { | ||
border: 1px dotted gray; | ||
padding: 1em; | ||
} |
38 changes: 38 additions & 0 deletions
38
...l-packages-and-cells/web/src/components/RandomNumberServerCell/RandomNumberServerCell.tsx
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,38 @@ | ||
import type { CellSuccessProps, CellFailureProps } from '@redwoodjs/web' | ||
|
||
import { globalValues } from './actions' | ||
|
||
import './RandomNumberServerCell.css' | ||
|
||
interface DataArgs { | ||
global?: boolean | ||
} | ||
|
||
export const data = async ({ global }: DataArgs) => { | ||
const num = Math.round(Math.random() * 1000) | ||
if (global) { | ||
globalValues.num ??= num | ||
} | ||
|
||
return { num: global ? globalValues.num : num } | ||
} | ||
|
||
export const Loading = () => <div>Loading...</div> | ||
|
||
export const Empty = () => <div>Empty</div> | ||
|
||
export const Failure = ({ error }: CellFailureProps) => ( | ||
<div className="rw-cell-error">{error?.message}</div> | ||
) | ||
|
||
type SuccessProps = CellSuccessProps<Awaited<ReturnType<typeof data>>> & | ||
DataArgs | ||
|
||
export const Success = ({ num, global }: SuccessProps) => { | ||
return ( | ||
<div className="random-number-server-cell"> | ||
<h2>RandomNumberServerCell{global && ' (global)'}</h2> | ||
<div>{num}</div> | ||
</div> | ||
) | ||
} |
16 changes: 16 additions & 0 deletions
16
...ernal-packages-and-cells/web/src/components/RandomNumberServerCell/UpdateRandomButton.tsx
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,16 @@ | ||
'use client' | ||
|
||
import { updateRandom } from './actions.js' | ||
|
||
export const UpdateRandomButton = () => { | ||
return ( | ||
<button | ||
onClick={async () => { | ||
const res = await updateRandom() | ||
console.log('res', res) | ||
}} | ||
> | ||
Update | ||
</button> | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
...ject-rsc-external-packages-and-cells/web/src/components/RandomNumberServerCell/actions.ts
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 server' | ||
|
||
export const globalValues = { | ||
num: undefined as number, | ||
} | ||
|
||
export async function updateRandom() { | ||
globalValues.num = Math.round(Math.random() * 1000) | ||
|
||
return globalValues.num | ||
} |
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
9 changes: 9 additions & 0 deletions
9
...est-project-rsc-external-packages-and-cells/web/src/pages/MultiCellPage/MultiCellPage.css
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,9 @@ | ||
.multi-cell-page { | ||
padding: 1em; | ||
} | ||
|
||
.multi-cell-page-grid { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr; | ||
gap: 1em; | ||
} |
36 changes: 36 additions & 0 deletions
36
...est-project-rsc-external-packages-and-cells/web/src/pages/MultiCellPage/MultiCellPage.tsx
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 @@ | ||
import { Assets } from '@redwoodjs/vite/assets' | ||
import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal' | ||
|
||
import { updateRandom } from 'src/components/RandomNumberServerCell/actions' | ||
import RandomNumberServerCell from 'src/components/RandomNumberServerCell/RandomNumberServerCell' | ||
import { UpdateRandomButton } from 'src/components/RandomNumberServerCell/UpdateRandomButton' | ||
|
||
import './MultiCellPage.css' | ||
|
||
// TODO (RSC) Something like this will probably be needed | ||
// const RwRscGlobal = import.meta.env.PROD ? ProdRwRscServerGlobal : DevRwRscServerGlobal; | ||
|
||
globalThis.rwRscGlobal = new ProdRwRscServerGlobal() | ||
|
||
const MultiCellPage = () => { | ||
return ( | ||
<div className="multi-cell-page"> | ||
{/* TODO (RSC) <Assets /> should be part of the router later */} | ||
<Assets /> | ||
<div className="multi-cell-page-grid"> | ||
<RandomNumberServerCell /> | ||
<RandomNumberServerCell /> | ||
<RandomNumberServerCell global /> | ||
<RandomNumberServerCell global /> | ||
</div> | ||
<h3>Update Random Number (client)</h3> | ||
<UpdateRandomButton /> | ||
<h3>Update Random Number (server)</h3> | ||
<form action={updateRandom}> | ||
<button type="submit">Update</button> | ||
</form> | ||
</div> | ||
) | ||
} | ||
|
||
export default MultiCellPage |