Questions in a chat panel behind a floating button
Where a finished detailed analysis can be asked about (chart, comparison, forecast), a floating button with the silhouette icon opens a chat panel (a side panel on desktop, full screen on phones): earlier questions and answers as bubbles, the question box at the bottom, or a one-line package offer when no questions are left. The end of the analysis keeps a short line that opens the same panel; the button hides while that line is in view. The panel stays mounted when closed, so an answer keeps arriving and the button shows a dot for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -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; }
|
||||
|
||||
@@ -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<Question[] | null>(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<HTMLDivElement>(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 (
|
||||
<section className="questions" aria-labelledby={`${fieldId}-title`}>
|
||||
<h3 id={`${fieldId}-title`}>{TEXTS[about].title}</h3>
|
||||
<p className="hint">{TEXTS[about].hint}</p>
|
||||
<section
|
||||
className={inPanel ? "questions questions-panel" : "questions"}
|
||||
aria-labelledby={inPanel ? undefined : `${fieldId}-title`}
|
||||
aria-label={inPanel ? TEXTS[about].title : undefined}
|
||||
>
|
||||
{!inPanel && <h3 id={`${fieldId}-title`}>{TEXTS[about].title}</h3>}
|
||||
<div className="qa-thread" ref={thread}>
|
||||
<p className="hint">{TEXTS[about].hint}</p>
|
||||
|
||||
{questions?.map((q) => (
|
||||
<article key={q.id} className="qa" aria-busy={q.status === "pending" || q.status === "running"}>
|
||||
<p className="qa-question">
|
||||
<span className="eyebrow">Kérdésed</span>
|
||||
{q.question}
|
||||
</p>
|
||||
{q.status === "done" && q.answer ? (
|
||||
<div className="qa-answer">
|
||||
{isAdmin && (
|
||||
<RegenerateButton<Question> url={`/admin/questions/${q.id}/regenerate`} onStarted={replace} />
|
||||
)}
|
||||
<Paragraphs text={q.answer} />
|
||||
</div>
|
||||
) : q.status === "failed" ? (
|
||||
<div className="qa-answer">
|
||||
{isAdmin && (
|
||||
<RegenerateButton<Question> url={`/admin/questions/${q.id}/regenerate`} onStarted={replace} />
|
||||
)}
|
||||
<p className="msg msg-error" role="alert">
|
||||
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.
|
||||
</p>
|
||||
{isAdmin && q.error && <p className="hint">Hiba: {q.error}</p>}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<AnalysisLoading
|
||||
compact
|
||||
text="Készül a válasz, ez általában fél perc…"
|
||||
since={q.requested_at ?? q.created_at}
|
||||
/>
|
||||
<RetryNotice status={q.status} error={q.error} nextAttemptAt={q.next_attempt_at} isAdmin={isAdmin} />
|
||||
</>
|
||||
)}
|
||||
</article>
|
||||
))}
|
||||
{questions?.map((q) => (
|
||||
<article key={q.id} className="qa" aria-busy={q.status === "pending" || q.status === "running"}>
|
||||
<p className="qa-question">
|
||||
<span className="eyebrow">Kérdésed</span>
|
||||
{q.question}
|
||||
</p>
|
||||
{q.status === "done" && q.answer ? (
|
||||
<div className="qa-answer">
|
||||
{isAdmin && (
|
||||
<RegenerateButton<Question> url={`/admin/questions/${q.id}/regenerate`} onStarted={replace} />
|
||||
)}
|
||||
<Paragraphs text={q.answer} />
|
||||
</div>
|
||||
) : q.status === "failed" ? (
|
||||
<div className="qa-answer">
|
||||
{isAdmin && (
|
||||
<RegenerateButton<Question> url={`/admin/questions/${q.id}/regenerate`} onStarted={replace} />
|
||||
)}
|
||||
<p className="msg msg-error" role="alert">
|
||||
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.
|
||||
</p>
|
||||
{isAdmin && q.error && <p className="hint">Hiba: {q.error}</p>}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<AnalysisLoading
|
||||
compact
|
||||
text="Készül a válasz, ez általában fél perc…"
|
||||
since={q.requested_at ?? q.created_at}
|
||||
/>
|
||||
<RetryNotice status={q.status} error={q.error} nextAttemptAt={q.next_attempt_at} isAdmin={isAdmin} />
|
||||
</>
|
||||
)}
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{canAsk && !buying ? (
|
||||
<form className="qa-form" onSubmit={ask}>
|
||||
@@ -184,7 +208,7 @@ export function AnalysisQuestions({
|
||||
<textarea
|
||||
id={fieldId}
|
||||
className="inp"
|
||||
rows={3}
|
||||
rows={inPanel ? 2 : 3}
|
||||
maxLength={MAX_CHARS}
|
||||
value={text}
|
||||
placeholder={TEXTS[about].example}
|
||||
@@ -212,7 +236,7 @@ export function AnalysisQuestions({
|
||||
Most nincs felhasználható kérdésed. Öt kérdés 1 000 Ft, és nem jár le: bármelyik elemzésedről vagy
|
||||
előrejelzésedről kérdezhetsz vele.
|
||||
</p>
|
||||
<PackageChooser ids={["addon_questions"]} canPay={canPay} onBought={bought} />
|
||||
<PackageChooser ids={["addon_questions"]} canPay={canPay} onBought={bought} row={inPanel} />
|
||||
</div>
|
||||
) : (
|
||||
<p className="hint">
|
||||
|
||||
@@ -8,8 +8,8 @@ import type { Analysis, PayMethod } from "@/lib/types";
|
||||
|
||||
import { AI_SHORT } from "./AiNote";
|
||||
import { AnalysisLoading } from "./AnalysisLoading";
|
||||
import { AnalysisQuestions } from "./AnalysisQuestions";
|
||||
import { PackageChooser } from "./PackageCards";
|
||||
import { QuestionsDock } from "./QuestionsDock";
|
||||
import { RegenerateButton } from "./RegenerateButton";
|
||||
import { RetryNotice } from "./RetryNotice";
|
||||
import { AnalysisView } from "./AnalysisView";
|
||||
@@ -157,7 +157,7 @@ export function DetailedAnalysis({
|
||||
{note && <p className="hint">{note}</p>}
|
||||
<AnalysisView content={analysis.content} kind={target.kind} language={analysis.language} />
|
||||
{questionsLeft !== undefined && (
|
||||
<AnalysisQuestions
|
||||
<QuestionsDock
|
||||
analysisId={analysis.id}
|
||||
left={questionsLeft}
|
||||
isAdmin={isAdmin}
|
||||
|
||||
@@ -21,6 +21,7 @@ export function PackageCards({
|
||||
ids,
|
||||
canPay,
|
||||
compact = false,
|
||||
row = false,
|
||||
onBought,
|
||||
}: {
|
||||
packages: Package[];
|
||||
@@ -29,6 +30,8 @@ export function PackageCards({
|
||||
/** How the user can pay (null: purchases are off, the buttons say "soon"). */
|
||||
canPay: PayMethod | null;
|
||||
compact?: boolean;
|
||||
/** One line per package (name, price, button), for tight places like the question panel. */
|
||||
row?: boolean;
|
||||
/** After a stand-in purchase (default: reload the page data). */
|
||||
onBought?: (p: Package) => Promise<void> | void;
|
||||
}) {
|
||||
@@ -83,61 +86,78 @@ export function PackageCards({
|
||||
}
|
||||
}
|
||||
|
||||
const buyButton = (p: Package) =>
|
||||
canPay ? (
|
||||
<button
|
||||
type="button"
|
||||
className={p.badge || row ? "btn btn-primary" : "btn"}
|
||||
onClick={() => buy(p)}
|
||||
disabled={busy !== null}
|
||||
>
|
||||
{busy === p.id ? (canPay === "mock" ? "Fizetés…" : "Átirányítás…") : "Megveszem"}
|
||||
</button>
|
||||
) : (
|
||||
<button type="button" className="btn" disabled>
|
||||
Hamarosan
|
||||
</button>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="field" style={{ gap: 12 }}>
|
||||
<div className={compact ? "pkg-grid pkg-grid-compact" : "pkg-grid"}>
|
||||
{shown.map((p, i) => {
|
||||
const prev = i > 0 ? shown[i - 1] : null;
|
||||
const step = prev && p.tier === "main" && prev.tier === "main" ? p.price_huf - prev.price_huf : null;
|
||||
return (
|
||||
<article key={p.id} className={p.badge ? "pkg pkg-featured" : "pkg"} aria-labelledby={`pkg-${p.id}`}>
|
||||
<div className="pkg-tags">
|
||||
{p.badge && <span className="pkg-badge">{p.badge}</span>}
|
||||
{p.savings_percent ? <span className="pkg-save">−{p.savings_percent}%</span> : null}
|
||||
{row ? (
|
||||
<div className="pkg-rows">
|
||||
{shown.map((p) => (
|
||||
<div key={p.id} className="pkg-row">
|
||||
<div className="pkg-row-text">
|
||||
<strong>{p.name}</strong>
|
||||
<span className="num">{huf(p.price_huf)}</span>
|
||||
</div>
|
||||
<h3 id={`pkg-${p.id}`} className="pkg-name">
|
||||
{p.name}
|
||||
</h3>
|
||||
{!compact && <p className="muted pkg-tagline">{p.tagline}</p>}
|
||||
<div className="pkg-price">
|
||||
<strong>{huf(p.price_huf)}</strong>
|
||||
{p.list_price_huf > p.price_huf && (
|
||||
<s className="hint" aria-label={`Külön megvéve ${huf(p.list_price_huf)}`}>
|
||||
{huf(p.list_price_huf)}
|
||||
</s>
|
||||
)}
|
||||
</div>
|
||||
<ul className="pkg-list">
|
||||
{contents(p).map((line) => (
|
||||
<li key={line}>{line}</li>
|
||||
))}
|
||||
</ul>
|
||||
<p className="hint pkg-per">
|
||||
{p.per_analysis_huf ? `Elemzésenként ${huf(p.per_analysis_huf)}` : " "}
|
||||
</p>
|
||||
{step !== null && step > 0 && prev && (
|
||||
<p className="pkg-step">
|
||||
Csak +{huf(step)} a(z) {prev.name} csomaghoz képest
|
||||
{buyButton(p)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className={compact ? "pkg-grid pkg-grid-compact" : "pkg-grid"}>
|
||||
{shown.map((p, i) => {
|
||||
const prev = i > 0 ? shown[i - 1] : null;
|
||||
const step = prev && p.tier === "main" && prev.tier === "main" ? p.price_huf - prev.price_huf : null;
|
||||
return (
|
||||
<article key={p.id} className={p.badge ? "pkg pkg-featured" : "pkg"} aria-labelledby={`pkg-${p.id}`}>
|
||||
<div className="pkg-tags">
|
||||
{p.badge && <span className="pkg-badge">{p.badge}</span>}
|
||||
{p.savings_percent ? <span className="pkg-save">−{p.savings_percent}%</span> : null}
|
||||
</div>
|
||||
<h3 id={`pkg-${p.id}`} className="pkg-name">
|
||||
{p.name}
|
||||
</h3>
|
||||
{!compact && <p className="muted pkg-tagline">{p.tagline}</p>}
|
||||
<div className="pkg-price">
|
||||
<strong>{huf(p.price_huf)}</strong>
|
||||
{p.list_price_huf > p.price_huf && (
|
||||
<s className="hint" aria-label={`Külön megvéve ${huf(p.list_price_huf)}`}>
|
||||
{huf(p.list_price_huf)}
|
||||
</s>
|
||||
)}
|
||||
</div>
|
||||
<ul className="pkg-list">
|
||||
{contents(p).map((line) => (
|
||||
<li key={line}>{line}</li>
|
||||
))}
|
||||
</ul>
|
||||
<p className="hint pkg-per">
|
||||
{p.per_analysis_huf ? `Elemzésenként ${huf(p.per_analysis_huf)}` : " "}
|
||||
</p>
|
||||
)}
|
||||
{canPay ? (
|
||||
<button
|
||||
type="button"
|
||||
className={p.badge ? "btn btn-primary" : "btn"}
|
||||
onClick={() => buy(p)}
|
||||
disabled={busy !== null}
|
||||
>
|
||||
{busy === p.id ? (canPay === "mock" ? "Fizetés…" : "Átirányítás…") : "Megveszem"}
|
||||
</button>
|
||||
) : (
|
||||
<button type="button" className="btn" disabled>
|
||||
Hamarosan
|
||||
</button>
|
||||
)}
|
||||
</article>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{step !== null && step > 0 && prev && (
|
||||
<p className="pkg-step">
|
||||
Csak +{huf(step)} a(z) {prev.name} csomaghoz képest
|
||||
</p>
|
||||
)}
|
||||
{buyButton(p)}
|
||||
</article>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
@@ -187,17 +207,20 @@ export function usePackages(): Package[] | null {
|
||||
export function PackageChooser({
|
||||
ids,
|
||||
canPay,
|
||||
row = false,
|
||||
onBought,
|
||||
}: {
|
||||
ids: string[];
|
||||
canPay: PayMethod | null;
|
||||
/** One line per package (see PackageCards). */
|
||||
row?: boolean;
|
||||
onBought?: (p: Package) => Promise<void> | void;
|
||||
}) {
|
||||
const packages = usePackages();
|
||||
if (packages === null) return <p className="muted">Csomagok betöltése…</p>;
|
||||
return (
|
||||
<div className="field" style={{ gap: 8 }}>
|
||||
<PackageCards packages={packages} ids={ids} canPay={canPay} compact onBought={onBought} />
|
||||
<PackageCards packages={packages} ids={ids} canPay={canPay} compact row={row} onBought={onBought} />
|
||||
<Link href="/csomagok" className="hint">
|
||||
Összes csomag és a részletek →
|
||||
</Link>
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useId, useRef, useState } from "react";
|
||||
|
||||
import type { PayMethod } from "@/lib/types";
|
||||
|
||||
import { AnalysisQuestions, QUESTION_TEXTS } from "./AnalysisQuestions";
|
||||
|
||||
type About = "natal" | "synastry" | "forecast";
|
||||
|
||||
/** The floating button's label and the line under the panel's title. */
|
||||
const DOCK: Record<About, { button: string; lead: string; teaser: string }> = {
|
||||
natal: {
|
||||
button: "Kérdezz a képletedről",
|
||||
lead: "A képleted és az elemzésed alapján válaszolunk.",
|
||||
teaser: "Kérdésed van a képleteddel?",
|
||||
},
|
||||
synastry: {
|
||||
button: "Kérdezz a kapcsolatotokról",
|
||||
lead: "A két képlet és az elemzés alapján válaszolunk. A kérdéseket mindketten látjátok.",
|
||||
teaser: "Kérdésed van a kapcsolatotokkal?",
|
||||
},
|
||||
forecast: {
|
||||
button: "Kérdezz az évedről",
|
||||
lead: "Az év adatai és az előrejelzésed alapján válaszolunk.",
|
||||
teaser: "Kérdésed van az előrejelzéseddel?",
|
||||
},
|
||||
};
|
||||
|
||||
export const QUESTION_ICON = "/img/kerdezz.webp";
|
||||
|
||||
/**
|
||||
* Questions about a finished analysis in a chat panel behind a floating button
|
||||
* (bottom right), plus a short line at the end of the analysis that opens the
|
||||
* same panel. With no questions left the panel offers the question package.
|
||||
* The panel stays mounted while closed, so a pending answer keeps arriving.
|
||||
*/
|
||||
export function QuestionsDock({
|
||||
analysisId,
|
||||
left,
|
||||
isAdmin,
|
||||
canPay,
|
||||
about,
|
||||
}: {
|
||||
analysisId: string;
|
||||
left: number;
|
||||
isAdmin: boolean;
|
||||
canPay: PayMethod | null;
|
||||
about: About;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [unread, setUnread] = useState(false);
|
||||
// The line at the end of the analysis is on screen: the floating button would only repeat it.
|
||||
const [teaserInView, setTeaserInView] = useState(false);
|
||||
const teaser = useRef<HTMLDivElement>(null);
|
||||
const panel = useRef<HTMLElement>(null);
|
||||
const fab = useRef<HTMLButtonElement>(null);
|
||||
const panelId = useId();
|
||||
const titleId = useId();
|
||||
const t = DOCK[about];
|
||||
|
||||
function show() {
|
||||
setOpen(true);
|
||||
setUnread(false);
|
||||
}
|
||||
|
||||
function hide() {
|
||||
setOpen(false);
|
||||
// The button is shown again on the next render; then it gets the focus back
|
||||
// (or the line at the end of the analysis, while the button stays hidden).
|
||||
requestAnimationFrame(() => {
|
||||
const target = fab.current && !fab.current.hidden ? fab.current : teaser.current?.querySelector("button");
|
||||
target?.focus();
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
panel.current?.querySelector<HTMLTextAreaElement>("textarea")?.focus({ preventScroll: true });
|
||||
const escape = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") hide();
|
||||
};
|
||||
document.addEventListener("keydown", escape);
|
||||
// On phones the panel fills the screen: the page behind it does not scroll.
|
||||
document.body.classList.add("qdock-open");
|
||||
return () => {
|
||||
document.removeEventListener("keydown", escape);
|
||||
document.body.classList.remove("qdock-open");
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
useEffect(() => {
|
||||
const el = teaser.current;
|
||||
if (!el || typeof IntersectionObserver === "undefined") return;
|
||||
const io = new IntersectionObserver(([entry]) => setTeaserInView(entry.isIntersecting));
|
||||
io.observe(el);
|
||||
return () => io.disconnect();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="qa-teaser" ref={teaser}>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src={QUESTION_ICON} alt="" width={48} height={48} className="qa-teaser-icon" />
|
||||
<div className="qa-teaser-text">
|
||||
<strong>{t.teaser}</strong>
|
||||
<span className="hint">{t.lead}</span>
|
||||
</div>
|
||||
<button type="button" className="btn btn-primary" onClick={show}>
|
||||
Kérdezz
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button
|
||||
ref={fab}
|
||||
type="button"
|
||||
className="qdock-fab"
|
||||
hidden={open || (teaserInView && !unread)}
|
||||
aria-controls={panelId}
|
||||
aria-expanded={open}
|
||||
aria-label={unread ? `${t.button} – új válasz érkezett` : t.button}
|
||||
onClick={show}
|
||||
>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src={QUESTION_ICON} alt="" width={44} height={44} />
|
||||
<span className="qdock-fab-label">{t.button}</span>
|
||||
{unread && <span className="qdock-dot" aria-hidden="true" />}
|
||||
</button>
|
||||
|
||||
<aside ref={panel} id={panelId} className="qdock-panel" hidden={!open} aria-labelledby={titleId}>
|
||||
<header className="qdock-head">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src={QUESTION_ICON} alt="" width={40} height={40} />
|
||||
<div className="qdock-title">
|
||||
<h2 id={titleId}>{QUESTION_TEXTS[about].title}</h2>
|
||||
<span className="hint">{t.lead}</span>
|
||||
</div>
|
||||
<button type="button" className="modal-close" onClick={hide} aria-label="Bezárás">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M6 6l12 12M18 6L6 18" />
|
||||
</svg>
|
||||
</button>
|
||||
</header>
|
||||
<AnalysisQuestions
|
||||
analysisId={analysisId}
|
||||
left={left}
|
||||
isAdmin={isAdmin}
|
||||
canPay={canPay}
|
||||
about={about}
|
||||
inPanel
|
||||
onAnswered={() => {
|
||||
if (!panel.current || panel.current.hidden) setUnread(true);
|
||||
}}
|
||||
/>
|
||||
</aside>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user