1
0
Fork 0

Compare commits

..

No commits in common. "45c626bbd291a204456415e79dae9021ff93892c" and "9dea9d1e3628461e412c6ca918a73c8cafe4e8c6" have entirely different histories.

4 changed files with 2 additions and 96 deletions

View file

@ -78,8 +78,6 @@ export default async function JournalDetailPage({
const missionsResult = await payload.find({
collection: "missions",
// Only main operations are eligible as a journal's related mission.
where: { operationType: { equals: "main" } },
limit: 200,
depth: 0,
sort: "-id",

View file

@ -9,25 +9,6 @@ import { emitGameEvent } from "@/utils/event-log/emit";
import { EventTypes } from "@/utils/event-log/eventTypes";
import type { Journal } from "@/payload-types";
/**
* Earliest allowed in-universe date for journal entries (unit founding,
* 2156-03-19). Stored as a UTC-midnight epoch so it compares cleanly against
* the ISO `occurredAt` the client sends.
*/
const MIN_OCCURRENCE_DATE = Date.parse("2156-03-19T00:00:00.000Z");
/**
* Days the in-game clock runs ahead of real time. The latest allowed in-world
* journal date is exactly this many days from the real "now", so the picker
* never lets an author write about the in-game future.
*/
const MAX_OCCURRENCE_OFFSET_DAYS = 47_326;
/** Latest allowed in-world date as an instant: real now + the game's offset. */
function maxOccurrenceInstant(): number {
return Date.now() + MAX_OCCURRENCE_OFFSET_DAYS * 86_400_000;
}
export interface ActionResult<T = undefined> {
success: boolean;
error?: string;
@ -64,17 +45,6 @@ function validate(input: JournalInput): string | null {
if (!root || !Array.isArray(root.children) || root.children.length === 0) {
return "Entry body is required.";
}
if (input.occurredAt) {
const occurred = Date.parse(input.occurredAt);
if (!Number.isNaN(occurred)) {
if (occurred < MIN_OCCURRENCE_DATE) {
return "The in-world date cannot be before March 19, 2156.";
}
if (occurred > maxOccurrenceInstant()) {
return "The in-world date cannot be after the current in-game date.";
}
}
}
return null;
}

View file

@ -51,8 +51,6 @@ export default async function JournalsPage() {
const missionsResult = await payload.find({
collection: "missions",
// Only main operations are eligible as a journal's related mission.
where: { operationType: { equals: "main" } },
limit: 200,
depth: 0,
sort: "-id",

View file

@ -29,48 +29,6 @@ import {
} from "@/components/frontend/intelligence/LexicalRichTextEditor";
import { createJournal, updateJournal } from "@/app/(frontend)/journals/actions";
/**
* Days the in-game clock runs ahead of real time. The in-world date picker is
* capped exactly this many days from "now", so it lines up with the game's
* present and never lets an author pick a date in the in-game future.
*/
export const MAX_OCCURRENCE_OFFSET_DAYS = 47_326;
/** Format a Date as a local yyyy-MM-dd string (the <input type="date"> value form). */
function toYMD(date: Date): string {
const y = date.getFullYear();
const m = String(date.getMonth() + 1).padStart(2, "0");
const d = String(date.getDate()).padStart(2, "0");
return `${y}-${m}-${d}`;
}
/**
* The Awakening: the campaign's start date (2156-03-19). In-world dates are
* measured from here, so the subtitle can say how many days in-universe it has
* been since it all began.
*/
const AWAKENING_EPOCH = Date.parse("2156-03-19T00:00:00.000Z");
/**
* Format a yyyy-MM-dd in-universe date as a locale string (e.g. "May 10, 2156").
* Built in local time so formatting never shifts the calendar day.
*/
function formatInWorldDate(ymd: string): string {
const [y, m, d] = ymd.split("-").map(Number);
return new Intl.DateTimeFormat("en-US", {
month: "long",
day: "numeric",
year: "numeric",
}).format(new Date(y, m - 1, d));
}
/** Whole calendar days between a yyyy-MM-dd date and the Awakening. */
function daysSinceAwakening(ymd: string): number {
const [y, m, d] = ymd.split("-").map(Number);
const occurredUTC = Date.UTC(y, m - 1, d);
return Math.round((occurredUTC - AWAKENING_EPOCH) / 86_400_000);
}
export interface MissionOption {
id: number;
label: string;
@ -111,12 +69,9 @@ export function JournalFormDialog({
const router = useRouter();
const isEdit = typeof draft.id === "number";
// Latest selectable in-world date: real now + the game's clock offset.
const maxAttr = toYMD(new Date(Date.now() + MAX_OCCURRENCE_OFFSET_DAYS * 86_400_000));
const [title, setTitle] = React.useState(draft.title);
const [status, setStatus] = React.useState<"draft" | "published">(draft.status);
const [occurredAt, setOccurredAt] = React.useState(draft.occurredAt || maxAttr);
const [occurredAt, setOccurredAt] = React.useState(draft.occurredAt);
const [missionId, setMissionId] = React.useState<string>(
draft.missionId === null ? "none" : String(draft.missionId),
);
@ -128,21 +83,11 @@ export function JournalFormDialog({
if (!open) return;
setTitle(draft.title);
setStatus(draft.status);
setOccurredAt(draft.occurredAt || maxAttr);
setOccurredAt(draft.occurredAt);
setMissionId(draft.missionId === null ? "none" : String(draft.missionId));
setBody(draft.body);
}, [open, draft]);
// Subtitle under the date picker: locale date + days since the Awakening.
// Pre-Awakening dates (older seed data) can't be selected in the picker, so
// show just the locale date rather than a negative "days since" count.
const daysSince = occurredAt ? daysSinceAwakening(occurredAt) : null;
const sinceAwakening =
daysSince !== null && daysSince >= 0
? ` - ${daysSince} ${daysSince === 1 ? "day" : "days"} since awakening`
: "";
const dateSubtitle = occurredAt ? `${formatInWorldDate(occurredAt)}${sinceAwakening}` : null;
const handleSubmit = async () => {
setSaving(true);
const input = {
@ -210,14 +155,9 @@ export function JournalFormDialog({
<Input
id="journal-date"
type="date"
min="2156-03-19"
max={maxAttr}
value={occurredAt}
onChange={(e) => setOccurredAt(e.target.value)}
/>
{dateSubtitle && (
<p className="text-xs text-muted-foreground">{dateSubtitle}</p>
)}
</div>
<div className="flex flex-col gap-1.5">
<Label>Related mission</Label>