Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.get('/next', async (req, res) => {
const role = getRole(req)
const defaultUrl = role === 'sg_anonymous' ? '/subjects/search' : '/dashboard'
if (!req.query.goal && !req.cookies.goal) {
return res.redirect(defaultUrl)
}
// ?goal => query.goal, undefined
// ?step => cookie.goal, query.step
// ?____ => cookie.goal, cookie.step
const gqlRes = await GQL.next(req, {
goal: toU(req.query.goal || req.cookies.goal),
step: req.query.goal ? undefined : toU(req.query.step || req.cookies.step),
})
const { next, step, goal, kind, card } = get(gqlRes, 'next.nextPage')
res.cookie('goal', to58(goal), LEARN_COOKIE_PARAMS)
if (step) res.cookie('step', to58(step), LEARN_COOKIE_PARAMS)
else res.clearCookie('step')
const kindUrl = get(CARD_KIND, [kind, 'url'])
const urlMap = {
CREATE_CARD: `/cards/create?subjectId=${to58(step)}`,
LEARN_CARD: `/${kindUrl}-cards/${to58(card)}/learn`,
COMPLETE_SUBJECT: `/subjects/${to58(goal)}/complete`,
CHOOSE_STEP: `/subjects/${to58(goal)}/steps`,
}
return res.redirect(get(urlMap, next, defaultUrl))
})
app.get('/next', async (req, res) => {
const role = getRole(req)
const defaultUrl = role === 'sg_anonymous' ? '/subjects/search' : '/dashboard'
if (!req.query.goal && !req.cookies.goal) {
return res.redirect(defaultUrl)
}
// ?goal => query.goal, undefined
// ?step => cookie.goal, query.step
// ?____ => cookie.goal, cookie.step
const gqlRes = await GQL.next(req, {
goal: toU(req.query.goal || req.cookies.goal),
step: req.query.goal ? undefined : toU(req.query.step || req.cookies.step),
})
const { next, step, goal, kind, card } = get(gqlRes, 'next.nextPage')
res.cookie('goal', to58(goal), LEARN_COOKIE_PARAMS)
if (step) res.cookie('step', to58(step), LEARN_COOKIE_PARAMS)
else res.clearCookie('step')
const kindUrl = get(CARD_KIND, [kind, 'url'])
const urlMap = {
CREATE_CARD: `/cards/create?subjectId=${to58(step)}`,
LEARN_CARD: `/${kindUrl}-cards/${to58(card)}/learn`,
COMPLETE_SUBJECT: `/subjects/${to58(goal)}/complete`,
CHOOSE_STEP: `/subjects/${to58(goal)}/steps`,
}
return res.redirect(get(urlMap, next, defaultUrl))
})
export default function Topic({
id,
created,
name,
postsByTopicId,
gqlErrors,
query,
body,
}) {
const selected = query['topic-id'] === to58(id)
return (
<li id="{`topic-${to58(id)}`}">
<details open="{selected}">
<summary>
<h3>{name}</h3> {/* if author, edit name */}
<small>
</small>
</summary>
{postsByTopicId.nodes.length ? (
{postsByTopicId.nodes.map(post => (
))}
<table></table>
) : (
<p>
<em>There's no posts yet. Be the first!</em></p></details></li>
export default function Topic({
id,
created,
name,
postsByTopicId,
gqlErrors,
query,
body,
}) {
const selected = query['topic-id'] === to58(id)
return (
<li id="{`topic-${to58(id)}`}">
<details open="{selected}">
<summary>
<h3>{name}</h3> {/* if author, edit name */}
<small>
</small>
</summary>
{postsByTopicId.nodes.length ? (
{postsByTopicId.nodes.map(post => (
))}
<table></table>
) : (</details></li>
export default function TempHelp({ name, cardId, subjectId }) {
if (SKIPLIST.includes(to58(subjectId)) || !name || !cardId) return <>
return (
<section>
<hr>
<p>
<small>
Sagefy currently shows computer-made examples of many subjects. <br>
If you want to learn about <q>{name}</q> and
help others learn too,{' '}
<a href="{`/cards/${to58(cardId)}/edit?redirect=/cards/${to58(">
help us by editing!
</a>
</small></p></section>
async (req, res) => {
try {
const gqlRes = await GQL.createTopic(req, req.body)
const topicId = to58(get(gqlRes, 'createTopic.topic.id'))
return res.redirect(`?topic-id=${topicId}#topic-${topicId}`)
} catch (e) {
return res.redirect('')
}
}
)
async (req, res) => {
try {
const gqlRes = await GQL.createPost(req, req.body)
return res.redirect(
`..?topic-id=${req.params.topicId}#post-${to58(
get(gqlRes, 'createPost.post.id')
)}`
)
} catch (e) {
return res.redirect(`..?topic-id=${req.params.topicId}`)
}
}
)
({ entityId, name }) => (
<li>
<a href="{`/subjects/${to58(entityId)}`}">{name}</a>
</li>
)
)}
{kCards.map(({ name, entityId }) => (
<li>
<a href="{`/${get(CARD_KIND,">
{name}
</a>
</li>
))}
{mySubjects.map(({ entityId, name, cardCount, childCount }) => (
<li>
<a href="{`/cards/create?subjectId=${to58(entityId)}`}">
Add cards to <q>{name}</q>
</a>{' '}
<small>
({cardCount} cards, {childCount} child subjects)
</small>
</li>
))}