Add the website: Go server + Vue SPA in site/, with CI
A standalone container for web_server, shaped like job-tracker: serves /usaco/ with solved problems public and solving/skipped plus edits (status, link, notes) for the site admin. Git is the only store: the server clones adamf/usaco from Gitea, pulls on the push webhook, and commits edits back. CI builds the image only when site/ changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,207 @@
|
||||
<script setup>
|
||||
/**
|
||||
* The problem list. Visitors see solved problems; the admin also sees what
|
||||
* is in progress or skipped (the server decides, this only shows the tabs
|
||||
* when there is something behind them). Filter and sort live in the query
|
||||
* string so a filtered view can be linked and survives the back button.
|
||||
*/
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { RouterLink, useRoute, useRouter } from "vue-router";
|
||||
import { listProblems } from "@/api";
|
||||
import { LANG_LABELS, STATUS_LABELS, formatDate, title } from "@/format";
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const problems = ref([]);
|
||||
const admin = ref(false);
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
|
||||
const status = computed({
|
||||
get: () => route.query.status || "all",
|
||||
set: (v) => router.replace({ query: { ...route.query, status: v === "all" ? undefined : v } }),
|
||||
});
|
||||
const sort = computed({
|
||||
get: () => route.query.sort || "recent",
|
||||
set: (v) => router.replace({ query: { ...route.query, sort: v === "recent" ? undefined : v } }),
|
||||
});
|
||||
const search = computed({
|
||||
get: () => route.query.q || "",
|
||||
set: (v) => router.replace({ query: { ...route.query, q: v || undefined } }),
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const data = await listProblems();
|
||||
problems.value = data.problems;
|
||||
admin.value = data.admin;
|
||||
} catch (e) {
|
||||
error.value = e.message;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
const counts = computed(() => {
|
||||
const c = { all: problems.value.length, solved: 0, solving: 0, skipped: 0 };
|
||||
for (const p of problems.value) c[p.status]++;
|
||||
return c;
|
||||
});
|
||||
|
||||
const tabs = computed(() =>
|
||||
admin.value ? ["all", "solving", "solved", "skipped"] : [],
|
||||
);
|
||||
|
||||
// When a problem was last worked on, for sorting: the solve date if it has
|
||||
// one, else its last commit.
|
||||
const when = (p) => p.solvedAt || p.lastTouched || "";
|
||||
|
||||
const shown = computed(() => {
|
||||
const q = search.value.trim().toLowerCase();
|
||||
const list = problems.value.filter(
|
||||
(p) =>
|
||||
(status.value === "all" || p.status === status.value) &&
|
||||
(!q || p.name.includes(q.replace(/\s+/g, "-")) || (p.source || "").toLowerCase().includes(q)),
|
||||
);
|
||||
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));
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section>
|
||||
<p v-if="!loading && !error" class="intro muted">
|
||||
{{ counts.solved }} solved problems from USACO and other judges, each with its solution and test cases.
|
||||
</p>
|
||||
|
||||
<div class="controls">
|
||||
<div v-if="tabs.length" class="tabs" role="tablist">
|
||||
<button
|
||||
v-for="t in tabs"
|
||||
:key="t"
|
||||
role="tab"
|
||||
:aria-selected="status === t"
|
||||
:class="{ on: status === t }"
|
||||
@click="status = t"
|
||||
>
|
||||
{{ t === "all" ? "All" : STATUS_LABELS[t] }} <span class="n">{{ counts[t] }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<input v-model="search" type="search" placeholder="Search problems" aria-label="Search problems" />
|
||||
<select v-model="sort" aria-label="Sort by">
|
||||
<option value="recent">Most recent</option>
|
||||
<option value="name">Name</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<p v-if="loading" class="muted">Loading…</p>
|
||||
<p v-else-if="error" class="error">{{ error }}</p>
|
||||
<p v-else-if="!shown.length" class="muted">Nothing matches.</p>
|
||||
|
||||
<ul v-else class="list">
|
||||
<li v-for="p in shown" :key="p.name">
|
||||
<RouterLink :to="{ name: 'problem', params: { name: p.name } }" class="row card">
|
||||
<div class="main">
|
||||
<span class="name">{{ title(p.name) }}</span>
|
||||
<span class="meta muted">
|
||||
<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.hasNotes"> · notes</template>
|
||||
</span>
|
||||
</div>
|
||||
<div class="side">
|
||||
<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>
|
||||
<time v-if="when(p)" class="muted" :datetime="when(p)">{{ formatDate(when(p)) }}</time>
|
||||
</div>
|
||||
</RouterLink>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.intro {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.controls {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px 12px;
|
||||
align-items: center;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.tabs {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
margin-right: auto;
|
||||
}
|
||||
.tabs button {
|
||||
padding: 4px 12px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid transparent;
|
||||
color: var(--color-ink-muted);
|
||||
cursor: pointer;
|
||||
}
|
||||
.tabs button.on {
|
||||
border-color: var(--color-ink);
|
||||
color: var(--color-ink);
|
||||
background: var(--color-paper);
|
||||
}
|
||||
.tabs .n {
|
||||
color: var(--color-ink-faint);
|
||||
margin-left: 2px;
|
||||
}
|
||||
input,
|
||||
select {
|
||||
padding: 6px 10px;
|
||||
border: 1px solid var(--color-line);
|
||||
border-radius: 4px;
|
||||
background: var(--color-paper);
|
||||
min-width: 0;
|
||||
}
|
||||
input {
|
||||
flex: 1 1 200px;
|
||||
max-width: 320px;
|
||||
}
|
||||
.list {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
}
|
||||
.row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 8px 16px;
|
||||
padding: 12px 16px;
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
.row:hover {
|
||||
border-color: var(--color-ink-faint);
|
||||
}
|
||||
.main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
}
|
||||
.name {
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
.meta {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.side {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
time {
|
||||
min-width: 7.5em;
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user