diff --git a/src/actions.ts b/src/actions.ts index 5121f40..0e62f28 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -1,8 +1,11 @@ import { batch } from '@preact/signals' import { fetchArea } from './fetch' -import { D2R } from './geo' +import { bboxOf } from './building' +import { D2R, ll2m, m2ll } from './geo' import { t } from './i18n' import { writeHash } from './persist' +import { frameCovered, frameRadius } from './page' +import { renderPrintMap } from './print' import { fitView } from './render' import { base, @@ -14,6 +17,17 @@ import { progress, radius, rawBuildings, + rawParcels, + answered, + commentary, + mapAuthor, + mapTitle, + mixMin, + mode, + orientation, + overrides, + printJob, + showFrame, S, sel, status, @@ -34,23 +48,45 @@ export function showToast(fn: () => string) { toastTimer = setTimeout(() => (toast.value = null), 2400) } -export function applyData(d: AreaData, lon: number, lat: number) { +/** + * Show loaded data. r: the load radius (to know which area is covered); + * keepView: centre the view on (lon, lat) and keep the zoom, instead of fitting to the data. + */ +export function applyData(d: AreaData, lon: number, lat: number, r?: number, keepView = false) { S.center = [lon, lat] S.K = Math.cos(lat * D2R) S.loaded = true + if (r) { + const [cx, cy] = ll2m(lon, lat), + h = (1.1 * r * 0.995) / S.K + S.loadedBB = [cx - h, cy - h, cx + h, cy + h] + } else S.loadedBB = bboxOf(d.buildings.flatMap((b) => b.rings)) // fitView inside the batch so the map redraw triggered by the new data uses the new view batch(() => { rawBuildings.value = d.buildings + rawParcels.value = d.parcels base.value = d.base sel.value = null hidden.value = new Set() - fitView() + if (!keepView) fitView() + else { + const [cx, cy] = ll2m(lon, lat) + S.view = { ...S.view, cx, cy } + } }) } +/** Radius to load: in the HG3 mode with the frame on, at least enough for the A4 frame. */ +const loadRadius = () => + mode.value === 'hg3' && showFrame.value ? Math.max(radius.value, frameRadius()) : radius.value + let loadSeq = 0 /** Load an area from ČÚZK. A newer call supersedes one still in flight. */ -export async function liveLoad(p: LatLon, quietFallback: boolean): Promise { +export async function liveLoad( + p: LatLon, + quietFallback: boolean, + keepView = false, +): Promise { const my = ++loadSeq const current = () => my === loadSeq batch(() => { @@ -59,7 +95,7 @@ export async function liveLoad(p: LatLon, quietFallback: boolean): Promise t('st_loading')) }) try { - const r = radius.value + const r = loadRadius() const d = await fetchArea(p.lon, p.lat, r, (done, total) => { if (current()) progress.value = { done, total } }) @@ -68,7 +104,7 @@ export async function liveLoad(p: LatLon, quietFallback: boolean): Promise t('st_none'), 'err') return false } - applyData(d, p.lon, p.lat) + applyData(d, p.lon, p.lat, r, keepView) writeHash(p, r) lastLoc.value = { lat: p.lat, lon: p.lon } const loc = `${p.lat.toFixed(5)}, ${p.lon.toFixed(5)}`, @@ -133,3 +169,86 @@ export async function copyLink() { window.prompt(t('copyLink'), location.href) } } + +/** Load data for the A4 frame around the current view centre, keeping the view. */ +export function loadFrame() { + const [lon, lat] = m2ll(S.view.cx, S.view.cy) + locText.value = `${lat.toFixed(6)}, ${lon.toFixed(6)}` + return liveLoad({ lat, lon }, false, true) +} + +/* ================= printing ================= */ +/** Render the A4 map and open the print dialog for the submission PDF or the field worksheet. */ +export async function preparePrint(kind: 'submission' | 'worksheet') { + if (!frameCovered()) { + setStatus(() => t('needData'), 'err') + return + } + showToast(() => t('preparing')) + await new Promise((r) => setTimeout(r, 30)) // let the toast paint before the heavy render + const mapUrl = await renderPrintMap(kind === 'worksheet') + printJob.value = { kind, mapUrl } + // wait for PrintView to render and the map image to decode + await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))) + await document + .querySelector('.print-root img') + ?.decode() + .catch(() => {}) + window.print() +} + +/* ================= project file ================= */ +const PROJECT_APP = 'building-use-map/hg3' + +export function projectData() { + return { + app: PROJECT_APP, + version: 1, + savedAt: new Date().toISOString(), + location: lastLoc.value, + radius: radius.value, + view: lastLoc.value ? m2ll(S.view.cx, S.view.cy) : null, + orientation: orientation.value, + title: mapTitle.value, + author: mapAuthor.value, + mixMin: mixMin.value, + overrides: overrides.value, + commentary: commentary.value, + answered: answered.value, + } +} + +/** Restore a project saved with "Save project" and load its area. */ +export async function openProject(file: File) { + let d: Partial> + try { + d = JSON.parse(await file.text()) + } catch { + d = {} + } + if (d.app !== PROJECT_APP) { + setStatus(() => t('projectBad'), 'err') + return + } + batch(() => { + if (d.overrides && typeof d.overrides === 'object') overrides.value = { ...d.overrides } + if (typeof d.commentary === 'string') commentary.value = d.commentary + if (Array.isArray(d.answered)) answered.value = d.answered.filter((n) => typeof n === 'number') + if (typeof d.title === 'string') mapTitle.value = d.title + if (typeof d.author === 'string') mapAuthor.value = d.author + if (d.orientation === 'landscape' || d.orientation === 'portrait') + orientation.value = d.orientation + if (d.mixMin === 0 || d.mixMin === 1 || d.mixMin === 2) mixMin.value = d.mixMin + if (typeof d.radius === 'number' && d.radius >= 100 && d.radius <= 700) radius.value = d.radius + mode.value = 'hg3' + }) + showToast(() => t('projectLoaded')) + // load the saved frame position (view centre), else the saved location + const v = + Array.isArray(d.view) && d.view.length === 2 ? { lon: +d.view[0], lat: +d.view[1] } : null + const p = v ?? d.location + if (p && typeof p.lat === 'number' && typeof p.lon === 'number') { + locText.value = `${p.lat.toFixed(6)}, ${p.lon.toFixed(6)}` + await liveLoad(p, false, !!v) + } +} diff --git a/src/building.ts b/src/building.ts index cec6cf2..a4547da 100644 --- a/src/building.ts +++ b/src/building.ts @@ -1,16 +1,8 @@ -import type { Building, Ring } from './types' +import type { BBox, Building, Parcel, Ring } from './types' type Num = number | string | null | undefined -export function mkBuilding( - cp: Num, - use: Num, - flats: Num, - floors: Num, - area: Num, - done: number | null | undefined, - rings: Ring[], -): Building { +export function bboxOf(rings: Ring[]): BBox { let x0 = 1e18, y0 = 1e18, x1 = -1e18, @@ -22,17 +14,60 @@ export function mkBuilding( if (p[1] < y0) y0 = p[1] if (p[1] > y1) y1 = p[1] } + return [x0, y0, x1, y1] +} + +const num = (v: Num) => (v == null || v === '' ? null : +v) + +export function mkBuilding( + id: Num, + parcel: Num, + cp: Num, + use: Num, + flats: Num, + floors: Num, + area: Num, + done: number | null | undefined, + rings: Ring[], +): Building { const year = done != null && isFinite(done) ? new Date(done).getUTCFullYear() : null return { + kind: 'b', + id: String(id ?? ''), + parcel: parcel == null ? null : String(parcel), cp: (cp || '').toString().trim(), use: use == null ? 0 : +use, - flats: flats == null ? null : +flats, - floors: floors == null ? null : +floors, - area: area == null ? null : +area, + flats: num(flats), + floors: num(floors), + area: num(area), year, rings, - bb: [x0, y0, x1, y1], - cat: 'other', - sc: 'other', + bb: bboxOf(rings), + auto: 'ost', + hg: 'ost', + cat: 'ost', + } +} + +export function mkParcel( + id: Num, + numText: Num, + druh: Num, + use: Num, + area: Num, + rings: Ring[], +): Parcel { + return { + kind: 'p', + id: String(id ?? ''), + num: (numText ?? '').toString(), + druh: num(druh), + use: num(use), + area: num(area), + rings, + bb: bboxOf(rings), + auto: 'ostn', + hg: 'ostn', + cat: 'ostn', } } diff --git a/src/categories.ts b/src/categories.ts index 9d0f662..8238d0f 100644 --- a/src/categories.ts +++ b/src/categories.ts @@ -1,71 +1,129 @@ -import { t, tKey, ruianUseName } from './i18n' import { computed } from '@preact/signals' -import { mixMin, mode, rawBuildings } from './state' -import type { Building } from './types' +import { ruianUseName, t, tKey } from './i18n' +import { mixMin, mode, overrides, rawBuildings, rawParcels } from './state' +import type { Building, MapItem } from './types' -/* ================= categories ================= */ -// Simple scheme: key, colour, show house number -type SimpleDef = [key: string, color: string, nums: 0 | 1] -export const SIMPLE: SimpleDef[] = [ - ['res', '#000000', 0], - ['unit', '#d62728', 1], - ['rec', '#2ca02c', 1], - ['mix', '#ff8c00', 1], - ['civic', '#1f5fbf', 1], - ['assem', '#4fb3e8', 1], - ['shop', '#e377c2', 1], - ['hotel', '#e8c000', 1], - ['office', '#17808a', 1], - ['ind', '#7b3294', 1], - ['agri', '#8c564b', 0], - ['tech', '#4d4d4d', 0], - ['garage', '#d9b77e', 0], - ['other', '#bdbdbd', 0], +/* ================= HG3 semester project categories ================= + * Exactly the 16 categories required by the assignment ("Humánní geografie 3: Zadání + * semestrálního projektu"), in its order. Colours follow the crayon legend in the assignment. + */ +export interface HgCat { + key: string + color: string + built: boolean + /** show house numbers for this category at medium zoom */ + nums?: boolean +} +export const HG: HgCat[] = [ + // Zastavěné plochy + { key: 'byt', color: '#f06fc4', built: true, nums: true }, // Bydlení – bytové domy + { key: 'rd', color: '#e53935', built: true }, // Bydlení – rodinné domy + { key: 'rek', color: '#f28a1f', built: true, nums: true }, // Objekty individuální rekreace + { key: 'ver', color: '#7fd0ef', built: true, nums: true }, // Veřejné služby + { key: 'kom', color: '#9a5bd6', built: true, nums: true }, // Komerční služby + { key: 'pru', color: '#8d5a2b', built: true, nums: true }, // Průmysl + { key: 'dop', color: '#a9a9a9', built: true }, // Dopravní sítě a vybavení + { key: 'smi', color: '#8e2463', built: true, nums: true }, // Smíšené plochy + { key: 'ost', color: '#4f79a6', built: true }, // Ostatní plochy (zastavěné) + // Nezastavěné plochy + { key: 'zel', color: '#4caf50', built: false }, // Upravená zeleň + { key: 'zah', color: '#b5dc63', built: false }, // Zahrady + { key: 'pole', color: '#f3c74d', built: false }, // Pole + { key: 'louka', color: '#f6ef8e', built: false }, // Louky + { key: 'les', color: '#1d7a4c', built: false }, // Lesy + { key: 'voda', color: '#3b82d9', built: false }, // Vodní plochy + { key: 'ostn', color: '#d9d4e8', built: false }, // Ostatní plochy (nezastavěné) ] -const SIMPLE_COLOR: Record = Object.fromEntries(SIMPLE.map((c) => [c[0], c[1]])) -export const SIMPLE_NUMS: Record = Object.fromEntries( - SIMPLE.map((c) => [c[0], !!c[2]]), -) -const SIMPLE_ORDER = [ - 'other', - 'garage', - 'agri', - 'tech', - 'ind', - 'office', - 'hotel', - 'shop', - 'assem', - 'civic', - 'res', - 'unit', - 'rec', - 'mix', -] -const USE_CAT: Record = { - 1: 'ind', - 2: 'agri', - 4: 'agri', - 5: 'civic', - 6: 'unit', - 7: 'res', - 8: 'rec', - 9: 'assem', - 10: 'shop', - 11: 'hotel', - 12: 'ind', - 13: 'agri', - 14: 'office', - 15: 'civic', - 16: 'tech', - 17: 'tech', - 18: 'garage', - 19: 'other', - 20: 'other', - 21: 'other', +const HG_BY_KEY = Object.fromEntries(HG.map((c) => [c.key, c])) +export const HG_BUILT = HG.filter((c) => c.built).map((c) => c.key) +export const HG_OPEN = HG.filter((c) => !c.built).map((c) => c.key) +export const isBuilt = (key: string) => !!HG_BY_KEY[key]?.built +export const hgColor = (key: string) => HG_BY_KEY[key]?.color ?? '#bdbdbd' +export const hgLabel = (key: string) => tKey('hg.' + key) +export const isHgKey = (v: unknown): v is string => typeof v === 'string' && v in HG_BY_KEY + +/** RÚIAN building use code → HG3 category (before the mixed-use rule). */ +const BUILDING_HG: Record = { + 1: 'pru', // průmyslový objekt + 2: 'rd', // zemědělská usedlost (a farmhouse is lived in) + 4: 'pru', // objekt lesního hospodářství + 5: 'ver', // objekt občanské vybavenosti + 6: 'byt', // bytový dům + 7: 'rd', // rodinný dům + 8: 'rek', // stavba pro rodinnou rekreaci + 9: 'ver', // stavba pro shromažďování většího počtu osob + 10: 'kom', // stavba pro obchod + 11: 'kom', // stavba ubytovacího zařízení + 12: 'pru', // stavba pro výrobu a skladování + 13: 'pru', // zemědělská stavba + 14: 'kom', // stavba pro administrativu + 15: 'ver', // stavba občanského vybavení + 16: 'ver', // stavba technického vybavení (technické sítě a vybavení) + 17: 'dop', // stavba pro dopravu + 18: 'dop', // garáž +} +const AGRI = new Set([4, 13]) + +export function buildingHg(use: number, flats: number | null): string { + const f = flats || 0 + if (use === 3) return f >= 4 ? 'byt' : 'rd' // "objekt k bydlení" without a finer type + const base = BUILDING_HG[use] ?? 'ost' + // RÚIAN has no mixed class: a non-residential building with flats counts as mixed use + const mixable = + base === 'ver' || base === 'kom' || base === 'ost' || (base === 'pru' && !AGRI.has(use)) + if (mixable && mixMin.value > 0 && f >= mixMin.value) return 'smi' + return base } -// Detailed scheme: one entry per RÚIAN use code +/** Parcel land type / land use → HG3 category; built-up parcels take their building's category. */ +export function parcelHg(druh: number | null, use: number | null, building?: string): string { + switch (druh) { + case 2: // orná půda + case 3: // chmelnice + case 4: // vinice + return 'pole' + case 5: // zahrada + case 6: // ovocný sad + return 'zah' + case 7: // trvalý travní porost + case 8: + return 'louka' + case 10: // lesní pozemek + return 'les' + case 11: // vodní plocha + return 'voda' + case 13: // zastavěná plocha a nádvoří + return building ?? (use === 13 ? 'ostn' : 'ost') + } + switch (use) { + case 14: // dráha + case 15: // dálnice + case 16: // silnice + case 17: // ostatní komunikace + case 18: // ostatní dopravní plocha + return 'dop' + case 19: // zeleň + case 21: // pohřebiště + return 'zel' + case 20: // sportoviště a rekreační plocha + case 22: // kulturní a osvětová plocha + case 29: // fotovoltaická elektrárna (technické vybavení) + return 'ver' + case 12: // společný dvůr + return 'ost' + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 28: + return 'voda' + } + return building ?? 'ostn' // jiná plocha, manipulační plocha, neplodná půda, mez, skládka… +} + +/* ================= detailed scheme: one colour per RÚIAN use code ================= */ const DETAIL_COLOR: Record = { u1: '#7b3294', u2: '#8c564b', @@ -144,57 +202,85 @@ const DETAIL_LIST = [ 'uw', 'u0', ] +const DETAIL_NUMS = new Set([ + 'u6', + 'u3', + 'u8', + 'mix', + 'u5', + 'u15', + 'u9', + 'u10', + 'u11', + 'u14', + 'u1', + 'u12', +]) -export function simpleKey(use: number, flats: number | null): string { - const f = flats || 0 - if (use === 3) return f >= 4 ? 'unit' : 'res' // generic dwelling - const base = USE_CAT[use] || 'other' - if (base === 'res' || base === 'unit' || base === 'rec') return base - if (mixMin.value > 0 && f >= mixMin.value && base !== 'garage' && base !== 'agri') return 'mix' - return base -} -export function detailKey(use: number, sk: string): string { - if (sk === 'mix') return 'mix' +function detailKey(use: number, mixed: boolean): string { + if (mixed) return 'mix' if (use >= 1 && use <= 21) return 'u' + use if (use >= 22 && use <= 29) return 'uw' return 'u0' } + +/* ================= classification ================= */ /** - * Buildings with `sc`/`cat` set for the current colour mode and mixed-use rule. - * Categories are written onto the building objects (so a selected building stays the same object); + * Buildings with categories for the current mode, mixed-use rule and field corrections. + * Categories are written onto the objects (so a selected building stays the same object); * a new array is returned so dependants see a change. */ export const buildings = computed(() => { const list = rawBuildings.value, - m = mode.value + m = mode.value, + ov = overrides.value for (const b of list) { - b.sc = simpleKey(b.use, b.flats) - b.cat = m === 'simple' ? b.sc : detailKey(b.use, b.sc) + b.auto = buildingHg(b.use, b.flats) + b.hg = ov['b:' + b.id] ?? b.auto + b.cat = m === 'hg3' ? b.hg : detailKey(b.use, b.auto === 'smi') } return list.slice() }) -/** - * Category of a building in the current mode. Reading `buildings` first makes sure the - * classification is up to date and subscribes the caller to mode / mixed-use changes. - */ -export function catOf(b: Building): string { - // oxlint-disable-next-line no-unused-expressions - buildings.value - return b.cat +/** Parcels with HG3 categories (only drawn in the HG3 mode). */ +export const parcels = computed(() => { + const ov = overrides.value + const onParcel = new Map() + for (const b of buildings.value) if (b.parcel) onParcel.set(b.parcel, b.hg) + const list = rawParcels.value + for (const p of list) { + p.auto = parcelHg(p.druh, p.use, onParcel.get(p.id)) + p.hg = ov['p:' + p.id] ?? p.auto + p.cat = p.hg + } + return list.slice() +}) + +/** Category of an item in the current mode; reading the lists keeps it current and subscribed. */ +export function catOf(item: MapItem): string { + const list: MapItem[] = item.kind === 'b' ? buildings.value : parcels.value + return list.length >= 0 ? item.cat : item.cat } export const catColor = (key: string): string => - (mode.value === 'simple' ? SIMPLE_COLOR[key] : DETAIL_COLOR[key]) || '#bdbdbd' + (mode.value === 'hg3' ? hgColor(key) : DETAIL_COLOR[key]) || '#bdbdbd' export function catLabel(key: string): string { - if (mode.value === 'simple') return tKey('cat.' + key) + if (mode.value === 'hg3') return hgLabel(key) if (key === 'mix') return t('cat.mix') if (key === 'uw') return ruianUseName('w') if (key === 'u0') return ruianUseName(0) return key.slice(1) + ' · ' + ruianUseName(+key.slice(1)) } -export const catList = () => (mode.value === 'simple' ? SIMPLE.map((c) => c[0]) : DETAIL_LIST) -export const catOrder = () => (mode.value === 'simple' ? SIMPLE_ORDER : DETAIL_ORDER) +/** Legend order. */ +export const catList = () => (mode.value === 'hg3' ? HG.map((c) => c.key) : DETAIL_LIST) +/** Drawing order for buildings (later on top). */ +export const catOrder = () => (mode.value === 'hg3' ? HG.map((c) => c.key) : DETAIL_ORDER) +export const showsNumber = (b: Building) => + mode.value === 'hg3' ? !!HG_BY_KEY[b.cat]?.nums : DETAIL_NUMS.has(b.cat) + +export const overrideKey = (item: MapItem) => (item.kind === 'b' ? 'b:' : 'p:') + item.id +export const isCorrected = (item: MapItem) => overrideKey(item) in overrides.value + export function isDark(hex: string): boolean { const n = parseInt(hex.slice(1), 16), r = n >> 16, diff --git a/src/codes.ts b/src/codes.ts new file mode 100644 index 0000000..a361e44 --- /dev/null +++ b/src/codes.ts @@ -0,0 +1,54 @@ +import { lang } from './i18n' + +/* Names of the cadastral code lists used for parcels (ČÚZK VFR domains). */ + +const DRUH: Record = { + 2: ['orná půda', 'arable land'], + 3: ['chmelnice', 'hop field'], + 4: ['vinice', 'vineyard'], + 5: ['zahrada', 'garden'], + 6: ['ovocný sad', 'orchard'], + 7: ['trvalý travní porost', 'permanent grassland'], + 8: ['trvalý travní porost', 'permanent grassland'], + 10: ['lesní pozemek', 'forest land'], + 11: ['vodní plocha', 'water area'], + 13: ['zastavěná plocha a nádvoří', 'built-up area and courtyard'], + 14: ['ostatní plocha', 'other area'], +} + +const USE: Record = { + 1: ['skleník, pařeniště', 'greenhouse, hotbed'], + 2: ['školka', 'plant nursery'], + 3: ['plantáž dřevin', 'tree plantation'], + 4: ['les jiný než hospodářský', 'non-commercial forest'], + 5: ['lesní pozemek, na kterém je budova', 'forest land with a building'], + 6: ['rybník', 'fishpond'], + 7: ['koryto vodního toku přirozené nebo upravené', 'natural or regulated watercourse'], + 8: ['koryto vodního toku umělé', 'artificial watercourse'], + 9: ['vodní nádrž přírodní', 'natural reservoir'], + 10: ['vodní nádrž umělá', 'artificial reservoir'], + 11: ['zamokřená plocha', 'wetland'], + 12: ['společný dvůr', 'shared courtyard'], + 13: ['zbořeniště', 'demolition site'], + 14: ['dráha', 'railway'], + 15: ['dálnice', 'motorway'], + 16: ['silnice', 'road'], + 17: ['ostatní komunikace', 'other road / path'], + 18: ['ostatní dopravní plocha', 'other transport area'], + 19: ['zeleň', 'greenery'], + 20: ['sportoviště a rekreační plocha', 'sports and recreation ground'], + 21: ['pohřebiště', 'cemetery'], + 22: ['kulturní a osvětová plocha', 'cultural area'], + 23: ['manipulační plocha', 'handling area / yard'], + 24: ['dobývací prostor', 'mining area'], + 25: ['skládka', 'landfill'], + 26: ['jiná plocha', 'other area'], + 27: ['neplodná půda', 'barren land'], + 28: ['vodní plocha, na které je budova', 'water area with a building'], + 29: ['fotovoltaická elektrárna', 'photovoltaic power plant'], + 30: ['mez, stráň', 'balk, slope'], +} + +const pick = (v: [string, string] | undefined) => (v ? v[lang.value === 'cs' ? 0 : 1] : '') +export const druhName = (c: number | null) => (c == null ? '' : pick(DRUH[c])) +export const useLandName = (c: number | null) => (c == null ? '' : pick(USE[c])) diff --git a/src/components/App.tsx b/src/components/App.tsx index b363f0d..e99b773 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -3,7 +3,9 @@ import { useEffect } from 'preact/hooks' import { lang, t } from '../i18n' import { attachKeyboard } from '../interaction' import { toast } from '../state' +import { CommentaryDialog } from './CommentaryDialog' import { MapView } from './MapView' +import { PrintView } from './PrintView' import { Sidebar } from './Sidebar' export function App() { @@ -14,14 +16,19 @@ export function App() { useEffect(attachKeyboard, []) const tst = toast.value return ( -
- - - {tst && ( -
- {tst.fn()} -
- )} -
+ <> +
+ + + {tst && ( +
+ {tst.fn()} +
+ )} +
+ {/* outside #app: print mode hides the app and shows only the print pages */} + + + ) } diff --git a/src/components/CommentaryDialog.tsx b/src/components/CommentaryDialog.tsx new file mode 100644 index 0000000..8348704 --- /dev/null +++ b/src/components/CommentaryDialog.tsx @@ -0,0 +1,91 @@ +import { useEffect, useRef } from 'preact/hooks' +import { lang, t, type MsgKey } from '../i18n' +import { answered, commentary, commentaryOpen } from '../state' +import { MIN_CHARS } from './Project' +import { Icon } from './ui/Icon' + +const QUESTIONS: MsgKey[] = ['q1', 'q2', 'q3', 'q4', 'q5', 'q6'] + +/** Editor for the commentary (pages 3–4 of the submission), with the assignment's questions. */ +export function CommentaryDialog() { + const area = useRef(null) + const open = commentaryOpen.value + useEffect(() => { + if (open) area.current?.focus() + }, [open]) + if (!open) return null + const text = commentary.value, + n = text.length, + words = text.trim() ? text.trim().split(/\s+/).length : 0, + l = lang.value + const done = new Set(answered.value) + const toggle = (i: number) => + (answered.value = done.has(i) ? answered.value.filter((x) => x !== i) : [...answered.value, i]) + const close = () => (commentaryOpen.value = false) + return ( +
{ + if (e.target === e.currentTarget) close() + }} + > +