Fix Docker build error; add multi-year view, PDF export, ntfy notifier
Fix: remove unused 'accessibleMonths' variable (tsc exit code 2) Features: - AllYearsLetter view: all years in chronological order, reachable from "All Years" at the top of the sidebar - PDF export: window.print() with @media print CSS — sidebar, toolbar, and chrome hidden; each year starts on a new page via page-break - "Download all" exports a plain-text file of every year's letter - ntfy notifier: standalone Node.js service (notifier/) that fires a push notification via ntfy on the 1st of each month; configurable via NTFY_TOPIC, NTFY_URL, CRON_SCHEDULE, APP_URL env vars - docker-compose: adds `notifier` service alongside `app`; reads from .env (example in .env.example); NTFY_TEST_ON_START=true sends a test ping on container start Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
54d54c2e1a
commit
7f38c038fb
11 files changed
+275
-2
No files matched your search
@@ -6,6 +6,7 @@ import { LetterView } from "./components/LetterView";
|
||||
import { Welcome } from "./components/Welcome";
|
||||
import { PodcastYearEndForm } from "./components/PodcastYearEnd";
|
||||
import { Home } from "./components/Home";
|
||||
import { AllYearsLetter } from "./components/AllYearsLetter";
|
||||
import {
|
||||
load,
|
||||
save,
|
||||
@@ -100,6 +101,9 @@ export default function App() {
|
||||
{view.kind === "letter" && (
|
||||
<LetterView data={data} year={view.year} />
|
||||
)}
|
||||
{view.kind === "allYears" && (
|
||||
<AllYearsLetter data={data} />
|
||||
)}
|
||||
{view.kind === "podcast" && (
|
||||
<PodcastYearEndForm
|
||||
key={view.year}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import { useRef } from "react";
|
||||
import { generateLetter } from "../utils/letterTemplate";
|
||||
import type { AppData } from "../types";
|
||||
|
||||
interface AllYearsLetterProps {
|
||||
data: AppData;
|
||||
}
|
||||
|
||||
export function AllYearsLetter({ data }: AllYearsLetterProps) {
|
||||
const contentRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const years = Array.from(
|
||||
new Set([
|
||||
...data.monthlyEntries.map((e) => e.year),
|
||||
...data.yearEndEntries.map((e) => e.year),
|
||||
])
|
||||
).sort((a, b) => b - a); // newest first
|
||||
|
||||
if (years.length === 0) {
|
||||
return (
|
||||
<div className="letter-view">
|
||||
<h2>All Years</h2>
|
||||
<p style={{ color: "var(--text-muted)", marginTop: 16, fontStyle: "italic" }}>
|
||||
No entries yet. Fill in some months to see your letters here.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function handlePrint() {
|
||||
window.print();
|
||||
}
|
||||
|
||||
function handleDownload() {
|
||||
const lines: string[] = [];
|
||||
for (const year of [...years].reverse()) {
|
||||
lines.push(generateLetter(data, year));
|
||||
lines.push("\n\n" + "─".repeat(60) + "\n\n");
|
||||
}
|
||||
const blob = new Blob([lines.join("")], { type: "text/plain" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = `${data.name || "my"}-letters-all-years.txt`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="letter-view">
|
||||
<div className="letter-toolbar">
|
||||
<h2>All Years</h2>
|
||||
<div className="toolbar-actions">
|
||||
<button className="btn-secondary" onClick={handleDownload}>
|
||||
Download all
|
||||
</button>
|
||||
<button className="btn-secondary" onClick={handlePrint}>
|
||||
Export PDF
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ref={contentRef} className="all-years-content">
|
||||
{[...years].reverse().map((year, i) => {
|
||||
const letter = generateLetter(data, year);
|
||||
const rendered = renderMarkdown(letter);
|
||||
return (
|
||||
<div key={year} className="year-letter-block print-page-break">
|
||||
{i > 0 && <div className="year-divider" />}
|
||||
<div
|
||||
className="letter-content"
|
||||
dangerouslySetInnerHTML={{ __html: rendered }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function renderMarkdown(text: string): string {
|
||||
return text
|
||||
.split(/\n\n+/)
|
||||
.map((para) => {
|
||||
const inner = para
|
||||
.split("\n")
|
||||
.map((line) => {
|
||||
line = line.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>");
|
||||
line = line.replace(/\*(.+?)\*/g, "<em>$1</em>");
|
||||
return line;
|
||||
})
|
||||
.join("<br/>");
|
||||
return `<p>${inner}</p>`;
|
||||
})
|
||||
.join("");
|
||||
}
|
||||
@@ -14,7 +14,6 @@ export function Home({ data, currentYear, currentMonth, onNavigate }: HomeProps)
|
||||
const yearEnd = data.yearEndEntries.find((e) => e.year === currentYear);
|
||||
const podcast = data.podcastEntries?.find((e) => e.year === currentYear);
|
||||
|
||||
const accessibleMonths = currentMonth + 1; // 0-indexed, months up to today
|
||||
const completedMonths = monthEntries.length;
|
||||
const pct = Math.round((completedMonths / 12) * 100);
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ export type View =
|
||||
| { kind: "month"; year: number; month: number }
|
||||
| { kind: "yearEnd"; year: number }
|
||||
| { kind: "letter"; year: number }
|
||||
| { kind: "podcast"; year: number };
|
||||
| { kind: "podcast"; year: number }
|
||||
| { kind: "allYears" };
|
||||
|
||||
interface SidebarProps {
|
||||
data: AppData;
|
||||
@@ -36,6 +37,17 @@ export function Sidebar({
|
||||
<span className="brand-name">Annual Letter</span>
|
||||
</button>
|
||||
|
||||
<ul className="sidebar-months" style={{ marginBottom: 8 }}>
|
||||
<li>
|
||||
<button
|
||||
className={`sidebar-item sidebar-letter ${view.kind === "allYears" ? "active" : ""}`}
|
||||
onClick={() => onViewChange({ kind: "allYears" })}
|
||||
>
|
||||
<span className="sidebar-item-name">📚 All Years</span>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
{years.map((year) => {
|
||||
const monthEntries = data.monthlyEntries.filter((e) => e.year === year);
|
||||
const yearEndEntry = data.yearEndEntries.find((e) => e.year === year);
|
||||
|
||||
@@ -377,6 +377,56 @@ body { font-family: "Georgia", serif; background: var(--bg); color: var(--text);
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
/* ─── All-years view ─────────────────────────────────────────────────────── */
|
||||
.all-years-content { display: flex; flex-direction: column; gap: 0; }
|
||||
.year-letter-block { }
|
||||
.year-divider { border: none; border-top: 2px dashed var(--border); margin: 48px 0; }
|
||||
|
||||
/* ─── Print / PDF export ─────────────────────────────────────────────────── */
|
||||
@media print {
|
||||
/* Hide everything except the letter content */
|
||||
.sidebar,
|
||||
.letter-toolbar,
|
||||
.toolbar-actions,
|
||||
.home-header button,
|
||||
.tab-bar {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.layout {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.main {
|
||||
padding: 0;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.letter-content,
|
||||
.all-years-content .letter-content {
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
padding: 0;
|
||||
max-width: 100%;
|
||||
font-size: 11pt;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.year-divider {
|
||||
border-top: 1px solid #999;
|
||||
margin: 32pt 0;
|
||||
}
|
||||
|
||||
/* Each year starts on a new page */
|
||||
.print-page-break + .print-page-break {
|
||||
page-break-before: always;
|
||||
}
|
||||
|
||||
@page {
|
||||
margin: 1.2in 1in;
|
||||
}
|
||||
}
|
||||
|
||||
/* ─── Tabs ───────────────────────────────────────────────────────────────── */
|
||||
.tab-bar {
|
||||
display: flex;
|
||||
|
||||
Reference in new issue
Block a user