Tidy the site's problem pages and typeset math in explanations
The problem page's Explain and recording-review forms took most of the first screen, above the solution. They now fold into the admin bar with the editor, one open at a time; a running job is reported in the bar, so a form can be closed while it works. The problem list is grouped by month when sorted by recency, as one card per month with divided rows, laid out on a fixed grid so rows line up on a phone. Empty status tabs are hidden. Rust solutions are now highlighted, the file picker is styled like the other buttons, header links no longer break mid-word on a phone, and keyboard focus is visible. Markdown everywhere now goes through one renderer that typesets $...$, $$...$$ and ```math with KaTeX. The explanation prompt asked for $...$ only when the statement used it, so formulas came out as inline code; it now asks for LaTeX for math and code spans for code, and the review prompt does the same for complexities. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -104,7 +104,8 @@ How to explain:
|
|||||||
- Justify correctness informally but convincingly, especially for greedy choices.
|
- Justify correctness informally but convincingly, especially for greedy choices.
|
||||||
- If they describe what they are stuck on, or include their attempt, address that directly: say what in their attempt is on the right track and where it goes wrong. Do not rewrite their code.
|
- If they describe what they are stuck on, or include their attempt, address that directly: say what in their attempt is on the right track and where it goes wrong. Do not rewrite their code.
|
||||||
- Never give a complete solution in any real programming language. The sketch is short pseudocode for the core idea only.
|
- Never give a complete solution in any real programming language. The sketch is short pseudocode for the core idea only.
|
||||||
- Write in plain, direct prose. Use markdown for emphasis, lists and inline code. Use $...$ only if the problem statement does.
|
- Write in plain, direct prose. Use markdown for emphasis, lists and inline code.
|
||||||
|
- Write math as LaTeX, which the page typesets with KaTeX: $...$ inline, and $$...$$ on lines of its own for a formula worth displaying, such as a recurrence or an identity the approach rests on. That covers formulas, bounds, complexities and indexed sums (write $O(n \log n)$ and $\sum_{i=L}^{R} d_i$, not O(n log n) or Σ_{i=L..R} d[i]). Keep inline code for code: variable names, array accesses and expressions as they would appear in a program.
|
||||||
|
|
||||||
Diagram rules for each walkthrough step's svg:
|
Diagram rules for each walkthrough step's svg:
|
||||||
- Show the actual mechanism on a small concrete example (the sample if it is small enough): array cells with index labels and pointer arrows, grid cells with their values and the current frontier, a DP table filling in, a graph with visited nodes and the edge being relaxed, a stack or heap's contents. Successive steps should show the state changing.
|
- Show the actual mechanism on a small concrete example (the sample if it is small enough): array cells with index labels and pointer arrows, grid cells with their values and the current frontier, a DP table filling in, a graph with visited nodes and the edge being relaxed, a stack or heap's contents. Successive steps should show the state changing.
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ Judging delivery:
|
|||||||
|
|
||||||
Scores, each 1 to 5: 1 missing or wrong, 2 weak, 3 adequate, 4 good, 5 what a strong candidate would do. Most decent attempts land at 3 or 4; give 5 only when nothing meaningful could be better.
|
Scores, each 1 to 5: 1 missing or wrong, 2 weak, 3 adequate, 4 good, 5 what a strong candidate would do. Most decent attempts land at 3 or 4; give 5 only when nothing meaningful could be better.
|
||||||
|
|
||||||
Be direct and specific. Praise only what earned it, and make every improvement something they could act on in the next recording. Write in plain, direct prose, using markdown for emphasis, lists and inline code.`
|
Be direct and specific. Praise only what earned it, and make every improvement something they could act on in the next recording. Write in plain, direct prose, using markdown for emphasis, lists and inline code, and LaTeX between $...$ for math such as complexities ($O(n \log n)$); the page typesets it with KaTeX.`
|
||||||
|
|
||||||
// Prompt is the user message.
|
// Prompt is the user message.
|
||||||
func Prompt(in Input) string {
|
func Prompt(in Input) string {
|
||||||
|
|||||||
Generated
+36
@@ -8,8 +8,10 @@
|
|||||||
"name": "usaco-site-web",
|
"name": "usaco-site-web",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@vscode/markdown-it-katex": "^1.1.2",
|
||||||
"dompurify": "^3.4.17",
|
"dompurify": "^3.4.17",
|
||||||
"highlight.js": "^11.11.1",
|
"highlight.js": "^11.11.1",
|
||||||
|
"katex": "^0.16.25",
|
||||||
"markdown-it": "^14.1.0",
|
"markdown-it": "^14.1.0",
|
||||||
"vue": "^3.5.22",
|
"vue": "^3.5.22",
|
||||||
"vue-router": "^4.6.3"
|
"vue-router": "^4.6.3"
|
||||||
@@ -1292,6 +1294,15 @@
|
|||||||
"vue": "^3.2.25 || ^3.6.0-rc.10"
|
"vue": "^3.2.25 || ^3.6.0-rc.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@vscode/markdown-it-katex": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@vscode/markdown-it-katex/-/markdown-it-katex-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-+4IIv5PgrmhKvW/3LpkpkGg257OViEhXkOOgCyj5KMsjsOfnRXkni8XAuuF9Ui5p3B8WnUovlDXAQNb8RJ/RaQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"katex": "^0.16.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@vue/compiler-core": {
|
"node_modules/@vue/compiler-core": {
|
||||||
"version": "3.5.44",
|
"version": "3.5.44",
|
||||||
"resolved": "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.5.44.tgz",
|
"resolved": "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.5.44.tgz",
|
||||||
@@ -1414,6 +1425,15 @@
|
|||||||
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
|
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
|
||||||
"license": "Python-2.0"
|
"license": "Python-2.0"
|
||||||
},
|
},
|
||||||
|
"node_modules/commander": {
|
||||||
|
"version": "8.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz",
|
||||||
|
"integrity": "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 12"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/csstype": {
|
"node_modules/csstype": {
|
||||||
"version": "3.2.3",
|
"version": "3.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz",
|
||||||
@@ -1572,6 +1592,22 @@
|
|||||||
"jiti": "lib/jiti-cli.mjs"
|
"jiti": "lib/jiti-cli.mjs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/katex": {
|
||||||
|
"version": "0.16.25",
|
||||||
|
"resolved": "https://registry.npmjs.org/katex/-/katex-0.16.25.tgz",
|
||||||
|
"integrity": "sha512-woHRUZ/iF23GBP1dkDQMh1QBad9dmr8/PAwNA54VrSOVYgI12MAcE14TqnDdQOdzyEonGzMepYnqBMYdsoAr8Q==",
|
||||||
|
"funding": [
|
||||||
|
"https://opencollective.com/katex",
|
||||||
|
"https://github.com/sponsors/katex"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"commander": "^8.3.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"katex": "cli.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/lightningcss": {
|
"node_modules/lightningcss": {
|
||||||
"version": "1.32.0",
|
"version": "1.32.0",
|
||||||
"resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.32.0.tgz",
|
"resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.32.0.tgz",
|
||||||
|
|||||||
@@ -12,8 +12,10 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@vscode/markdown-it-katex": "^1.1.2",
|
||||||
"dompurify": "^3.4.17",
|
"dompurify": "^3.4.17",
|
||||||
"highlight.js": "^11.11.1",
|
"highlight.js": "^11.11.1",
|
||||||
|
"katex": "^0.16.25",
|
||||||
"markdown-it": "^14.1.0",
|
"markdown-it": "^14.1.0",
|
||||||
"vue": "^3.5.22",
|
"vue": "^3.5.22",
|
||||||
"vue-router": "^4.6.3"
|
"vue-router": "^4.6.3"
|
||||||
|
|||||||
@@ -49,11 +49,13 @@ import { RouterLink, RouterView } from "vue-router";
|
|||||||
}
|
}
|
||||||
nav {
|
nav {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 20px;
|
flex-wrap: wrap;
|
||||||
|
gap: 4px 20px;
|
||||||
}
|
}
|
||||||
nav a {
|
nav a {
|
||||||
color: var(--color-ink-muted);
|
color: var(--color-ink-muted);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
nav a:hover,
|
nav a:hover,
|
||||||
nav a.on {
|
nav a.on {
|
||||||
|
|||||||
@@ -80,6 +80,13 @@ a {
|
|||||||
color: var(--color-ink-link);
|
color: var(--color-ink-link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Preflight leaves focus to the browser default, which is faint on the
|
||||||
|
paper background; keyboard users get a clear ring everywhere. */
|
||||||
|
:focus-visible {
|
||||||
|
outline: 2px solid var(--color-ink-link);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
.card {
|
.card {
|
||||||
background: var(--color-paper);
|
background: var(--color-paper);
|
||||||
border: 1px solid var(--color-line-soft);
|
border: 1px solid var(--color-line-soft);
|
||||||
|
|||||||
@@ -8,10 +8,12 @@ import { computed, ref } from "vue";
|
|||||||
import hljs from "highlight.js/lib/core";
|
import hljs from "highlight.js/lib/core";
|
||||||
import cpp from "highlight.js/lib/languages/cpp";
|
import cpp from "highlight.js/lib/languages/cpp";
|
||||||
import python from "highlight.js/lib/languages/python";
|
import python from "highlight.js/lib/languages/python";
|
||||||
|
import rust from "highlight.js/lib/languages/rust";
|
||||||
|
|
||||||
hljs.registerLanguage("cpp", cpp);
|
hljs.registerLanguage("cpp", cpp);
|
||||||
hljs.registerLanguage("c", cpp);
|
hljs.registerLanguage("c", cpp);
|
||||||
hljs.registerLanguage("python", python);
|
hljs.registerLanguage("python", python);
|
||||||
|
hljs.registerLanguage("rust", rust);
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
content: { type: String, required: true },
|
content: { type: String, required: true },
|
||||||
|
|||||||
@@ -6,14 +6,15 @@
|
|||||||
* section (who wrote it, when) stays visible. Reviews use it too, with the
|
* section (who wrote it, when) stays visible. Reviews use it too, with the
|
||||||
* sections worth reading at once named in open.
|
* sections worth reading at once named in open.
|
||||||
*
|
*
|
||||||
* Markdown is rendered with html: false like the notes. The one exception
|
* Markdown is rendered like the notes (@/markdown: no raw HTML, KaTeX for
|
||||||
* is ```svg fences, the walkthrough's diagrams: they are inserted as SVG
|
* math). The one exception is ```svg fences, the walkthrough's diagrams:
|
||||||
* after DOMPurify's SVG profile has stripped scripts, event handlers and
|
* they are inserted as SVG after DOMPurify's SVG profile has stripped
|
||||||
|
* scripts, event handlers and
|
||||||
* anything else that is not drawing. Claude wrote them, the admin can edit
|
* anything else that is not drawing. Claude wrote them, the admin can edit
|
||||||
* them, and the public sees them once the problem is solved.
|
* them, and the public sees them once the problem is solved.
|
||||||
*/
|
*/
|
||||||
import { computed } from "vue";
|
import { computed } from "vue";
|
||||||
import MarkdownIt from "markdown-it";
|
import { markdown } from "@/markdown";
|
||||||
import DOMPurify from "dompurify";
|
import DOMPurify from "dompurify";
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -21,7 +22,7 @@ const props = defineProps({
|
|||||||
open: { type: Array, default: () => [] },
|
open: { type: Array, default: () => [] },
|
||||||
});
|
});
|
||||||
|
|
||||||
const md = new MarkdownIt({ html: false, linkify: true });
|
const md = markdown();
|
||||||
const fence = md.renderer.rules.fence;
|
const fence = md.renderer.rules.fence;
|
||||||
md.renderer.rules.fence = (tokens, idx, options, env, self) => {
|
md.renderer.rules.fence = (tokens, idx, options, env, self) => {
|
||||||
const t = tokens[idx];
|
const t = tokens[idx];
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* The one markdown setup every view renders with: notes, statements,
|
||||||
|
* explanations and reviews.
|
||||||
|
*
|
||||||
|
* html: false — markdown only, never raw HTML. Math is the exception that
|
||||||
|
* proves it: $…$, $$…$$ and ```math fences are typeset by KaTeX, whose
|
||||||
|
* output is its own markup and which refuses \href, \htmlClass and the like
|
||||||
|
* unless told to trust the source (it isn't). Explanations are asked to use
|
||||||
|
* $…$ when the statement does (internal/explain). A formula KaTeX can't
|
||||||
|
* parse is shown as its source in red rather than breaking the page.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import MarkdownIt from "markdown-it";
|
||||||
|
import katex from "@vscode/markdown-it-katex";
|
||||||
|
import "katex/dist/katex.min.css";
|
||||||
|
|
||||||
|
export function markdown() {
|
||||||
|
return new MarkdownIt({ html: false, linkify: true }).use(katex, { throwOnError: false, enableFencedBlocks: true });
|
||||||
|
}
|
||||||
@@ -49,8 +49,9 @@ const counts = computed(() => {
|
|||||||
return c;
|
return c;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// An empty tab is left out unless it is the one selected (a linked view).
|
||||||
const tabs = computed(() =>
|
const tabs = computed(() =>
|
||||||
admin.value ? ["all", "solving", "solved", "skipped"] : [],
|
admin.value ? ["all", "solving", "solved", "skipped"].filter((t) => counts.value[t] || status.value === t) : [],
|
||||||
);
|
);
|
||||||
|
|
||||||
// When a problem was last worked on, for sorting: the solve date if it has
|
// When a problem was last worked on, for sorting: the solve date if it has
|
||||||
@@ -67,6 +68,22 @@ const shown = computed(() => {
|
|||||||
if (sort.value === "name") return list.sort((a, b) => a.name.localeCompare(b.name));
|
if (sort.value === "name") return list.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
return list.sort((a, b) => when(b).localeCompare(when(a)) || a.name.localeCompare(b.name));
|
return list.sort((a, b) => when(b).localeCompare(when(a)) || a.name.localeCompare(b.name));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Most recent is split by month, so a long list has landmarks; by name it
|
||||||
|
// is one block. An undated problem sorts last, under "Undated".
|
||||||
|
const groups = computed(() => {
|
||||||
|
if (sort.value === "name") return [{ key: "all", label: "", items: shown.value }];
|
||||||
|
const out = [];
|
||||||
|
for (const p of shown.value) {
|
||||||
|
const w = when(p);
|
||||||
|
const key = w ? w.slice(0, 7) : "none";
|
||||||
|
if (out.at(-1)?.key !== key) {
|
||||||
|
out.push({ key, label: w ? formatDate(w, { month: "long", year: "numeric" }) : "Undated", items: [] });
|
||||||
|
}
|
||||||
|
out.at(-1).items.push(p);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -99,27 +116,35 @@ const shown = computed(() => {
|
|||||||
<p v-else-if="error" class="error">{{ error }}</p>
|
<p v-else-if="error" class="error">{{ error }}</p>
|
||||||
<p v-else-if="!shown.length" class="muted">Nothing matches.</p>
|
<p v-else-if="!shown.length" class="muted">Nothing matches.</p>
|
||||||
|
|
||||||
<ul v-else class="list">
|
<div v-else class="groups">
|
||||||
<li v-for="p in shown" :key="p.name">
|
<section v-for="g in groups" :key="g.key">
|
||||||
<RouterLink :to="{ name: 'problem', params: { name: p.name } }" class="row card">
|
<h2 v-if="g.label" class="month">{{ g.label }} <span class="n">{{ g.items.length }}</span></h2>
|
||||||
<div class="main">
|
<ul class="list card">
|
||||||
|
<li v-for="p in g.items" :key="p.name">
|
||||||
|
<RouterLink :to="{ name: 'problem', params: { name: p.name } }" class="row">
|
||||||
<span class="name">{{ title(p.name) }}</span>
|
<span class="name">{{ title(p.name) }}</span>
|
||||||
|
<span class="sub">
|
||||||
<span class="meta muted">
|
<span class="meta muted">
|
||||||
<template v-if="p.langs.length">{{ p.langs.map((l) => LANG_LABELS[l] || l).join(", ") }}</template>
|
<template v-if="p.langs.length">{{ p.langs.map((l) => LANG_LABELS[l] || l).join(", ") }}</template>
|
||||||
<template v-if="p.tests"> · {{ p.tests }} test{{ p.tests === 1 ? "" : "s" }}</template>
|
<template v-if="p.tests"> · {{ p.tests }} test{{ p.tests === 1 ? "" : "s" }}</template>
|
||||||
<template v-if="p.hasNotes"> · notes</template>
|
<template v-if="p.hasNotes"> · notes</template>
|
||||||
|
<template v-if="p.hasExplanation"> · explained</template>
|
||||||
<template v-if="p.reviewCount"> · {{ p.reviewCount }} review{{ p.reviewCount === 1 ? "" : "s" }}</template>
|
<template v-if="p.reviewCount"> · {{ p.reviewCount }} review{{ p.reviewCount === 1 ? "" : "s" }}</template>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
<span class="tags">
|
||||||
<div class="side">
|
|
||||||
<span v-if="p.source" class="badge">{{ p.source }}</span>
|
<span v-if="p.source" class="badge">{{ p.source }}</span>
|
||||||
<span v-if="admin || p.status !== 'solved'" class="badge" :class="p.status">{{ STATUS_LABELS[p.status] }}</span>
|
<span v-if="admin || p.status !== 'solved'" class="badge" :class="p.status">{{ STATUS_LABELS[p.status] }}</span>
|
||||||
<time v-if="when(p)" class="muted" :datetime="when(p)">{{ formatDate(when(p)) }}</time>
|
</span>
|
||||||
</div>
|
</span>
|
||||||
|
<time v-if="when(p)" class="muted" :class="{ full: !g.label }" :datetime="when(p)">
|
||||||
|
{{ g.label ? formatDate(when(p), { day: "numeric", month: "short" }) : formatDate(when(p)) }}
|
||||||
|
</time>
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -167,42 +192,96 @@ input {
|
|||||||
flex: 1 1 200px;
|
flex: 1 1 200px;
|
||||||
max-width: 320px;
|
max-width: 320px;
|
||||||
}
|
}
|
||||||
.list {
|
.groups {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 8px;
|
gap: 20px;
|
||||||
}
|
}
|
||||||
|
.month {
|
||||||
|
font-size: 1.4rem;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
.month .n {
|
||||||
|
font-family: var(--font-body);
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: var(--color-ink-faint);
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
.list > li + li {
|
||||||
|
border-top: 1px solid var(--color-line-soft);
|
||||||
|
}
|
||||||
|
/* Name and date on the first line, details and badges on the second, at
|
||||||
|
every width, so rows line up instead of wrapping each its own way. On a
|
||||||
|
phone the second line is one flex row, so the badges don't widen the date
|
||||||
|
column and squeeze the name. */
|
||||||
.row {
|
.row {
|
||||||
display: flex;
|
display: grid;
|
||||||
flex-wrap: wrap;
|
grid-template-columns: minmax(0, 1fr) auto;
|
||||||
justify-content: space-between;
|
grid-template-areas:
|
||||||
|
"name date"
|
||||||
|
"sub sub";
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 8px 16px;
|
gap: 2px 16px;
|
||||||
padding: 12px 16px;
|
padding: 10px 16px;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
.row:hover {
|
.row:hover {
|
||||||
border-color: var(--color-ink-faint);
|
background: var(--color-paper-tint);
|
||||||
}
|
}
|
||||||
.main {
|
li:first-child .row {
|
||||||
display: flex;
|
border-radius: 6px 6px 0 0;
|
||||||
flex-direction: column;
|
}
|
||||||
min-width: 0;
|
li:last-child .row {
|
||||||
|
border-radius: 0 0 6px 6px;
|
||||||
}
|
}
|
||||||
.name {
|
.name {
|
||||||
|
grid-area: name;
|
||||||
font-size: 1.05rem;
|
font-size: 1.05rem;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
.sub {
|
||||||
|
grid-area: sub;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 4px 12px;
|
||||||
}
|
}
|
||||||
.meta {
|
.meta {
|
||||||
|
grid-area: meta;
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
}
|
}
|
||||||
.side {
|
.tags {
|
||||||
|
grid-area: tags;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
justify-content: flex-end;
|
||||||
gap: 8px;
|
gap: 6px;
|
||||||
font-size: 0.85rem;
|
|
||||||
}
|
}
|
||||||
time {
|
time {
|
||||||
min-width: 7.5em;
|
grid-area: date;
|
||||||
|
font-size: 0.85rem;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
/* Fixed widths, so the dates line up down a card. */
|
||||||
|
@media (min-width: 640px) {
|
||||||
|
time {
|
||||||
|
min-width: 4em;
|
||||||
|
}
|
||||||
|
time.full {
|
||||||
|
min-width: 6.5em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Wide enough for one line: badges and date in columns of their own. */
|
||||||
|
@media (min-width: 640px) {
|
||||||
|
.row {
|
||||||
|
grid-template-columns: minmax(0, 1fr) auto auto;
|
||||||
|
grid-template-areas:
|
||||||
|
"name tags date"
|
||||||
|
"meta tags date";
|
||||||
|
}
|
||||||
|
.sub {
|
||||||
|
display: contents;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -10,10 +10,10 @@
|
|||||||
*/
|
*/
|
||||||
import { computed, onUnmounted, ref, watch } from "vue";
|
import { computed, onUnmounted, ref, watch } from "vue";
|
||||||
import { RouterLink } from "vue-router";
|
import { RouterLink } from "vue-router";
|
||||||
import MarkdownIt from "markdown-it";
|
|
||||||
import CodeBlock from "@/components/CodeBlock.vue";
|
import CodeBlock from "@/components/CodeBlock.vue";
|
||||||
import Explanation from "@/components/Explanation.vue";
|
import Explanation from "@/components/Explanation.vue";
|
||||||
import ReviewList from "@/components/ReviewList.vue";
|
import ReviewList from "@/components/ReviewList.vue";
|
||||||
|
import { markdown } from "@/markdown";
|
||||||
import {
|
import {
|
||||||
explainStatus,
|
explainStatus,
|
||||||
fetchStatement,
|
fetchStatement,
|
||||||
@@ -29,19 +29,24 @@ import { LANG_LABELS, STATUS_LABELS, formatDate, title } from "@/format";
|
|||||||
|
|
||||||
const props = defineProps({ name: { type: String, required: true } });
|
const props = defineProps({ name: { type: String, required: true } });
|
||||||
|
|
||||||
// html: false — notes are rendered as markdown only, never as raw HTML.
|
const md = markdown();
|
||||||
const md = new MarkdownIt({ html: false, linkify: true });
|
|
||||||
|
|
||||||
const problem = ref(null);
|
const problem = ref(null);
|
||||||
const admin = ref(false);
|
const admin = ref(false);
|
||||||
const loading = ref(true);
|
const loading = ref(true);
|
||||||
const error = ref("");
|
const error = ref("");
|
||||||
const activeFile = ref(0);
|
const activeFile = ref(0);
|
||||||
|
// The editor, Explain and Review forms fold into the admin bar, one open at
|
||||||
|
// a time, so the solution is not pushed below the fold. A running job is
|
||||||
|
// reported in the bar, so a panel can be closed while it works. Declared
|
||||||
|
// here because load() closes it and runs as soon as the watch below is set.
|
||||||
|
const panel = ref("");
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
error.value = "";
|
error.value = "";
|
||||||
activeFile.value = 0;
|
activeFile.value = 0;
|
||||||
|
panel.value = "";
|
||||||
try {
|
try {
|
||||||
const [p, me] = await Promise.all([getProblem(props.name), getMe().catch(() => ({ admin: false }))]);
|
const [p, me] = await Promise.all([getProblem(props.name), getMe().catch(() => ({ admin: false }))]);
|
||||||
problem.value = p;
|
problem.value = p;
|
||||||
@@ -63,10 +68,35 @@ const notesHtml = computed(() => (problem.value?.notes ? md.render(problem.value
|
|||||||
const statementHtml = computed(() => (problem.value?.statement ? md.render(problem.value.statement) : ""));
|
const statementHtml = computed(() => (problem.value?.statement ? md.render(problem.value.statement) : ""));
|
||||||
const file = computed(() => problem.value?.files[activeFile.value]);
|
const file = computed(() => problem.value?.files[activeFile.value]);
|
||||||
|
|
||||||
|
// ---- admin tools ----
|
||||||
|
const tools = [
|
||||||
|
{ id: "edit", label: "Edit details" },
|
||||||
|
{ id: "explain", label: "Explain" },
|
||||||
|
{ id: "review", label: "Review a recording" },
|
||||||
|
];
|
||||||
|
|
||||||
|
function toggle(id) {
|
||||||
|
// The file input goes with the panel, so the picked file must too.
|
||||||
|
if (panel.value === "review") recording.value = null;
|
||||||
|
if (panel.value === id) {
|
||||||
|
panel.value = "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (id === "edit") startEdit();
|
||||||
|
panel.value = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
const busy = computed(() => {
|
||||||
|
const out = [];
|
||||||
|
if (job.value.state === "running") out.push("Claude is writing an explanation…");
|
||||||
|
if (reviewJob.value.state === "uploading") out.push("Uploading the recording…");
|
||||||
|
if (reviewJob.value.state === "running") out.push("Transcribing and reviewing the recording… this takes a minute or two.");
|
||||||
|
return out;
|
||||||
|
});
|
||||||
|
|
||||||
// ---- admin edits ----
|
// ---- admin edits ----
|
||||||
const saving = ref(false);
|
const saving = ref(false);
|
||||||
const editError = ref("");
|
const editError = ref("");
|
||||||
const editing = ref(false);
|
|
||||||
const draftUrl = ref("");
|
const draftUrl = ref("");
|
||||||
const draftNotes = ref("");
|
const draftNotes = ref("");
|
||||||
const draftStatement = ref("");
|
const draftStatement = ref("");
|
||||||
@@ -77,7 +107,6 @@ function startEdit() {
|
|||||||
draftNotes.value = problem.value.notes || "";
|
draftNotes.value = problem.value.notes || "";
|
||||||
draftStatement.value = problem.value.statement || "";
|
draftStatement.value = problem.value.statement || "";
|
||||||
editError.value = "";
|
editError.value = "";
|
||||||
editing.value = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function run(action) {
|
async function run(action) {
|
||||||
@@ -97,7 +126,7 @@ async function run(action) {
|
|||||||
async function saveMeta() {
|
async function saveMeta() {
|
||||||
const meta = { url: draftUrl.value, notes: draftNotes.value, statement: draftStatement.value };
|
const meta = { url: draftUrl.value, notes: draftNotes.value, statement: draftStatement.value };
|
||||||
if (await run(() => updateMeta(props.name, meta))) {
|
if (await run(() => updateMeta(props.name, meta))) {
|
||||||
editing.value = false;
|
panel.value = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,6 +177,7 @@ async function checkExplain() {
|
|||||||
async function explain() {
|
async function explain() {
|
||||||
try {
|
try {
|
||||||
job.value = await startExplain(props.name, { note: stuckNote.value, includeCode: includeCode.value });
|
job.value = await startExplain(props.name, { note: stuckNote.value, includeCode: includeCode.value });
|
||||||
|
panel.value = "";
|
||||||
poll = setTimeout(checkExplain, 3000);
|
poll = setTimeout(checkExplain, 3000);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
job.value = { state: "error", error: e.message };
|
job.value = { state: "error", error: e.message };
|
||||||
@@ -160,7 +190,6 @@ const canExplain = computed(() => !!(problem.value?.statement || problem.value?.
|
|||||||
// The same shape as explanations, with its own job and timer: both can run
|
// The same shape as explanations, with its own job and timer: both can run
|
||||||
// at once.
|
// at once.
|
||||||
const recording = ref(null);
|
const recording = ref(null);
|
||||||
const recordingInput = ref(null);
|
|
||||||
const reviewNote = ref("");
|
const reviewNote = ref("");
|
||||||
const reviewCode = ref(true);
|
const reviewCode = ref(true);
|
||||||
const reviewJob = ref({ state: "idle" });
|
const reviewJob = ref({ state: "idle" });
|
||||||
@@ -212,7 +241,7 @@ async function submitReview() {
|
|||||||
try {
|
try {
|
||||||
reviewJob.value = await startReview(props.name, form);
|
reviewJob.value = await startReview(props.name, form);
|
||||||
recording.value = null;
|
recording.value = null;
|
||||||
if (recordingInput.value) recordingInput.value.value = "";
|
panel.value = "";
|
||||||
reviewPoll = setTimeout(checkReview, 3000);
|
reviewPoll = setTimeout(checkReview, 3000);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reviewJob.value = { state: "error", error: e.message };
|
reviewJob.value = { state: "error", error: e.message };
|
||||||
@@ -265,10 +294,25 @@ const moves = computed(() => {
|
|||||||
<button v-for="m in moves" :key="m.to" class="btn" :disabled="saving" @click="run(() => setStatus(problem.name, m.to))">
|
<button v-for="m in moves" :key="m.to" class="btn" :disabled="saving" @click="run(() => setStatus(problem.name, m.to))">
|
||||||
{{ m.label }}
|
{{ m.label }}
|
||||||
</button>
|
</button>
|
||||||
<button v-if="!editing" class="btn" :disabled="saving" @click="startEdit">Edit link, statement and notes</button>
|
<span class="sep" aria-hidden="true"></span>
|
||||||
<span v-if="saving" class="muted">Saving to git…</span>
|
<button
|
||||||
|
v-for="t in tools"
|
||||||
|
:key="t.id"
|
||||||
|
class="btn tool"
|
||||||
|
:class="{ on: panel === t.id }"
|
||||||
|
:aria-expanded="panel === t.id"
|
||||||
|
:disabled="t.id === 'edit' && saving"
|
||||||
|
@click="toggle(t.id)"
|
||||||
|
>
|
||||||
|
{{ t.label }}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<form v-if="editing" class="editor" @submit.prevent="saveMeta">
|
<div v-if="saving || busy.length" class="admin-row status" role="status">
|
||||||
|
<span v-if="saving" class="muted">Saving to git…</span>
|
||||||
|
<span v-for="b in busy" :key="b" class="working">{{ b }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form v-if="panel === 'edit'" class="editor panel" @submit.prevent="saveMeta">
|
||||||
<label>
|
<label>
|
||||||
Problem link
|
Problem link
|
||||||
<input v-model="draftUrl" type="url" placeholder="https://usaco.org/index.php?page=viewproblem2&cpid=…" />
|
<input v-model="draftUrl" type="url" placeholder="https://usaco.org/index.php?page=viewproblem2&cpid=…" />
|
||||||
@@ -288,13 +332,11 @@ const moves = computed(() => {
|
|||||||
</label>
|
</label>
|
||||||
<div class="admin-row">
|
<div class="admin-row">
|
||||||
<button class="btn primary" type="submit" :disabled="saving">Save</button>
|
<button class="btn primary" type="submit" :disabled="saving">Save</button>
|
||||||
<button class="btn" type="button" :disabled="saving" @click="editing = false">Cancel</button>
|
<button class="btn" type="button" :disabled="saving" @click="panel = ''">Cancel</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<p v-if="editError" class="error">{{ editError }}</p>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section v-if="admin" class="stuck card">
|
<div v-if="panel === 'explain'" class="panel">
|
||||||
<h2>Stuck?</h2>
|
<h2>Stuck?</h2>
|
||||||
<p class="muted">
|
<p class="muted">
|
||||||
Claude writes an intuitive explanation with diagrams, laid out as hints you open one at a time. It takes a
|
Claude writes an intuitive explanation with diagrams, laid out as hints you open one at a time. It takes a
|
||||||
@@ -306,29 +348,31 @@ const moves = computed(() => {
|
|||||||
<button class="btn primary" :disabled="job.state === 'running' || !canExplain" @click="explain">
|
<button class="btn primary" :disabled="job.state === 'running' || !canExplain" @click="explain">
|
||||||
{{ problem.explanation ? "Explain again" : "Explain" }}
|
{{ problem.explanation ? "Explain again" : "Explain" }}
|
||||||
</button>
|
</button>
|
||||||
<span v-if="job.state === 'running'" class="muted">Claude is writing it…</span>
|
<span v-if="!canExplain" class="muted">Add a link or the statement first.</span>
|
||||||
<span v-else-if="!canExplain" class="muted">Add a link or the statement first.</span>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p v-if="job.state === 'error'" class="error">{{ job.error }}</p>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section v-if="admin" class="stuck card">
|
<div v-if="panel === 'review'" class="panel">
|
||||||
<h2>Review my explanation</h2>
|
<h2>Review my explanation</h2>
|
||||||
<p class="muted">
|
<p class="muted">
|
||||||
Record yourself explaining your solution as you would to an interviewer, then upload it (mp3, m4a, wav,
|
Record yourself explaining your solution as you would to an interviewer, then upload it (mp3, m4a, wav,
|
||||||
webm, ogg or flac, up to 25 MB). It is transcribed, and Claude gives feedback on the approach and on your
|
webm, ogg or flac, up to 25 MB). It is transcribed, and Claude gives feedback on the approach and on your
|
||||||
delivery. Each review is committed under <code>reviews/</code>.
|
delivery. Each review is committed under <code>reviews/</code>.
|
||||||
</p>
|
</p>
|
||||||
<input ref="recordingInput" type="file" accept="audio/*,.mp3,.m4a,.wav,.webm,.ogg,.flac" @change="pickRecording" />
|
<input type="file" accept="audio/*,.mp3,.m4a,.wav,.webm,.ogg,.flac" @change="pickRecording" />
|
||||||
<textarea v-model="reviewNote" rows="2" placeholder="Optional context: a mock interview, a time limit, what to focus on"></textarea>
|
<textarea v-model="reviewNote" rows="2" placeholder="Optional context: a mock interview, a time limit, what to focus on"></textarea>
|
||||||
<div class="admin-row">
|
<div class="admin-row">
|
||||||
<label class="check"><input v-model="reviewCode" type="checkbox" /> Include my code</label>
|
<label class="check"><input v-model="reviewCode" type="checkbox" /> Include my code</label>
|
||||||
<button class="btn primary" :disabled="!canReview" @click="submitReview">Review</button>
|
<button class="btn primary" :disabled="!canReview" @click="submitReview">Review</button>
|
||||||
<span v-if="reviewJob.state === 'uploading'" class="muted">Uploading…</span>
|
<span v-if="!canExplain" class="muted">Add a link or the statement first.</span>
|
||||||
<span v-else-if="reviewJob.state === 'running'" class="muted">Transcribing and reviewing… this takes a minute or two.</span>
|
|
||||||
<span v-else-if="!canExplain" class="muted">Add a link or the statement first.</span>
|
|
||||||
</div>
|
</div>
|
||||||
<p v-if="reviewJob.state === 'error'" class="error">{{ reviewJob.error }}</p>
|
</div>
|
||||||
|
|
||||||
|
<!-- Outside the panels, so a job that fails after its panel was
|
||||||
|
closed still says so. -->
|
||||||
|
<p v-if="editError" class="error">{{ editError }}</p>
|
||||||
|
<p v-if="job.state === 'error'" class="error">Explain: {{ job.error }}</p>
|
||||||
|
<p v-if="reviewJob.state === 'error'" class="error">Review: {{ reviewJob.error }}</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section v-if="notesHtml" class="notes card prose" v-html="notesHtml"></section>
|
<section v-if="notesHtml" class="notes card prose" v-html="notesHtml"></section>
|
||||||
@@ -489,23 +533,64 @@ h2 {
|
|||||||
padding: 2px 10px;
|
padding: 2px 10px;
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
}
|
}
|
||||||
.stuck {
|
.sep {
|
||||||
padding: 12px 16px 16px;
|
width: 1px;
|
||||||
|
align-self: stretch;
|
||||||
|
margin: 0 4px;
|
||||||
|
background: var(--color-line-soft);
|
||||||
|
}
|
||||||
|
/* On a phone the buttons wrap, and the divider would end a line. */
|
||||||
|
@media (max-width: 639px) {
|
||||||
|
.sep {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.btn.tool.on {
|
||||||
|
border-color: var(--color-ink);
|
||||||
|
background: var(--color-paper-shade);
|
||||||
|
}
|
||||||
|
.status {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
/* A pulsing dot: the job is still going, and the page is polling for it. */
|
||||||
|
.working::before {
|
||||||
|
content: "";
|
||||||
|
display: inline-block;
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
margin-right: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--color-solving);
|
||||||
|
animation: pulse 1.2s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
@keyframes pulse {
|
||||||
|
50% {
|
||||||
|
opacity: 0.25;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.working::before {
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.panel {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
|
padding-top: 12px;
|
||||||
|
border-top: 1px solid var(--color-line-soft);
|
||||||
}
|
}
|
||||||
.stuck h2 {
|
.panel h2 {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
.stuck p {
|
.panel p {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
}
|
}
|
||||||
.stuck code {
|
.panel code {
|
||||||
font-family: var(--font-mono);
|
font-family: var(--font-mono);
|
||||||
font-size: 0.85em;
|
font-size: 0.85em;
|
||||||
}
|
}
|
||||||
.stuck textarea {
|
.panel textarea {
|
||||||
padding: 8px 10px;
|
padding: 8px 10px;
|
||||||
border: 1px solid var(--color-line);
|
border: 1px solid var(--color-line);
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
@@ -513,10 +598,22 @@ h2 {
|
|||||||
color: var(--color-ink);
|
color: var(--color-ink);
|
||||||
background: var(--color-paper);
|
background: var(--color-paper);
|
||||||
}
|
}
|
||||||
.stuck input[type="file"] {
|
.panel input[type="file"] {
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
.panel input[type="file"]::file-selector-button {
|
||||||
|
margin-right: 10px;
|
||||||
|
padding: 6px 14px;
|
||||||
|
border: 1px solid var(--color-line);
|
||||||
|
border-radius: 4px;
|
||||||
|
background: var(--color-paper);
|
||||||
|
color: var(--color-ink);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.panel input[type="file"]::file-selector-button:hover {
|
||||||
|
border-color: var(--color-ink-muted);
|
||||||
|
}
|
||||||
.check {
|
.check {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
Reference in New Issue
Block a user