diff --git a/src/app/(frontend)/journals/actions.ts b/src/app/(frontend)/journals/actions.ts index 0fbf1f53..9669f9d5 100644 --- a/src/app/(frontend)/journals/actions.ts +++ b/src/app/(frontend)/journals/actions.ts @@ -9,6 +9,7 @@ import { emitGameEvent } from "@/utils/event-log/emit"; import { EventTypes } from "@/utils/event-log/eventTypes"; import { recordContribution, revokeEntriesForSource } from "@/lib/contributions"; import { journalBodyLength } from "@/lib/journals/excerpt"; +import { JOURNAL_XP_MIN_CHARS } from "@/lib/journals/xp"; import type { Journal } from "@/payload-types"; /** @@ -25,12 +26,6 @@ const MIN_OCCURRENCE_DATE = Date.parse("2156-03-19T00:00:00.000Z"); */ const MAX_OCCURRENCE_OFFSET_DAYS = 47_326; -/** - * Minimum visible body length (chars) for a published entry to earn - * contribution XP; shorter entries still publish, they just do not count. - */ -const MIN_JOURNAL_BODY_CHARS = 200; - /** 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; @@ -118,7 +113,7 @@ export async function createJournal(input: JournalInput): Promise= MIN_JOURNAL_BODY_CHARS) { + if (journalBodyLength(input.body) >= JOURNAL_XP_MIN_CHARS) { await recordContribution(payload, { userId: user.id, type: "journal-publish", @@ -189,7 +184,7 @@ export async function updateJournal( targetCollection: "journals", targetId: id, }); - if (journalBodyLength(input.body) >= MIN_JOURNAL_BODY_CHARS) { + if (journalBodyLength(input.body) >= JOURNAL_XP_MIN_CHARS) { await recordContribution(payload, { userId: user.id, type: "journal-publish", diff --git a/src/components/frontend/journals/JournalFormDialog.tsx b/src/components/frontend/journals/JournalFormDialog.tsx index 0ba73987..a4097131 100644 --- a/src/components/frontend/journals/JournalFormDialog.tsx +++ b/src/components/frontend/journals/JournalFormDialog.tsx @@ -3,7 +3,7 @@ import * as React from "react"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; -import { Loader2Icon } from "lucide-react"; +import { Loader2Icon, SparklesIcon } from "lucide-react"; import { Button } from "@/components/ui/button"; import { @@ -28,6 +28,8 @@ import { type LexicalJson, } from "@/components/frontend/intelligence/LexicalRichTextEditor"; import { createJournal, updateJournal } from "@/app/(frontend)/journals/actions"; +import { journalBodyLength } from "@/lib/journals/excerpt"; +import { JOURNAL_XP_MIN_CHARS, JOURNAL_XP_POINTS } from "@/lib/journals/xp"; /** * Days the in-game clock runs ahead of real time. The in-world date picker is @@ -143,6 +145,9 @@ export function JournalFormDialog({ : ""; const dateSubtitle = occurredAt ? `${formatInWorldDate(occurredAt)}${sinceAwakening}` : null; + // Live body length, so the composer can hint once the entry will earn XP. + const bodyLength = journalBodyLength(body); + const handleSubmit = async () => { setSaving(true); const input = { @@ -245,6 +250,12 @@ export function JournalFormDialog({ onChange={setBody} placeholder="Write your entry here..." /> + {bodyLength >= JOURNAL_XP_MIN_CHARS && ( +

+ + {`Nice - you'll earn ${JOURNAL_XP_POINTS} XP from this journal entry!`} +

+ )} diff --git a/src/lib/journals/xp.ts b/src/lib/journals/xp.ts new file mode 100644 index 00000000..60d2945b --- /dev/null +++ b/src/lib/journals/xp.ts @@ -0,0 +1,11 @@ +import { CONTRIBUTION_RULES } from "@/lib/contributions/rules"; + +/** + * Minimum visible body length (chars) for a published journal entry to earn + * contribution XP; shorter entries still publish, they just do not count. + * Shared by the publish action and the composer's XP hint so they never drift. + */ +export const JOURNAL_XP_MIN_CHARS = 200; + +/** XP earned for publishing a qualifying journal entry (from the rule table). */ +export const JOURNAL_XP_POINTS = CONTRIBUTION_RULES["journal-publish"].points ?? 0;