feat(ui): add new ui

This commit is contained in:
shafin-r
2026-02-20 19:10:13 +06:00
parent 3c8f945539
commit 76d2108aec
16 changed files with 4263 additions and 1702 deletions

View File

@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import { useParams, useNavigate } from "react-router-dom";
import { api } from "../../../utils/api";
import { useAuthStore } from "../../../stores/authStore";
import type { PracticeSheet } from "../../../types/sheet";
@ -10,223 +10,456 @@ import {
CarouselItem,
type CarouselApi,
} from "../../../components/ui/carousel";
import { Button } from "../../../components/ui/button";
import { useNavigate } from "react-router-dom";
import { useExamConfigStore } from "../../../stores/useExamConfigStore";
// ─── Shared background dots (same subtle config as rest of app) ───────────────
const DOTS = [
{ size: 10, color: "#f97316", top: "8%", left: "5%", delay: "0s" },
{ size: 7, color: "#a855f7", top: "28%", left: "2%", delay: "1.2s" },
{ size: 9, color: "#22c55e", top: "60%", left: "4%", delay: "0.6s" },
{ size: 12, color: "#3b82f6", top: "12%", right: "4%", delay: "1.8s" },
{ size: 7, color: "#f43f5e", top: "45%", right: "3%", delay: "0.9s" },
{ size: 9, color: "#eab308", top: "75%", right: "6%", delay: "0.4s" },
];
const STYLES = `
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;700;800;900&family=Nunito+Sans:wght@400;600;700&display=swap');
.pt-screen {
min-height: 100vh;
background: #fffbf4;
font-family: 'Nunito', sans-serif;
position: relative;
overflow-x: hidden;
}
/* ── Blobs ── */
.pt-blob { position: fixed; pointer-events: none; z-index: 0; filter: blur(48px); opacity: 0.35; }
.pt-blob-1 { width:240px;height:240px;background:#fde68a;top:-80px;left:-80px;border-radius:60% 40% 70% 30%/50% 60% 40% 50%;animation:ptWobble1 14s ease-in-out infinite; }
.pt-blob-2 { width:190px;height:190px;background:#a5f3c0;bottom:-50px;left:6%;border-radius:40% 60% 30% 70%/60% 40% 60% 40%;animation:ptWobble2 16s ease-in-out infinite; }
.pt-blob-3 { width:210px;height:210px;background:#fbcfe8;top:15%;right:-60px;border-radius:70% 30% 50% 50%/40% 60% 40% 60%;animation:ptWobble1 18s ease-in-out infinite reverse; }
.pt-blob-4 { width:150px;height:150px;background:#bfdbfe;bottom:12%;right:2%;border-radius:50% 50% 30% 70%/60% 40% 60% 40%;animation:ptWobble2 12s ease-in-out infinite; }
@keyframes ptWobble1 {
0%,100%{border-radius:60% 40% 70% 30%/50% 60% 40% 50%;transform:translate(0,0) rotate(0deg);}
50%{border-radius:40% 60% 30% 70%/60% 40% 60% 40%;transform:translate(12px,16px) rotate(8deg);}
}
@keyframes ptWobble2 {
0%,100%{border-radius:40% 60% 30% 70%/60% 40% 60% 40%;transform:translate(0,0) rotate(0deg);}
50%{border-radius:60% 40% 70% 30%/40% 60% 40% 60%;transform:translate(-10px,12px) rotate(-6deg);}
}
/* ── Floating dots ── */
.pt-dot { position:fixed;border-radius:50%;pointer-events:none;z-index:0;opacity:0.3;animation:ptFloat 7s ease-in-out infinite; }
@keyframes ptFloat {
0%,100%{transform:translateY(0) rotate(0deg);}
50%{transform:translateY(-12px) rotate(180deg);}
}
/* ── Inner scroll container ── */
.pt-inner {
position: relative; z-index: 1;
max-width: 580px; margin: 0 auto;
padding: 2rem 1.25rem 4rem;
display: flex; flex-direction: column; gap: 1.25rem;
}
/* ── Pop-in animation ── */
@keyframes ptPopIn {
from { opacity:0; transform: scale(0.92) translateY(12px); }
to { opacity:1; transform: scale(1) translateY(0); }
}
.pt-anim { animation: ptPopIn 0.4s cubic-bezier(0.34,1.56,0.64,1) both; }
.pt-anim-1 { animation-delay: 0.05s; }
.pt-anim-2 { animation-delay: 0.1s; }
.pt-anim-3 { animation-delay: 0.15s; }
.pt-anim-4 { animation-delay: 0.2s; }
.pt-anim-5 { animation-delay: 0.25s; }
/* ── Header ── */
.pt-header { animation: ptPopIn 0.4s cubic-bezier(0.34,1.56,0.64,1) both; }
.pt-eyebrow {
font-size: 0.65rem; font-weight: 800; letter-spacing: 0.16em;
text-transform: uppercase; color: #a855f7; margin-bottom: 0.3rem;
}
.pt-title {
font-size: clamp(1.6rem, 5vw, 2.2rem); font-weight: 900;
color: #1e1b4b; letter-spacing: -0.02em; line-height: 1.15;
}
.pt-desc {
font-family: 'Nunito Sans', sans-serif;
font-size: 0.9rem; font-weight: 600; color: #9ca3af; margin-top: 0.3rem;
}
/* ── White card base ── */
.pt-card {
background: white; border: 2.5px solid #f3f4f6; border-radius: 24px;
padding: 1.25rem 1.5rem;
box-shadow: 0 6px 20px rgba(0,0,0,0.04);
box-sizing: border-box;
}
/* ── Stats row ── */
.pt-stats-row {
display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem;
}
.pt-stat {
display: flex; flex-direction: column; align-items: center;
gap: 0.5rem; padding: 0.85rem 0.5rem;
background: white; border: 2.5px solid #f3f4f6; border-radius: 20px;
box-shadow: 0 3px 10px rgba(0,0,0,0.04);
}
.pt-stat-icon {
width: 44px; height: 44px; border-radius: 50%;
display: flex; align-items: center; justify-content: center;
}
.pt-stat-icon.cyan { background: #cffafe; }
.pt-stat-icon.purple { background: #f3e8ff; }
.pt-stat-icon.amber { background: #fef3c7; }
.pt-stat-value { font-size: 1.4rem; font-weight: 900; color: #1e1b4b; line-height: 1; }
.pt-stat-label { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: #9ca3af; }
/* ── Loading skeleton ── */
.pt-loading {
display: flex; flex-direction: column; align-items: center;
gap: 0.75rem; padding: 2rem;
background: white; border: 2.5px solid #f3f4f6; border-radius: 24px;
box-shadow: 0 6px 20px rgba(0,0,0,0.04);
}
.pt-spinner { animation: ptSpin 0.8s linear infinite; }
@keyframes ptSpin { to { transform: rotate(360deg); } }
.pt-loading-text {
font-size: 0.85rem; font-weight: 700; color: #9ca3af;
}
/* ── Module carousel card ── */
.pt-module-card {
background: white; border: 2.5px solid #f3f4f6; border-radius: 24px;
padding: 1.25rem 1.5rem;
box-shadow: 0 6px 20px rgba(0,0,0,0.04);
display: flex; flex-direction: column; gap: 1rem;
}
.pt-module-header {
display: flex; align-items: center; gap: 0.6rem;
}
.pt-section-badge {
font-size: 0.65rem; font-weight: 800; letter-spacing: 0.12em;
text-transform: uppercase; color: #a855f7;
background: #f3e8ff; border-radius: 100px; padding: 0.25rem 0.7rem;
}
.pt-module-title {
font-size: 0.95rem; font-weight: 900; color: #1e1b4b; line-height: 1.3;
}
.pt-module-stats {
display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem;
}
.pt-module-stat {
display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
padding: 0.7rem 0.4rem;
border: 2px solid #f3f4f6; border-radius: 16px;
background: #fafafa;
}
.pt-module-stat-icon {
width: 36px; height: 36px; border-radius: 50%;
display: flex; align-items: center; justify-content: center;
}
.pt-module-stat-icon.cyan { background: #cffafe; }
.pt-module-stat-icon.lime { background: #d9f99d; }
.pt-module-stat-icon.amber { background: #fef3c7; }
.pt-module-stat-value { font-size: 1rem; font-weight: 900; color: #1e1b4b; line-height: 1; }
.pt-module-stat-label { font-size: 0.6rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: #9ca3af; }
/* ── Dot indicator ── */
.pt-dots {
display: flex; align-items: center; justify-content: center; gap: 0.4rem;
margin-top: 0.75rem;
}
.pt-dot-ind {
border-radius: 100px; height: 7px;
transition: width 0.3s ease, background 0.3s ease;
}
.pt-dot-ind.active { width: 20px; background: #a855f7; }
.pt-dot-ind.inactive { width: 7px; background: #e5e7eb; }
/* ── Tip card ── */
.pt-tip {
display: flex; align-items: flex-start; gap: 0.75rem;
}
.pt-tip-emoji { font-size: 1.4rem; flex-shrink: 0; margin-top: 2px; }
.pt-tip-text { font-size: 0.88rem; font-weight: 700; color: #374151; line-height: 1.5; }
/* ── Start button ── */
.pt-start-btn {
width: 100%;
background: #f97316; color: white; border: none; border-radius: 100px;
padding: 1.1rem; font-family: 'Nunito', sans-serif;
font-size: 1rem; font-weight: 800; cursor: pointer;
box-shadow: 0 6px 0 #c2560e, 0 8px 20px rgba(249,115,22,0.25);
transition: transform 0.1s ease, box-shadow 0.1s ease;
display: flex; align-items: center; justify-content: center; gap: 0.5rem;
}
.pt-start-btn:hover:not(:disabled) { transform:translateY(-2px); box-shadow:0 8px 0 #c2560e,0 12px 24px rgba(249,115,22,0.3); }
.pt-start-btn:active:not(:disabled) { transform:translateY(3px); box-shadow:0 3px 0 #c2560e,0 4px 12px rgba(249,115,22,0.2); }
.pt-start-btn:disabled { opacity:0.6; cursor:not-allowed; box-shadow:none; }
/* ── Error card ── */
.pt-error {
background: #fff5f5; border: 2.5px solid #fecaca; border-radius: 24px;
padding: 1.5rem; text-align: center;
font-size: 0.9rem; font-weight: 700; color: #ef4444;
}
`;
export const Pretest = () => {
const { setSheetId, setMode, storeDuration, setQuestionCount } =
useExamConfigStore();
const user = useAuthStore((state) => state.user);
const { sheetId } = useParams<{ sheetId: string }>();
const [carouselApi, setCarouselApi] = useState<CarouselApi>();
const [current, setCurrent] = useState(0);
const [count, setCount] = useState(0);
const navigate = useNavigate();
const [carouselApi, setCarouselApi] = useState<CarouselApi>();
const [current, setCurrent] = useState(0);
const [practiceSheet, setPracticeSheet] = useState<PracticeSheet | null>(
null,
);
function handleStartTest(sheetId: string) {
if (!sheetId) {
console.error("Sheet ID is required to start the test.");
return;
}
setSheetId(sheetId);
function handleStartTest(id: string) {
if (!id) return;
setSheetId(id);
setMode("SIMULATION");
storeDuration(practiceSheet?.time_limit ?? 0);
setQuestionCount(2);
navigate(`/student/practice/${sheetId}/test`, { replace: true });
navigate(`/student/practice/${id}/test`, { replace: true });
}
useEffect(() => {
if (!user) return;
async function fetchPracticeSheet(sheetId: string) {
async function fetchSheet(id: string) {
const authStorage = localStorage.getItem("auth-storage");
if (!authStorage) {
console.error("authStorage not found in local storage");
return;
}
if (!authStorage) return;
const {
state: { token },
} = JSON.parse(authStorage);
if (!token) {
console.error("Token not found in authStorage");
return;
}
const data = await api.getPracticeSheetById(token, sheetId);
if (!token) return;
const data = await api.getPracticeSheetById(token, id);
setPracticeSheet(data);
}
fetchPracticeSheet(sheetId!);
}, [sheetId]);
fetchSheet(sheetId!);
}, [sheetId, user]);
useEffect(() => {
if (!carouselApi) {
return;
}
setCount(carouselApi.scrollSnapList().length);
if (!carouselApi) return;
setCurrent(carouselApi.selectedScrollSnap() + 1);
carouselApi.on("select", () => {
setCurrent(carouselApi.selectedScrollSnap() + 1);
});
carouselApi.on("select", () =>
setCurrent(carouselApi.selectedScrollSnap() + 1),
);
}, [carouselApi]);
return (
<div className="p-8 space-y-6">
<header className="space-y-2">
<h1 className="text-4xl font-satoshi-bold">{practiceSheet?.title}</h1>
<p className="text-lg font-satoshi text-gray-700">
{practiceSheet?.description}
</p>
</header>
{practiceSheet ? (
<section className="flex flex-col gap-6 rounded-4xl bg-white border p-8">
<div className="flex items-center gap-4">
<Clock size={65} color="black" />
<div>
<h3 className="text-3xl font-satoshi-bold ">
{practiceSheet?.time_limit}
</h3>
<p className="text-xl font-satoshi ">Minutes</p>
</div>
</div>
<div className="flex items-center gap-4">
<Layers size={65} color="black" />
<div>
<h3 className="text-3xl font-satoshi-bold ">
{practiceSheet?.modules.length}
</h3>
<p className="text-xl font-satoshi">Modules</p>
</div>
</div>
<div className="flex items-center gap-4">
<CircleQuestionMark size={65} color="black" />
<div>
<h3 className="text-3xl font-satoshi-bold ">
{practiceSheet?.questions_count}
</h3>
<p className="text-xl font-satoshi ">Questions</p>
</div>
</div>
</section>
) : (
<section className="flex flex-col items-center gap-6 rounded-4xl bg-white border p-8">
<div>
<Loader size={30} className="transition animate-spin" />
</div>
</section>
)}
<Carousel className="" setApi={setCarouselApi}>
<CarouselContent>
{practiceSheet ? (
practiceSheet.modules.length > 0 ? (
practiceSheet.modules.map((module, index) => (
<CarouselItem key={index} className="">
<section className="flex flex-col gap-6 rounded-4xl p-8 bg-white border">
<h1 className="text-2xl font-satoshi-bold">
Section {Math.floor(index / 2) + 1}
</h1>
<p className="text-lg font-satoshi text-gray-700">
{module.title}
</p>
<section className="grid grid-cols-3 gap-6 sm:grid-cols-3">
<div className="flex flex-col justify-center items-center gap-4">
<div className="w-fit bg-cyan-100 p-2 rounded-full">
<Clock size={30} color="oklch(60.9% 0.126 221.723)" />
</div>
<div className="flex flex-col justify-center items-center">
<h3 className="text-xl font-satoshi-bold ">
{module.duration}
</h3>
<p className="text-md font-satoshi ">Minutes</p>
</div>
</div>
<div className="flex flex-col justify-center items-center gap-4">
<div className="w-fit bg-lime-100 p-2 rounded-full">
<CircleQuestionMark
size={30}
color="oklch(64.8% 0.2 131.684)"
/>
</div>
<div className="flex flex-col justify-center items-center">
<h3 className="text-xl font-satoshi-bold ">
{module.questions.length}
</h3>
<p className="text-md font-satoshi">Questions</p>
</div>
</div>
<div className="flex flex-col justify-center items-center gap-4">
<div className="w-fit bg-amber-100 p-2 rounded-full">
<Tag size={30} color="oklch(66.6% 0.179 58.318)" />
</div>
<div className="flex flex-col justify-center items-center">
<h3 className="text-xl font-satoshi-bold ">
{module.section}
</h3>
<p className="text-md font-satoshi">Type</p>
</div>
</div>
</section>
</section>
</CarouselItem>
))
) : (
<CarouselItem>
<section className="w-full rounded-4xl p-8 bg-red-100 border border-red-300">
<h1 className="text-lg text-center font-satoshi-bold text-red-500">
No modules available.
</h1>
</section>
</CarouselItem>
)
) : (
<CarouselItem>
<section className="flex flex-col w-full rounded-4xl p-8 bg-yellow-100 border items-center justify-between gap-4">
<div>
<Loader size={30} className="transition animate-spin" />
</div>
<h1 className="text-center text-xl font-satoshi-bold text-yellow-500">
Loading...
</h1>
</section>
</CarouselItem>
)}
</CarouselContent>
<div className="pt-screen">
<style>{STYLES}</style>
<div className="flex justify-center mt-4">
{practiceSheet?.modules.map((_, index) => (
<div
key={index}
className={`w-2 h-2 mx-1 rounded-full ${
index + 1 === current ? "bg-indigo-500" : "bg-gray-300"
}`}
></div>
))}
</div>
</Carousel>
<section className="w-full rounded-4xl p-8 bg-white border flex flex-col justify-between gap-4">
<h1 className="text-lg font-satoshi-bold ">
This practice sheet will help you prepare for the SAT. Take your time
and do your best!
</h1>
</section>
<Button
onClick={() => handleStartTest(practiceSheet?.id!)}
variant="outline"
className="font-satoshi rounded-3xl w-full text-lg py-8 bg-linear-to-br from-indigo-500 to-indigo-600 text-white active:bg-linear-to-br active:from-indigo-600 active:to-indigo-700 active:translate-y-1"
disabled={!practiceSheet}
>
{/* Blobs */}
<div className="pt-blob pt-blob-1" />
<div className="pt-blob pt-blob-2" />
<div className="pt-blob pt-blob-3" />
<div className="pt-blob pt-blob-4" />
{/* Floating dots */}
{DOTS.map((d, i) => (
<div
key={i}
className="pt-dot"
style={
{
width: d.size,
height: d.size,
background: d.color,
top: d.top,
left: d.left,
right: d.right,
animationDelay: d.delay,
animationDuration: `${5 + i * 0.5}s`,
} as React.CSSProperties
}
/>
))}
<div className="pt-inner">
{/* ── Header ── */}
<header className="pt-header">
<p className="pt-eyebrow">📋 Practice Sheet</p>
{practiceSheet ? (
<>
<h1 className="pt-title">{practiceSheet.title}</h1>
<p className="pt-desc">{practiceSheet.description}</p>
</>
) : (
<>
<div
style={{
height: "2rem",
width: "70%",
background: "#f3f4f6",
borderRadius: 8,
marginBottom: "0.5rem",
}}
/>
<div
style={{
height: "1rem",
width: "50%",
background: "#f3f4f6",
borderRadius: 8,
}}
/>
</>
)}
</header>
{/* ── At-a-glance stats ── */}
{practiceSheet ? (
"Start Test"
<div className="pt-stats-row pt-anim pt-anim-1">
<div className="pt-stat">
<div className="pt-stat-icon cyan">
<Clock size={22} color="#0891b2" />
</div>
<span className="pt-stat-value">{practiceSheet.time_limit}</span>
<span className="pt-stat-label">Minutes</span>
</div>
<div className="pt-stat">
<div className="pt-stat-icon purple">
<Layers size={22} color="#9333ea" />
</div>
<span className="pt-stat-value">
{practiceSheet.modules.length}
</span>
<span className="pt-stat-label">Modules</span>
</div>
<div className="pt-stat">
<div className="pt-stat-icon amber">
<CircleQuestionMark size={22} color="#d97706" />
</div>
<span className="pt-stat-value">
{practiceSheet.questions_count}
</span>
<span className="pt-stat-label">Questions</span>
</div>
</div>
) : (
<div>
<Loader size={60} className="transition animate-spin" />
<div className="pt-loading pt-anim pt-anim-1">
<Loader size={26} className="pt-spinner" color="#a855f7" />
<p className="pt-loading-text">Loading sheet details...</p>
</div>
)}
</Button>
{/* ── Module carousel ── */}
<div className="pt-anim pt-anim-2">
<Carousel setApi={setCarouselApi}>
<CarouselContent>
{practiceSheet ? (
practiceSheet.modules.length > 0 ? (
practiceSheet.modules.map((module, index) => (
<CarouselItem key={index}>
<div className="pt-module-card">
<div className="pt-module-header">
<span className="pt-section-badge">
Section {Math.floor(index / 2) + 1}
</span>
</div>
<p className="pt-module-title">{module.title}</p>
<div className="pt-module-stats">
<div className="pt-module-stat">
<div className="pt-module-stat-icon cyan">
<Clock size={18} color="#0891b2" />
</div>
<span className="pt-module-stat-value">
{module.duration}
</span>
<span className="pt-module-stat-label">Min</span>
</div>
<div className="pt-module-stat">
<div className="pt-module-stat-icon lime">
<CircleQuestionMark size={18} color="#65a30d" />
</div>
<span className="pt-module-stat-value">
{module.questions.length}
</span>
<span className="pt-module-stat-label">
Questions
</span>
</div>
<div className="pt-module-stat">
<div className="pt-module-stat-icon amber">
<Tag size={18} color="#d97706" />
</div>
<span
className="pt-module-stat-value"
style={{ fontSize: "0.85rem" }}
>
{module.section}
</span>
<span className="pt-module-stat-label">Type</span>
</div>
</div>
</div>
</CarouselItem>
))
) : (
<CarouselItem>
<div className="pt-error">
😕 No modules available for this sheet.
</div>
</CarouselItem>
)
) : (
<CarouselItem>
<div className="pt-loading">
<Loader size={26} className="pt-spinner" color="#a855f7" />
<p className="pt-loading-text">Loading modules...</p>
</div>
</CarouselItem>
)}
</CarouselContent>
{/* Dot indicator */}
{practiceSheet && practiceSheet.modules.length > 1 && (
<div className="pt-dots">
{practiceSheet.modules.map((_, i) => (
<div
key={i}
className={`pt-dot-ind ${i + 1 === current ? "active" : "inactive"}`}
/>
))}
</div>
)}
</Carousel>
</div>
{/* ── Encouragement tip ── */}
<div className="pt-card pt-anim pt-anim-3">
<div className="pt-tip">
<span className="pt-tip-emoji">💪</span>
<p className="pt-tip-text">
Take your time, read each question carefully, and do your best.
Every practice run brings you closer to your goal!
</p>
</div>
</div>
{/* ── Start button ── */}
<button
className="pt-start-btn pt-anim pt-anim-4"
onClick={() => handleStartTest(practiceSheet?.id!)}
disabled={!practiceSheet}
>
{practiceSheet ? (
<>Start Test </>
) : (
<Loader size={20} className="pt-spinner" />
)}
</button>
</div>
</div>
);
};