initial implementation
This commit is contained in:
@@ -56,6 +56,7 @@ const Routes = () => {
|
||||
<Route path="/u/{userName}" page={UserPage} name="user" />
|
||||
<Route path="/u/{userName}/{projectTitle}" page={ProjectPage} name="project" />
|
||||
<Route path="/u/{userName}/{projectTitle}/ide" page={IdeProjectPage} name="ide" />
|
||||
<Route path="/u/{userName}/{projectTitle}/embed" page={EmbedProjectPage} name="embed" />
|
||||
<Route path="/u/{userName}/{projectTitle}/social-card" page={SocialCardPage} name="socialCard" />
|
||||
|
||||
<Private unauthenticated="home" role="admin">
|
||||
|
||||
32
app/web/src/components/EmbedProject/EmbedProject.tsx
Normal file
32
app/web/src/components/EmbedProject/EmbedProject.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import Seo from 'src/components/Seo/Seo'
|
||||
import IdeViewer from 'src/components/IdeViewer/IdeViewer'
|
||||
import { useIdeState } from 'src/helpers/hooks/useIdeState'
|
||||
import type { Project } from 'src/components/EmbedProjectCell/EmbedProjectCell'
|
||||
import { IdeContext } from 'src/helpers/hooks/useIdeContext'
|
||||
import { use3dViewerResize } from 'src/helpers/hooks/use3dViewerResize'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
|
||||
interface Props {
|
||||
project?: Project
|
||||
}
|
||||
|
||||
const EmbedProject = ({ project }: Props) => {
|
||||
const [state, thunkDispatch] = useIdeState()
|
||||
const { viewerDomRef, handleViewerSizeUpdate } = use3dViewerResize()
|
||||
|
||||
useEffect(() => {
|
||||
console.log({ rect: viewerDomRef.current.getBoundingClientRect(), status: 'uh what?'})
|
||||
handleViewerSizeUpdate()
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className="h-screen flex flex-col" ref={viewerDomRef} >
|
||||
<IdeContext.Provider value={{ state, thunkDispatch, project }}>
|
||||
<IdeViewer />
|
||||
</IdeContext.Provider>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default EmbedProject
|
||||
@@ -0,0 +1,6 @@
|
||||
// Define your own mock data here:
|
||||
export const standard = (/* vars, { ctx, req } */) => ({
|
||||
ideProject: {
|
||||
id: 42,
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Loading, Empty, Success } from './EmbedProjectCell'
|
||||
import { standard } from './EmbedProjectCell.mock'
|
||||
|
||||
export const loading = () => {
|
||||
return Loading ? <Loading /> : null
|
||||
}
|
||||
|
||||
export const empty = () => {
|
||||
return Empty ? <Empty /> : null
|
||||
}
|
||||
|
||||
export const success = () => {
|
||||
return Success ? <Success {...standard()} /> : null
|
||||
}
|
||||
|
||||
export default { title: 'Cells/IdeProjectCell' }
|
||||
@@ -0,0 +1,21 @@
|
||||
import { render, screen } from '@redwoodjs/testing'
|
||||
import { Loading, Empty, Success } from './EmbedProjectCell'
|
||||
import { standard } from './EmbedProjectCell.mock'
|
||||
|
||||
describe('IdeProjectCell', () => {
|
||||
test('Loading renders successfully', () => {
|
||||
render(<Loading />)
|
||||
// Use screen.debug() to see output
|
||||
expect(screen.getByText('Loading...')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('Empty renders successfully', async () => {
|
||||
render(<Empty />)
|
||||
expect(screen.getByText('Empty')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('Success renders successfully', async () => {
|
||||
render(<Success ideProject={standard().ideProject} />)
|
||||
expect(screen.getByText(/42/i)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
71
app/web/src/components/EmbedProjectCell/EmbedProjectCell.tsx
Normal file
71
app/web/src/components/EmbedProjectCell/EmbedProjectCell.tsx
Normal file
@@ -0,0 +1,71 @@
|
||||
import useUser from 'src/helpers/hooks/useUser'
|
||||
import EmbedProject from 'src/components/EmbedProject/EmbedProject'
|
||||
import { useIdeState } from 'src/helpers/hooks/useIdeState'
|
||||
import { IdeContext } from 'src/helpers/hooks/useIdeContext'
|
||||
|
||||
export const QUERY = gql`
|
||||
query FIND_PROJECT_BY_USENAME_TITLE(
|
||||
$projectTitle: String!
|
||||
$userName: String!
|
||||
) {
|
||||
project: projectByUserAndTitle(
|
||||
projectTitle: $projectTitle
|
||||
userName: $userName
|
||||
) {
|
||||
id
|
||||
title
|
||||
description
|
||||
code
|
||||
mainImage
|
||||
createdAt
|
||||
cadPackage
|
||||
user {
|
||||
id
|
||||
userName
|
||||
image
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
export interface Project {
|
||||
id: string
|
||||
title: string
|
||||
code: string
|
||||
description: string
|
||||
mainImage: string
|
||||
createdAt: string
|
||||
cadPackage: 'openscad' | 'cadquery'
|
||||
user: {
|
||||
id: string
|
||||
userName: string
|
||||
image: string
|
||||
}
|
||||
}
|
||||
|
||||
export const Loading = () => <div>Loading...</div>
|
||||
|
||||
export const Empty = () => <div>Project not found</div>
|
||||
|
||||
interface SaveCodeArgs {
|
||||
input: any
|
||||
id: string
|
||||
isFork: boolean
|
||||
}
|
||||
|
||||
export const Success = ({
|
||||
project,
|
||||
refetch,
|
||||
}: {
|
||||
project: Project
|
||||
refetch: any
|
||||
}) => {
|
||||
const [state, thunkDispatch] = useIdeState()
|
||||
|
||||
|
||||
return (
|
||||
<IdeContext.Provider value={{ state, thunkDispatch, project }}>
|
||||
<EmbedProject project={project} />
|
||||
</IdeContext.Provider>
|
||||
)
|
||||
}
|
||||
11
app/web/src/pages/EmbedProjectPage/EmbedProjectPage.test.tsx
Normal file
11
app/web/src/pages/EmbedProjectPage/EmbedProjectPage.test.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { render } from '@redwoodjs/testing'
|
||||
|
||||
import EmbedProjectPage from './EmbedProjectPage'
|
||||
|
||||
describe('EmbedProjectPage', () => {
|
||||
it('renders successfully', () => {
|
||||
expect(() => {
|
||||
render(<EmbedProjectPage />)
|
||||
}).not.toThrow()
|
||||
})
|
||||
})
|
||||
11
app/web/src/pages/EmbedProjectPage/EmbedProjectPage.tsx
Normal file
11
app/web/src/pages/EmbedProjectPage/EmbedProjectPage.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import EmbedProjectCell from 'src/components/EmbedProjectCell'
|
||||
|
||||
const EmbedProjectPage = ({ userName, projectTitle }) => {
|
||||
return (
|
||||
<>
|
||||
<EmbedProjectCell userName={userName} projectTitle={projectTitle} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default EmbedProjectPage
|
||||
Reference in New Issue
Block a user