diff --git a/services/frontend/public/img/kerdezz.webp b/services/frontend/public/img/kerdezz.webp new file mode 100644 index 0000000..3c1aa3b Binary files /dev/null and b/services/frontend/public/img/kerdezz.webp differ diff --git a/services/frontend/src/app/globals.css b/services/frontend/src/app/globals.css index 41b8971..ec6904c 100644 --- a/services/frontend/src/app/globals.css +++ b/services/frontend/src/app/globals.css @@ -745,6 +745,76 @@ a.pair-row:hover strong { color: var(--gold); } .qa-answer p { margin: 0 0 8px; } .qa-form { display: flex; flex-direction: column; gap: 8px; } .qa-form textarea { resize: vertical; min-height: 84px; } + +/* Questions: a line at the end of the analysis, a floating button and the chat panel (QuestionsDock). */ +.qa-teaser { + display: flex; align-items: center; gap: 14px; margin-top: 28px; padding: 16px 18px; + border: 1px solid rgba(217, 180, 106, 0.35); border-radius: 14px; background: rgba(217, 180, 106, 0.05); +} +.qa-teaser-icon { border-radius: 50%; flex: none; } +.qa-teaser-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; } +.qdock-fab { + position: fixed; right: 20px; bottom: 20px; z-index: 55; display: flex; align-items: center; gap: 10px; + padding: 5px 18px 5px 5px; border-radius: 999px; border: 1px solid rgba(217, 180, 106, 0.55); + background: var(--panel); color: var(--ink); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; + box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); +} +.qdock-fab:hover { border-color: var(--gold); color: var(--gold); } +.qdock-fab[hidden] { display: none; } +.qdock-fab img { border-radius: 50%; display: block; } +.qdock-dot { + position: absolute; top: 2px; left: 38px; width: 13px; height: 13px; border-radius: 50%; + background: var(--gold); border: 2px solid var(--panel); +} +.qdock-panel { + position: fixed; right: 20px; bottom: 20px; z-index: 56; width: min(420px, calc(100vw - 40px)); + height: min(660px, calc(100dvh - 40px)); display: flex; flex-direction: column; overflow: hidden; + background: var(--panel); border: 1px solid var(--line-2); border-radius: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55); +} +.qdock-panel[hidden] { display: none; } +.qdock-head { display: flex; align-items: center; gap: 12px; padding: 14px 14px 12px 16px; border-bottom: 1px solid var(--line); } +.qdock-head img { border-radius: 50%; flex: none; } +.qdock-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; } +.qdock-title h2 { font-size: 20px; line-height: 1.2; margin: 0; } +.qdock-title .hint { font-size: 12px; } +.questions-panel { flex: 1; min-height: 0; margin: 0; padding: 0; border: 0; gap: 0; } +.questions-panel .qa-thread { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; } +.questions-panel .qa-thread > .hint { margin: 0; } +.questions-panel .qa { border: 0; padding: 0; gap: 8px; } +.questions-panel .qa-question { + align-self: flex-end; max-width: 85%; padding: 10px 12px; font-weight: 500; + background: rgba(217, 180, 106, 0.14); border: 1px solid rgba(217, 180, 106, 0.3); border-radius: 14px 14px 4px 14px; +} +.questions-panel .qa-question .eyebrow { display: none; } +.questions-panel .qa-answer { + align-self: flex-start; max-width: 92%; padding: 10px 12px; font-size: 15px; + background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; +} +.questions-panel .qa-answer p { text-align: left; hyphens: manual; } +.questions-panel .qa-answer p:last-child { margin-bottom: 0; } +.questions-panel .qa-form, .questions-panel > .hint { border-top: 1px solid var(--line); padding: 12px 16px; margin: 0; } +.questions-panel .qa-form textarea { min-height: 60px; resize: none; } +.questions-panel .pay-box { border-radius: 0; border-width: 1px 0 0; padding: 14px 16px; gap: 10px; max-height: 60%; overflow-y: auto; } +.questions-panel .pay-box .hint { font-size: 12px; margin: 0; } +.pkg-rows { display: flex; flex-direction: column; gap: 8px; } +.pkg-row { + display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; + border: 1px solid rgba(217, 180, 106, 0.45); border-radius: 10px; background: var(--panel); +} +.pkg-row-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; } +.pkg-row-text .num { color: var(--gold); } +@media (max-width: 640px) { + .qdock-fab { right: 16px; bottom: 16px; padding: 4px; } + .qdock-fab img { width: 52px; height: 52px; } + .qdock-fab-label { display: none; } + .qdock-dot { left: 42px; } + .qdock-panel { inset: 0; width: 100%; height: 100dvh; border: 0; border-radius: 0; } + body.qdock-open { overflow: hidden; } +} +@media (max-width: 480px) { + .qa-teaser { flex-wrap: wrap; } + .qa-teaser .btn { width: 100%; } +} .hint.warn { color: var(--gold); } .job-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; } .job-row > span:first-child { display: flex; flex-direction: column; min-width: 0; } diff --git a/services/frontend/src/components/AnalysisQuestions.tsx b/services/frontend/src/components/AnalysisQuestions.tsx index 6264fe0..5b575c4 100644 --- a/services/frontend/src/components/AnalysisQuestions.tsx +++ b/services/frontend/src/components/AnalysisQuestions.tsx @@ -1,7 +1,7 @@ "use client"; import Link from "next/link"; -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import { api, ApiError, errorText } from "@/lib/api"; import type { PayMethod, Question, UnitBalance } from "@/lib/types"; @@ -14,7 +14,7 @@ import { Paragraphs } from "./Rich"; const MAX_CHARS = 600; -const TEXTS = { +export const QUESTION_TEXTS = { natal: { title: "Kérdezz az elemzésedről", hint: "Mit jelent ez a te életedben, hogyan kapcsolódik két rész egymáshoz? A válasz a képleted és az elemzés alapján készül, legfeljebb 250 szóban.", @@ -34,10 +34,13 @@ const TEXTS = { const POLL_MS = 3000; const MAX_POLLS = 80; // 4 minutes +const TEXTS = QUESTION_TEXTS; + /** * Questions about a finished analysis or forecast, and their answers. Each * question uses one from the user's questions (admins ask for free); the - * answer comes from the model that wrote the analysis. + * answer comes from the model that wrote the analysis. `inPanel`: shown in + * the chat panel (see QuestionsDock), which has its own heading. */ export function AnalysisQuestions({ analysisId, @@ -45,6 +48,8 @@ export function AnalysisQuestions({ isAdmin, canPay, about, + inPanel = false, + onAnswered, }: { analysisId: string; left: number; @@ -52,6 +57,9 @@ export function AnalysisQuestions({ canPay: PayMethod | null; /** What the analysis is about: the heading and the example question follow it. */ about: "natal" | "synastry" | "forecast"; + inPanel?: boolean; + /** An answer has just arrived (for the panel's "new answer" dot). */ + onAnswered?: () => void; }) { const [questions, setQuestions] = useState(null); const [left, setLeft] = useState(initialLeft); @@ -61,6 +69,9 @@ export function AnalysisQuestions({ const [buying, setBuying] = useState(false); const waiting = questions?.some((q) => q.status === "pending" || q.status === "running") ?? false; const fieldId = `question-${analysisId}`; + const thread = useRef(null); + const answered = useRef(onAnswered); + answered.current = onAnswered; useEffect(() => { api<{ questions: Question[] }>(`/analyses/${analysisId}/questions`) @@ -87,6 +98,7 @@ export function AnalysisQuestions({ replace(next); if (next.status === "done" || next.status === "failed") { if (next.status === "failed" && next.credits_charged > 0) setLeft((n) => n + next.credits_charged); + answered.current?.(); return; } } catch { @@ -132,49 +144,61 @@ export function AnalysisQuestions({ setBuying(false); } + // In the panel the newest message stays in view. + const last = questions?.at(-1); + useEffect(() => { + if (inPanel && thread.current) thread.current.scrollTop = thread.current.scrollHeight; + }, [inPanel, questions?.length, last?.status]); + const canAsk = left > 0; return ( -
-

{TEXTS[about].title}

-

{TEXTS[about].hint}

+
+ {!inPanel &&

{TEXTS[about].title}

} +
+

{TEXTS[about].hint}

- {questions?.map((q) => ( -
-

- Kérdésed - {q.question} -

- {q.status === "done" && q.answer ? ( -
- {isAdmin && ( - url={`/admin/questions/${q.id}/regenerate`} onStarted={replace} /> - )} - -
- ) : q.status === "failed" ? ( -
- {isAdmin && ( - url={`/admin/questions/${q.id}/regenerate`} onStarted={replace} /> - )} -

- Erre többszöri próbálkozás után sem sikerült válaszolni - {q.credits_charged > 0 ? ". A kérdést visszaadtuk, így ingyen újra felteheted" : ""}. Kérdezz újra egy - kicsit később. -

- {isAdmin && q.error &&

Hiba: {q.error}

} -
- ) : ( - <> - - - - )} -
- ))} + {questions?.map((q) => ( +
+

+ Kérdésed + {q.question} +

+ {q.status === "done" && q.answer ? ( +
+ {isAdmin && ( + url={`/admin/questions/${q.id}/regenerate`} onStarted={replace} /> + )} + +
+ ) : q.status === "failed" ? ( +
+ {isAdmin && ( + url={`/admin/questions/${q.id}/regenerate`} onStarted={replace} /> + )} +

+ Erre többszöri próbálkozás után sem sikerült válaszolni + {q.credits_charged > 0 ? ". A kérdést visszaadtuk, így ingyen újra felteheted" : ""}. Kérdezz újra egy + kicsit később. +

+ {isAdmin && q.error &&

Hiba: {q.error}

} +
+ ) : ( + <> + + + + )} +
+ ))} +
{canAsk && !buying ? (
@@ -184,7 +208,7 @@ export function AnalysisQuestions({