Trim comments to the non-obvious why
Drop narration, history and restated-code comments across the repo, keep short ones for security boundaries, upstream quirks and ordering constraints, and record the convention in CLAUDE.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -1,27 +1,12 @@
|
||||
<script setup>
|
||||
/**
|
||||
* Editable cover letter (contenteditable fields, print to PDF), split into
|
||||
* named sections whose paragraphs can be dragged within and between them.
|
||||
* STATUS: live — CV.vue imports it as the "Cover Letter" tab on /cv.
|
||||
*
|
||||
* Everyone gets the editor; /cv is public and nothing here needs the server
|
||||
* until something is saved. An admin also gets the toolbar (saved letters,
|
||||
* stores/coverLetters.js) and the paragraph bank (CoverSnippetBank.vue,
|
||||
* stores/coverSnippets.js). The letter's data shape and the moves live in
|
||||
* ./coverLetter.js.
|
||||
*
|
||||
* Section titles are editor furniture: they are `no-print`, so the printed
|
||||
* letter is one run of paragraphs, as it was before sections existed.
|
||||
*
|
||||
* Editing: contenteditable elements are filled with v-text and read back on
|
||||
* blur. v-text, not {{ }}, because it replaces the element's whole content —
|
||||
* an interpolated text node would sit alongside the <div>s a browser adds on
|
||||
* Enter and duplicate the text when Vue patched it.
|
||||
*
|
||||
* Dragging is native HTML5 DnD. `drag` holds what is in flight (dataTransfer
|
||||
* can't be read until the drop) and `dropAt` where it would land, which is
|
||||
* what draws the indicator line. Only the ⋮⋮ handle is draggable, so text in
|
||||
* a paragraph stays selectable.
|
||||
* Editable cover letter with draggable paragraphs and sections.
|
||||
* STATUS: live — the "Cover Letter" tab on /cv.
|
||||
* Admins also get saved letters and the paragraph bank. Data shape and moves
|
||||
* are in ./coverLetter.js.
|
||||
* contenteditable fields use v-text, not {{ }}: an interpolated text node would
|
||||
* duplicate text alongside the <div>s browsers add on Enter. Only the ⋮⋮
|
||||
* handle drags, so paragraph text stays selectable.
|
||||
*/
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
@@ -46,8 +31,7 @@ const isAdmin = computed(() => auth.loggedIn && !!auth.user.admin);
|
||||
const letter = ref(newLetter());
|
||||
// The open saved letter's id, or null for one never saved (or deleted).
|
||||
const currentId = ref(null);
|
||||
// The body as last saved or loaded; the letter is unsaved when it differs.
|
||||
// Starts as the blank template so an untouched page doesn't nag.
|
||||
// Starts as the blank template so an untouched page isn't "unsaved".
|
||||
const savedBody = ref(serialize(letter.value));
|
||||
const dirty = computed(() => serialize(letter.value) !== savedBody.value);
|
||||
const current = computed(() =>
|
||||
@@ -59,8 +43,7 @@ const error = ref("");
|
||||
|
||||
onMounted(() => auth.ensureLoaded());
|
||||
|
||||
// The stores are admin only, so they are fetched once an admin is known,
|
||||
// which can be after mount on a cold load.
|
||||
// Admin is known only after mount on a cold load.
|
||||
watch(
|
||||
isAdmin,
|
||||
(admin) => {
|
||||
@@ -71,8 +54,7 @@ watch(
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
// Closing the tab with unsaved changes asks first. Only for an admin, who
|
||||
// can save; a visitor's letter is throwaway by design.
|
||||
// Only admins can save; a visitor's letter is throwaway.
|
||||
function onBeforeUnload(event) {
|
||||
if (isAdmin.value && dirty.value) event.preventDefault();
|
||||
}
|
||||
@@ -102,8 +84,7 @@ function discardOk() {
|
||||
function open(letterRow) {
|
||||
letter.value = parseBody(letterRow.body);
|
||||
currentId.value = letterRow.id;
|
||||
// The normalised form, not the raw body, so an older row doesn't open
|
||||
// already marked unsaved.
|
||||
// Normalised, so an older row doesn't open as unsaved.
|
||||
savedBody.value = serialize(letter.value);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user