feat(journals): hint when a draft will earn XP
This commit is contained in:
parent
283cd3f4b2
commit
88d674cff6
3 changed files with 26 additions and 9 deletions
|
|
@ -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<ActionResult<n
|
|||
targetCollection: "journals",
|
||||
targetId: doc.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",
|
||||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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 && (
|
||||
<p className="flex items-center gap-1.5 text-xs text-amber-400">
|
||||
<SparklesIcon className="size-3.5 shrink-0" />
|
||||
{`Nice - you'll earn ${JOURNAL_XP_POINTS} XP from this journal entry!`}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
11
src/lib/journals/xp.ts
Normal file
11
src/lib/journals/xp.ts
Normal file
|
|
@ -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;
|
||||
Loading…
Reference in a new issue