Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const TypeErrorsView = () => (
<ul>
{useList(typeErrors, error => {
// TODO: hide libdefs until errors are fixed
if (
process.env.NODE_ENV === 'production' &&
error.message[0].loc?.type === 'LibFile'
)
return null
return (
<li>
{error.message.map((message, key) => (
))}
{error.extra &&
error.extra.map((extra, key) => )}
</li>
)</ul>
export default async(req, res) => {
const url = req.url.replace('/ssr', '').replace(/^\//, '')
if (url === '') {
const routes = Object.keys(users)
const route = routes[(Math.random() * routes.length) | 0]
res.setHeader('Location', `/${route}`)
res.status(302).send('')
return
}
if (!users.hasOwnProperty(url)) {
res.status(404).send('not found')
return
}
try {
const scope = await fork(app, {
start: startServer,
ctx: users[url],
})
const data = serialize(scope)
const content = renderToString(React.createElement(App, {root: scope}))
const result = await compile({content, data})
res.send(result)
} catch (err) {
console.error(err)
res.status(500).send('something going wrong')
}
}
const routes = Object.keys(users)
const route = routes[(Math.random() * routes.length) | 0]
res.setHeader('Location', `/${route}`)
res.status(302).send('')
return
}
if (!users.hasOwnProperty(url)) {
res.status(404).send('not found')
return
}
try {
const scope = await fork(app, {
start: startServer,
ctx: users[url],
})
const data = serialize(scope)
const content = renderToString(React.createElement(App, {root: scope}))
const result = await compile({content, data})
res.send(result)
} catch (err) {
console.error(err)
res.status(500).send('something going wrong')
}
}
const AvatarSection = () => {
const avatarUrl = useStore($avatarUrl)
return (
)
}
export const CardsHomePage = () => {
const ids = useStore($cardsIds)
const isLoading = useStore(homeCardsFetching.isLoading)
React.useEffect(() => {
pageReady()
}, [])
return (
}>
<p>What about to create new card?</p>}
/>
)
}
const Title = () => {
const title = useStore($title) || ""
const titleRef = React.createRef()
React.useEffect(() => {
if (titleRef.current) {
titleRef.current.focus()
}
}, [])
return (
export const CardViewPage = ({ match }: Props) => {
const cardId = parseInt(match.params.cardId, 10)
React.useEffect(() => {
cardLoading({ cardId })
}, [cardId])
const current = useStore($card)
return (
}>
{current ? (
) : (
)}
)
}
export const UserPage = ({ match }: Props) => {
const [tab, setTab] = React.useState<"created" | "useful">("useful")
const userId = parseInt(match.params.userId, 10)
const user = useStore($user)
const { created, useful } = useStore($cards)
const isLoading = useStore($isLoading)
const isFailed = useStore($isFailed)
const error = useStore($error)
React.useEffect(() => {
pageMounted({ userId })
}, [userId])
if (isFailed)
return
return (
}>
setTab("useful")}>
Useful
|
const RegisterForm = () => {
const form = useStore($form)
const formError = useStore(registerFetching.error)
const isSubmitEnabled = useStore($isSubmitEnabled)
return (
<form>
<h2>Registration to HowToCards</h2>
{formError && (
{mapServerToClientError(formError.error)}
)}
Create account
)</form>
const Password = () => {
const password = useStore($password)
const isFormDisabled = useStore($isFormDisabled)
const passwordError = useStore($passwordError)
return (
<input value="{password}" disabled="{isFormDisabled}" label="Password" autocomplete="password" name="password" type="password">
)
}