Skip to content

Commit

Permalink
Open Question Generator (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenClontz authored Dec 6, 2024
1 parent 0b8853e commit e3004a6
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/viewer/src/components/Nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<a class="nav-link" href="/spaces/all">Spaces</a>
<a class="nav-link" href="/properties">Properties</a>
<a class="nav-link" href="/theorems">Theorems</a>
<a class="nav-link" href="/questions">Questions</a>
</div>

<div class="navbar-nav">
Expand Down
57 changes: 57 additions & 0 deletions packages/viewer/src/components/Questions/Questions.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<script lang="ts">
import type { Space, Property, Trait } from '@/types'
import { Dice } from '../Shared/Icons'
import Typeset from '../Shared/Typeset.svelte'
import context from '@/context'
const { spaces, traits } = context()
let openQuestion:
| { space: Space; property: Property; trait: Trait | undefined }
| undefined = undefined
const rollOpenQuestion = () => {
openQuestion = undefined
const ss = $spaces.all
while (openQuestion == undefined) {
const randomSpace = ss[Math.floor(Math.random() * ss.length)]
const openQuestions = $traits
.forSpaceAll(randomSpace)
.map(([p, t]) => {
return {
space: randomSpace,
property: p,
trait: t,
}
})
.filter(question => question.trait === undefined)
if (openQuestions.length === 0) {
openQuestion = undefined
} else {
openQuestion =
openQuestions[Math.floor(Math.random() * openQuestions.length)]
}
}
}
rollOpenQuestion()
$: bodyMain = `Does {S${openQuestion?.space.id}} satisfy {P${openQuestion?.property.id}}?`
$: bodySecondary = `Trait link: {S${openQuestion?.space.id}|P${openQuestion?.property.id}}`
</script>

<div class="text-center my-3">
<div class="mb-3">
<button
type="button"
class="btn btn-outline-secondary"
on:click={() => rollOpenQuestion()}
>
<Dice /> Reroll question
</button>
</div>
<div class="lead mb-3" style="font-size:2em">
<Typeset body={bodyMain} />
</div>
<div class="mb-3">
<Typeset body={bodySecondary} />
</div>
<p>
<small> Disclaimer: some questions cannot be answered in ZFC! </small>
</p>
</div>
1 change: 1 addition & 0 deletions packages/viewer/src/components/Questions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Questions } from './Questions.svelte'
10 changes: 10 additions & 0 deletions packages/viewer/src/components/Shared/Icons/Dice.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<svg
fill="currentColor"
viewBox="0 0 640 512"
height="1.5em"
width="1.5em"
xmlns="http://www.w3.org/2000/svg"
><!--!Font Awesome Free 6.7.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path
d="M592 192H473.3c12.7 29.6 7.1 65.2-17 89.3L320 417.6V464c0 26.5 21.5 48 48 48h224c26.5 0 48-21.5 48-48V240c0-26.5-21.5-48-48-48zM480 376c-13.3 0-24-10.8-24-24 0-13.3 10.8-24 24-24s24 10.7 24 24c0 13.3-10.8 24-24 24zm-46.4-186.7L258.7 14.4c-19.2-19.2-50.2-19.2-69.4 0L14.4 189.3c-19.2 19.2-19.2 50.2 0 69.4L189.3 433.6c19.2 19.2 50.2 19.2 69.4 0L433.6 258.7c19.2-19.2 19.2-50.2 0-69.4zM96 248c-13.3 0-24-10.8-24-24 0-13.3 10.8-24 24-24s24 10.7 24 24c0 13.3-10.8 24-24 24zm128 128c-13.3 0-24-10.8-24-24 0-13.3 10.8-24 24-24s24 10.7 24 24c0 13.3-10.8 24-24 24zm0-128c-13.3 0-24-10.8-24-24 0-13.3 10.8-24 24-24s24 10.7 24 24c0 13.3-10.8 24-24 24zm0-128c-13.3 0-24-10.8-24-24 0-13.3 10.8-24 24-24s24 10.7 24 24c0 13.3-10.8 24-24 24zm128 128c-13.3 0-24-10.8-24-24 0-13.3 10.8-24 24-24s24 10.7 24 24c0 13.3-10.8 24-24 24z"
/></svg
>
1 change: 1 addition & 0 deletions packages/viewer/src/components/Shared/Icons/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { default as Branch } from './Branch.svelte'
export { default as Check } from './Check.svelte'
export { default as Dice } from './Dice.svelte'
export { default as Question } from './Question.svelte'
export { default as Repeat } from './Repeat.svelte'
export { default as Search } from './Search.svelte'
Expand Down
8 changes: 8 additions & 0 deletions packages/viewer/src/routes/(app)/questions/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import Title from '@/components/Shared/Title.svelte'
import Questions from '@/components/Questions/Questions.svelte'
</script>

<Title title="Questions" />

<Questions />
1 change: 1 addition & 0 deletions packages/viewer/src/routes/(app)/questions/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const prerender = true

0 comments on commit e3004a6

Please sign in to comment.