Tarot readings have a topic: general, relationship, work, self-knowledge
The new reading form starts with the topic; it steers how the model reads the cards (with the topic's own limits, e.g. no break-up predictions for relationships) and shows on the reading and in the list. Readings from before count as general. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -69,6 +69,8 @@ impl ReadingRow {
|
||||
"status": self.status,
|
||||
"spread": self.tarot["spread"],
|
||||
"spread_name": spread.map(|s| s.name),
|
||||
"topic": tarot::topic(self.tarot["topic"].as_str()).map(|t| t.id),
|
||||
"topic_name": tarot::topic(self.tarot["topic"].as_str()).map(|t| t.name),
|
||||
"question": self.tarot["question"],
|
||||
"cards": cards,
|
||||
"content": self.content,
|
||||
@@ -147,6 +149,8 @@ pub async fn get_one(State(state): St, auth: AuthUser, WithRejection(Path(id), _
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct NewReading {
|
||||
spread: String,
|
||||
/// `general` (the default), `love`, `work` or `self`.
|
||||
topic: Option<String>,
|
||||
question: Option<String>,
|
||||
}
|
||||
|
||||
@@ -157,6 +161,7 @@ pub async fn create(
|
||||
WithRejection(Json(req), _): Body<NewReading>,
|
||||
) -> ApiResult<(StatusCode, Json<Value>)> {
|
||||
let spread = tarot::spread(&req.spread).ok_or_else(|| ApiError::BadRequest("unknown spread".into()))?;
|
||||
let topic = tarot::topic(req.topic.as_deref()).ok_or_else(|| ApiError::BadRequest("unknown topic".into()))?;
|
||||
let question = req.question.map(|q| q.trim().replace("\r\n", "\n")).filter(|q| !q.is_empty());
|
||||
if question.as_ref().is_some_and(|q| q.chars().count() > TAROT_QUESTION_MAX_CHARS) {
|
||||
return Err(ApiError::BadRequest(format!(
|
||||
@@ -179,6 +184,7 @@ pub async fn create(
|
||||
let (sun, moon, ascendant) = big_three(&state, auth.id()).await?;
|
||||
let reading = json!({
|
||||
"spread": spread.id,
|
||||
"topic": topic.id,
|
||||
"question": question,
|
||||
"cards": draw(spread),
|
||||
"sun": sun,
|
||||
|
||||
@@ -2593,7 +2593,7 @@ async fn tarot_readings_draw_on_the_server_and_use_tarot_units(pool: PgPool) {
|
||||
let app = TestApp::new(pool.clone()).await;
|
||||
let anna = app.register("anna@example.com", "Anna").await;
|
||||
app.chart(&anna, "Saját", true, "1990-07-01").await;
|
||||
let body = json!({"spread": "trinity", "question": "Merre induljak tovább?"});
|
||||
let body = json!({"spread": "trinity", "topic": "love", "question": "Merre induljak tovább?"});
|
||||
// No units: a package or the addon is needed.
|
||||
let r = app.post("/v1/tarot/readings", Some(&anna), body.clone()).await;
|
||||
assert_eq!(r.status, StatusCode::PAYMENT_REQUIRED, "{}", r.body);
|
||||
@@ -2610,6 +2610,8 @@ async fn tarot_readings_draw_on_the_server_and_use_tarot_units(pool: PgPool) {
|
||||
|
||||
let r = app.post("/v1/tarot/readings", Some(&anna), json!({"spread": "nincs"})).await;
|
||||
assert_eq!(r.status, StatusCode::BAD_REQUEST);
|
||||
let r = app.post("/v1/tarot/readings", Some(&anna), json!({"spread": "daily", "topic": "pénz"})).await;
|
||||
assert_eq!(r.status, StatusCode::BAD_REQUEST);
|
||||
let long = "x".repeat(analysis_prompt::TAROT_QUESTION_MAX_CHARS + 1);
|
||||
let r = app.post("/v1/tarot/readings", Some(&anna), json!({"spread": "daily", "question": long})).await;
|
||||
assert_eq!(r.status, StatusCode::BAD_REQUEST);
|
||||
@@ -2618,6 +2620,7 @@ async fn tarot_readings_draw_on_the_server_and_use_tarot_units(pool: PgPool) {
|
||||
assert_eq!(r.status, StatusCode::ACCEPTED, "{}", r.body);
|
||||
assert_eq!(r.body["status"], "pending");
|
||||
assert_eq!(r.body["spread_name"], "Sorsfonalak hármas");
|
||||
assert_eq!((&r.body["topic"], &r.body["topic_name"]), (&json!("love"), &json!("Párkapcsolat")));
|
||||
assert_eq!(r.body["question"], "Merre induljak tovább?");
|
||||
let cards = r.body["cards"].as_array().unwrap();
|
||||
assert_eq!(cards.len(), 3);
|
||||
|
||||
@@ -981,6 +981,15 @@ a.pair-row:hover strong { color: var(--gold); }
|
||||
.tarot-spread:hover { border-color: #5a6790; }
|
||||
.tarot-spread.is-active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
|
||||
.tarot-spread:has(input:focus-visible) { outline: 2px solid var(--gold); outline-offset: 2px; }
|
||||
.tarot-topics { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
.tarot-topics legend { margin-bottom: 8px; }
|
||||
.tarot-topic {
|
||||
display: inline-flex; align-items: center; min-height: 38px; padding: 0 16px; cursor: pointer; font-size: 14px;
|
||||
border: 1px solid var(--line-2); border-radius: 999px; background: var(--panel-2); color: var(--ink-2);
|
||||
}
|
||||
.tarot-topic:hover { border-color: #5a6790; }
|
||||
.tarot-topic.is-active { border-color: var(--gold); color: var(--gold); background: rgba(217, 180, 106, 0.08); }
|
||||
.tarot-topic:has(input:focus-visible) { outline: 2px solid var(--gold); outline-offset: 2px; }
|
||||
.tarot-spread-name { font-family: var(--font-display); font-size: 20px; font-weight: 600; }
|
||||
|
||||
.tarot-stage { align-items: stretch; }
|
||||
|
||||
@@ -24,6 +24,7 @@ export default async function TarotReadingPage({ params }: { params: Promise<{ i
|
||||
← Kártyajóslás
|
||||
</Link>
|
||||
<span className="eyebrow">
|
||||
{reading.topic_name ? `${reading.topic_name} · ` : ""}
|
||||
{reading.spread_name} · {day(reading.created_at)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -4,7 +4,15 @@ import Link from "next/link";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
import { api, ApiError, errorText } from "@/lib/api";
|
||||
import { SPREADS, TAROT_QUESTION_MAX, tarotCard, type SpreadId, type TarotReading } from "@/lib/tarot";
|
||||
import {
|
||||
SPREADS,
|
||||
TAROT_QUESTION_MAX,
|
||||
TOPICS,
|
||||
tarotCard,
|
||||
type SpreadId,
|
||||
type TarotReading,
|
||||
type TopicId,
|
||||
} from "@/lib/tarot";
|
||||
import type { PayMethod, UnitBalance } from "@/lib/types";
|
||||
|
||||
import { PackageChooser } from "../PackageCards";
|
||||
@@ -40,6 +48,7 @@ export function TarotTable({
|
||||
const [readings, setReadings] = useState(initialReadings);
|
||||
const [left, setLeft] = useState(initialLeft);
|
||||
const [spread, setSpread] = useState<SpreadId>("trinity");
|
||||
const [topic, setTopic] = useState<TopicId>("general");
|
||||
const [question, setQuestion] = useState("");
|
||||
const [phase, setPhase] = useState<Phase>("setup");
|
||||
const [picked, setPicked] = useState<number[]>([]);
|
||||
@@ -68,7 +77,7 @@ export function TarotTable({
|
||||
setError(null);
|
||||
try {
|
||||
const reading = await api<TarotReading>("/tarot/readings", {
|
||||
body: { spread, question: question.trim() || null },
|
||||
body: { spread, topic, question: question.trim() || null },
|
||||
});
|
||||
setCurrent(reading);
|
||||
setReadings((all) => [reading, ...all]);
|
||||
@@ -86,7 +95,7 @@ export function TarotTable({
|
||||
}
|
||||
}
|
||||
},
|
||||
[spread, question],
|
||||
[spread, topic, question],
|
||||
);
|
||||
|
||||
function pick(i: number) {
|
||||
@@ -151,6 +160,22 @@ export function TarotTable({
|
||||
</div>
|
||||
) : (
|
||||
<form className="field" style={{ gap: 18 }} onSubmit={start}>
|
||||
<fieldset className="tarot-topics">
|
||||
<legend className="label">Téma</legend>
|
||||
{TOPICS.map((t) => (
|
||||
<label key={t.id} className={t.id === topic ? "tarot-topic is-active" : "tarot-topic"}>
|
||||
<input
|
||||
type="radio"
|
||||
name="topic"
|
||||
value={t.id}
|
||||
checked={t.id === topic}
|
||||
onChange={() => setTopic(t.id)}
|
||||
className="sr-only"
|
||||
/>
|
||||
{t.name}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
<fieldset className="tarot-spreads">
|
||||
<legend className="label">Kirakás</legend>
|
||||
{SPREADS.map((s) => (
|
||||
@@ -176,7 +201,7 @@ export function TarotTable({
|
||||
rows={2}
|
||||
maxLength={TAROT_QUESTION_MAX}
|
||||
value={question}
|
||||
placeholder="Pl. Mire figyeljek, ha munkahelyet váltanék? Kérdés nélkül általános útmutatást kapsz."
|
||||
placeholder={`${TOPICS.find((x) => x.id === topic)?.example ?? ""} Kérdés nélkül a témában kapsz útmutatást.`}
|
||||
onChange={(e) => setQuestion(e.target.value)}
|
||||
/>
|
||||
<span className="hint">
|
||||
@@ -208,7 +233,9 @@ export function TarotTable({
|
||||
{phase !== "setup" && (
|
||||
<section className="card tarot-stage" aria-labelledby="tarot-stage-title">
|
||||
<div className="tarot-stage-head">
|
||||
<span className="eyebrow">{current?.spread_name ?? chosen.name}</span>
|
||||
<span className="eyebrow">
|
||||
{current?.spread_name ?? chosen.name} · {current?.topic_name ?? TOPICS.find((x) => x.id === topic)?.name}
|
||||
</span>
|
||||
<h2 id="tarot-stage-title">
|
||||
{phase === "picking"
|
||||
? `Válassz ${chosen.cards} lapot a pakliból`
|
||||
@@ -266,7 +293,8 @@ export function TarotTable({
|
||||
<span className="tarot-history-text">
|
||||
<strong>{r.content?.title ?? r.question ?? r.spread_name}</strong>
|
||||
<span className="hint">
|
||||
{day(r.created_at)} · {r.spread_name}
|
||||
{day(r.created_at)} · {r.topic_name ? `${r.topic_name} · ` : ""}
|
||||
{r.spread_name}
|
||||
{r.question && r.content ? ` · „${r.question}”` : ""}
|
||||
{r.status === "pending" || r.status === "running" ? " · készül" : ""}
|
||||
{r.status === "failed" ? " · nem sikerült" : ""}
|
||||
|
||||
@@ -43,6 +43,16 @@ export const SPREADS: { id: SpreadId; name: string; cards: number; about: string
|
||||
},
|
||||
];
|
||||
|
||||
export type TopicId = "general" | "love" | "work" | "self";
|
||||
|
||||
/** What a reading is about (the backend's `TOPICS`), with an example question. */
|
||||
export const TOPICS: { id: TopicId; name: string; example: string }[] = [
|
||||
{ id: "general", name: "Általános", example: "Pl. Mire figyeljek a következő hetekben?" },
|
||||
{ id: "love", name: "Párkapcsolat", example: "Pl. Mit tehetek azért, hogy közelebb kerüljünk egymáshoz?" },
|
||||
{ id: "work", name: "Munka és hivatás", example: "Pl. Mire figyeljek, ha munkahelyet váltanék?" },
|
||||
{ id: "self", name: "Önismeret", example: "Pl. Mit tanulhatok most önmagamról?" },
|
||||
];
|
||||
|
||||
/** Longest question (the backend's `TAROT_QUESTION_MAX_CHARS`). */
|
||||
export const TAROT_QUESTION_MAX = 300;
|
||||
|
||||
@@ -60,6 +70,8 @@ export interface TarotReading {
|
||||
status: "pending" | "running" | "done" | "failed";
|
||||
spread: SpreadId;
|
||||
spread_name: string | null;
|
||||
topic: TopicId | null;
|
||||
topic_name: string | null;
|
||||
question: string | null;
|
||||
cards: { card: string; reversed: boolean; position: string | null; about: string | null }[];
|
||||
content: TarotContent | null;
|
||||
|
||||
Reference in New Issue
Block a user