refactor: modify upload section
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
. "$(dirname "$0")/_/husky.sh"
|
# . "$(dirname "$0")/_/husky.sh"
|
||||||
|
|
||||||
npx lint-staged
|
# npx lint-staged
|
||||||
|
|||||||
2
next-env.d.ts
vendored
2
next-env.d.ts
vendored
@@ -1,6 +1,6 @@
|
|||||||
/// <reference types="next" />
|
/// <reference types="next" />
|
||||||
/// <reference types="next/image-types/global" />
|
/// <reference types="next/image-types/global" />
|
||||||
import './.next/dev/types/routes.d.ts';
|
import "./.next/types/routes.d.ts";
|
||||||
|
|
||||||
// NOTE: This file should not be edited
|
// NOTE: This file should not be edited
|
||||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useRouter } from 'next/navigation';
|
|
||||||
import dynamic from 'next/dynamic';
|
|
||||||
import { sessionService } from '@/services/api';
|
|
||||||
import { SessionContext } from '@/types';
|
|
||||||
import { PowerCircle, TrendingUp } from 'lucide-react';
|
|
||||||
import { PageHeader } from '@/components/page-header';
|
|
||||||
import { PoweredBy } from '@/components/powered-by';
|
|
||||||
import { ROUTES } from '@/utils/routes';
|
|
||||||
import { Reveal } from '@/components/ui/reveal';
|
|
||||||
|
|
||||||
const ProjectSelectionSection = dynamic(
|
|
||||||
() => import('@/components/project-selection-section').then((mod) => mod.ProjectSelectionSection),
|
|
||||||
{ ssr: false },
|
|
||||||
);
|
|
||||||
|
|
||||||
export default function NewAnalysisPage() {
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
const handleSelectionComplete = (session: SessionContext) => {
|
|
||||||
// Save session to storage and navigate to upload page
|
|
||||||
sessionService.saveSession(session);
|
|
||||||
router.push(ROUTES.UPLOAD);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{/* Main Content */}
|
|
||||||
<main>
|
|
||||||
<div>
|
|
||||||
{/* Refined Left-Aligned Header */}
|
|
||||||
<div className="mb-8">
|
|
||||||
<PageHeader
|
|
||||||
title="VisionRoad Detection System"
|
|
||||||
description="Select project details to begin your AI-powered road infrastructure analysis"
|
|
||||||
icon={TrendingUp}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Project Selection Section */}
|
|
||||||
<Reveal delay={0.2} direction="up">
|
|
||||||
<div>
|
|
||||||
<ProjectSelectionSection onSelectionComplete={handleSelectionComplete} />
|
|
||||||
</div>
|
|
||||||
</Reveal>
|
|
||||||
|
|
||||||
<Reveal delay={0.4}>
|
|
||||||
<PoweredBy />
|
|
||||||
</Reveal>
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -77,7 +77,7 @@ export default function VideoResultsPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sessionService.clearSession();
|
sessionService.clearSession();
|
||||||
router.push(ROUTES.NEW_ANALYSIS);
|
router.push(ROUTES.UPLOAD);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getTitle = () => {
|
const getTitle = () => {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export default function ResultsPage() {
|
|||||||
const videoData = sessionService.loadVideoData();
|
const videoData = sessionService.loadVideoData();
|
||||||
|
|
||||||
if (!sessionService.isSessionValid(storedSession) || !videoData) {
|
if (!sessionService.isSessionValid(storedSession) || !videoData) {
|
||||||
router.replace(ROUTES.NEW_ANALYSIS);
|
router.replace(ROUTES.UPLOAD);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ export default function ResultsPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sessionService.clearSession();
|
sessionService.clearSession();
|
||||||
router.push(ROUTES.NEW_ANALYSIS);
|
router.push(ROUTES.UPLOAD);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getTitle = () => {
|
const getTitle = () => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState, useEffect, useCallback } from 'react';
|
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||||
import { useRouter, useParams } from 'next/navigation';
|
import { useRouter, useParams } from 'next/navigation';
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { Loader2, TrendingUp, ArrowUp, ArrowDown } from 'lucide-react';
|
import { Loader2, TrendingUp, ArrowUp, ArrowDown } from 'lucide-react';
|
||||||
@@ -25,9 +25,14 @@ export default function VideoProcessingPage() {
|
|||||||
const [statusMessage, setStatusMessage] = useState('Initializing...');
|
const [statusMessage, setStatusMessage] = useState('Initializing...');
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const wsRef = useRef<WebSocket | null>(null);
|
||||||
|
|
||||||
const connectWebSocket = useCallback(
|
const connectWebSocket = useCallback(
|
||||||
(vid: string) => {
|
(vid: string) => {
|
||||||
|
if (wsRef.current) return wsRef.current;
|
||||||
|
|
||||||
const ws = new WebSocket(`${WS_URL}/ws/${vid}`);
|
const ws = new WebSocket(`${WS_URL}/ws/${vid}`);
|
||||||
|
wsRef.current = ws;
|
||||||
|
|
||||||
ws.onmessage = async (event) => {
|
ws.onmessage = async (event) => {
|
||||||
const data = JSON.parse(event.data);
|
const data = JSON.parse(event.data);
|
||||||
@@ -60,9 +65,14 @@ export default function VideoProcessingPage() {
|
|||||||
|
|
||||||
ws.onerror = () => {
|
ws.onerror = () => {
|
||||||
setStatusMessage('Connection lost. Reconnecting...');
|
setStatusMessage('Connection lost. Reconnecting...');
|
||||||
|
wsRef.current = null;
|
||||||
setTimeout(() => connectWebSocket(vid), 3000);
|
setTimeout(() => connectWebSocket(vid), 3000);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ws.onclose = () => {
|
||||||
|
wsRef.current = null;
|
||||||
|
};
|
||||||
|
|
||||||
return ws;
|
return ws;
|
||||||
},
|
},
|
||||||
[router],
|
[router],
|
||||||
@@ -72,10 +82,14 @@ export default function VideoProcessingPage() {
|
|||||||
const storedSession = sessionService.loadSession();
|
const storedSession = sessionService.loadSession();
|
||||||
setSession(storedSession);
|
setSession(storedSession);
|
||||||
|
|
||||||
|
let isMounted = true;
|
||||||
|
|
||||||
const checkStatus = async () => {
|
const checkStatus = async () => {
|
||||||
try {
|
try {
|
||||||
const statusData = await videoService.getVideoStatus(videoId);
|
const statusData = await videoService.getVideoStatus(videoId);
|
||||||
|
|
||||||
|
if (!isMounted) return;
|
||||||
|
|
||||||
if (statusData.status === 'completed') {
|
if (statusData.status === 'completed') {
|
||||||
router.replace(`/results/${videoId}`);
|
router.replace(`/results/${videoId}`);
|
||||||
return;
|
return;
|
||||||
@@ -94,14 +108,24 @@ export default function VideoProcessingPage() {
|
|||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Status check failed:', err);
|
console.error('Status check failed:', err);
|
||||||
|
if (isMounted) {
|
||||||
setError('Failed to connect to server.');
|
setError('Failed to connect to server.');
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (videoId) {
|
if (videoId) {
|
||||||
checkStatus();
|
checkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
isMounted = false;
|
||||||
|
if (wsRef.current) {
|
||||||
|
wsRef.current.close();
|
||||||
|
wsRef.current = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
}, [videoId, router, connectWebSocket]);
|
}, [videoId, router, connectWebSocket]);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect, useCallback } from 'react';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@@ -13,17 +13,16 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from '@/components/ui/select';
|
} from '@/components/ui/select';
|
||||||
import { Loader2, TrendingUp, ArrowUp, ArrowDown } from 'lucide-react';
|
import { Loader2, TrendingUp, ChevronRight } from 'lucide-react';
|
||||||
import { PageHeader } from '@/components/page-header';
|
import { PageHeader } from '@/components/page-header';
|
||||||
import { PoweredBy } from '@/components/powered-by';
|
import { PoweredBy } from '@/components/powered-by';
|
||||||
import { sessionService, videoService } from '@/services/api';
|
import { sessionService, videoService } from '@/services/api';
|
||||||
import { SessionContext } from '@/types';
|
import { SessionContext } from '@/types';
|
||||||
import { ROUTES } from '@/utils/routes';
|
|
||||||
import { storeVideoFile } from '@/lib/video-storage';
|
import { storeVideoFile } from '@/lib/video-storage';
|
||||||
|
import { ProjectSelectionSection } from '@/components/project-selection-section';
|
||||||
|
import { Reveal } from '@/components/ui/reveal';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
|
||||||
|
|
||||||
const DETECTION_METHODS = [
|
const DETECTION_METHODS = [
|
||||||
{ value: 'yolo', label: 'YOLO Detection Model' },
|
{ value: 'yolo', label: 'YOLO Detection Model' },
|
||||||
{ value: 'yolo_vl', label: 'YOLO with Vision-Language Model' },
|
{ value: 'yolo_vl', label: 'YOLO with Vision-Language Model' },
|
||||||
@@ -45,20 +44,21 @@ export default function UploadPage() {
|
|||||||
|
|
||||||
// Upload states
|
// Upload states
|
||||||
const [uploading, setUploading] = useState(false);
|
const [uploading, setUploading] = useState(false);
|
||||||
const [progress, setProgress] = useState(0);
|
|
||||||
const [statusMessage, setStatusMessage] = useState('');
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
// Load session on mount
|
// Load session on mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const storedSession = sessionService.loadSession();
|
// We don't load session on mount for the upload page to ensure
|
||||||
if (!sessionService.isSessionValid(storedSession)) {
|
// project details are filled manually as requested.
|
||||||
router.replace(ROUTES.NEW_ANALYSIS);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setSession(storedSession);
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}, [router]);
|
}, []);
|
||||||
|
|
||||||
|
const handleSelectionChange = useCallback((selectedSession: SessionContext | null) => {
|
||||||
|
setSession(selectedSession);
|
||||||
|
if (selectedSession) {
|
||||||
|
sessionService.saveSession(selectedSession);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleUpload = async () => {
|
const handleUpload = async () => {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@@ -66,27 +66,27 @@ export default function UploadPage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!session) {
|
||||||
|
setError('Please complete the project selection first');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
formData.append('detection_mode', selectMethod);
|
formData.append('detection_mode', selectMethod);
|
||||||
|
formData.append('chainage_id', session.chainageId as string);
|
||||||
if (session?.chainageId) {
|
|
||||||
formData.append('chainage_id', session.chainageId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jsonFile) {
|
if (jsonFile) {
|
||||||
formData.append('json_file', jsonFile);
|
formData.append('json_file', jsonFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
setUploading(true);
|
setUploading(true);
|
||||||
setProgress(0);
|
|
||||||
setStatusMessage('Uploading...');
|
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await videoService.uploadVideo(formData);
|
const result = await videoService.uploadVideo(formData);
|
||||||
|
|
||||||
// Store file locally for potential recovery/results display
|
// Store file locally
|
||||||
if (file) {
|
if (file) {
|
||||||
try {
|
try {
|
||||||
await storeVideoFile(result.video_id, file);
|
await storeVideoFile(result.video_id, file);
|
||||||
@@ -96,8 +96,6 @@ export default function UploadPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sessionService.saveVideoData({ videoId: result.video_id });
|
sessionService.saveVideoData({ videoId: result.video_id });
|
||||||
|
|
||||||
// Redirect to the dynamic processing page
|
|
||||||
router.push(`/upload/${result.video_id}`);
|
router.push(`/upload/${result.video_id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
let errorMessage = 'Upload failed';
|
let errorMessage = 'Upload failed';
|
||||||
@@ -107,115 +105,72 @@ export default function UploadPage() {
|
|||||||
errorMessage = err.message;
|
errorMessage = err.message;
|
||||||
}
|
}
|
||||||
setError(errorMessage);
|
setError(errorMessage);
|
||||||
setStatusMessage('');
|
|
||||||
setUploading(false);
|
setUploading(false);
|
||||||
setProgress(0);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBackToSelection = () => {
|
|
||||||
sessionService.clearSession();
|
|
||||||
router.push(ROUTES.NEW_ANALYSIS);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getTitle = () => 'Road Analysis';
|
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex items-center justify-center">
|
<div className="min-h-screen flex items-center justify-center">
|
||||||
<Card className="p-8">
|
<Loader2 className="h-10 w-10 animate-spin text-primary" />
|
||||||
<Loader2 className="h-8 w-8 animate-spin text-primary" />
|
|
||||||
</Card>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isSessionComplete = !!(session && sessionService.isSessionValid(session));
|
||||||
|
const isFormValid = isSessionComplete && file;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen">
|
<div className="min-h-screen pb-12">
|
||||||
{/* Main Content */}
|
<main>
|
||||||
<main className="min-h-screen flex flex-col">
|
|
||||||
<div className="flex-1 container mx-auto px-6 py-6 max-w-340 flex flex-col">
|
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div className="mb-6">
|
<div className="mb-10">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title={getTitle()}
|
title="Intelligent Road Asset AI Analysis"
|
||||||
description="Upload video file and fill in required details to start the road analysis"
|
description="High-precision detection for potholes, signboards, and culverts from video data"
|
||||||
icon={TrendingUp}
|
icon={TrendingUp}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Compact Session Info Bar */}
|
<div className="space-y-8 mt-8">
|
||||||
{session && (
|
{/* Module 1: Project Selection */}
|
||||||
<div className="mb-6">
|
<Reveal direction="up" delay={0.1}>
|
||||||
<Card className="p-0 border shadow-sm overflow-hidden">
|
<Card className="border">
|
||||||
<div className="flex flex-col md:flex-row md:items-center justify-between py-4 px-6 gap-6 bg-card">
|
<CardHeader>
|
||||||
<div className="flex flex-wrap items-center gap-x-12 gap-y-4">
|
<CardTitle className="text-xl font-bold">1. Project Details</CardTitle>
|
||||||
{[
|
<CardDescription>
|
||||||
{ label: 'Project', value: session.projectName, primary: true },
|
Select the target project, package, and chainage segment.
|
||||||
{ label: 'Package', value: session.packageName },
|
|
||||||
{ label: 'Chainage', value: session.chainageName },
|
|
||||||
].map((item, idx) => (
|
|
||||||
<div
|
|
||||||
key={item.label}
|
|
||||||
className={cn(
|
|
||||||
'flex flex-col',
|
|
||||||
idx !== 0 && 'border-l pl-12 border-border/60',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<span className="text-[10px] font-bold uppercase tracking-widest text-muted-foreground mb-1.5">
|
|
||||||
{item.label}
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
className={cn(
|
|
||||||
'leading-tight flex items-center gap-1.5',
|
|
||||||
item.primary
|
|
||||||
? 'text-base font-bold'
|
|
||||||
: 'text-sm font-semibold text-muted-foreground',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{item.value}
|
|
||||||
{item.label === 'Chainage' && session.chainageDirection && (
|
|
||||||
<span className="flex items-center gap-1 px-1 py-0.5 rounded bg-muted text-[10px] font-bold uppercase border ml-1">
|
|
||||||
{session.chainageDirection === 'UP' ? (
|
|
||||||
<ArrowUp className="h-2.5 w-2.5" />
|
|
||||||
) : (
|
|
||||||
<ArrowDown className="h-2.5 w-2.5" />
|
|
||||||
)}
|
|
||||||
{session.chainageDirection}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={handleBackToSelection}
|
|
||||||
className="font-semibold px-6 shrink-0 h-9"
|
|
||||||
>
|
|
||||||
Change Selection
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Upload Card */}
|
|
||||||
<Card className="flex-1">
|
|
||||||
<CardHeader className="pb-4">
|
|
||||||
<CardTitle className="text-xl font-bold">Upload Video</CardTitle>
|
|
||||||
<CardDescription className="text-sm">
|
|
||||||
Select video file, GPS JSON file, and method for analysis
|
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="pt-4 space-y-6">
|
<CardContent>
|
||||||
<div className="space-y-6">
|
<ProjectSelectionSection
|
||||||
{/* Video File Input - Full Width */}
|
onSelectionChange={handleSelectionChange}
|
||||||
|
asStep={true}
|
||||||
|
hideButton={true}
|
||||||
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</Reveal>
|
||||||
|
|
||||||
|
{/* Module 2: Upload Data */}
|
||||||
|
<Reveal direction="up" delay={0.2}>
|
||||||
|
<Card className={cn("border transition-all duration-300", !isSessionComplete && "opacity-60 pointer-events-none grayscale-[0.5]")}>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="text-xl font-bold flex items-center gap-2">
|
||||||
|
2. Upload Video Data
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Provide the video file and optional GPS telemetry for processing.
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-6">
|
||||||
|
<div className="grid grid-cols-1 gap-6 text-sm">
|
||||||
|
{/* Video File Input */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="video-file" className="text-sm font-semibold">
|
<Label htmlFor="video-file" className="text-sm font-semibold">
|
||||||
Video File
|
Video File <span className="text-destructive">*</span>
|
||||||
</Label>
|
</Label>
|
||||||
|
<div className="relative group">
|
||||||
<Input
|
<Input
|
||||||
id="video-file"
|
id="video-file"
|
||||||
type="file"
|
type="file"
|
||||||
@@ -224,17 +179,17 @@ export default function UploadPage() {
|
|||||||
setFile(e.target.files?.[0] || null);
|
setFile(e.target.files?.[0] || null);
|
||||||
setError(null);
|
setError(null);
|
||||||
}}
|
}}
|
||||||
disabled={uploading}
|
disabled={uploading || !isSessionComplete}
|
||||||
className="h-11 bg-muted/20 file:mr-3 file:py-1.5 file:px-3 file:rounded-md file:border-0 file:bg-primary/10 file:text-primary file:font-medium file:text-xs hover:file:bg-primary/20"
|
className="h-12 bg-muted/30 border-dashed border-2 group-hover:border-primary/50 transition-colors cursor-pointer file:mr-4 file:py-1.5 file:px-3 file:rounded-md file:border-0 file:bg-primary file:text-primary-foreground file:font-semibold file:text-xs"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* JSON File and Method - Both in one line */}
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||||
{/* JSON File Input */}
|
{/* JSON File Input */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="json-file" className="text-sm font-semibold">
|
<Label htmlFor="json-file" className="text-sm font-semibold">
|
||||||
GPS JSON File
|
GPS JSON File (Optional)
|
||||||
</Label>
|
</Label>
|
||||||
<Input
|
<Input
|
||||||
id="json-file"
|
id="json-file"
|
||||||
@@ -244,22 +199,22 @@ export default function UploadPage() {
|
|||||||
setJsonFile(e.target.files?.[0] || null);
|
setJsonFile(e.target.files?.[0] || null);
|
||||||
setError(null);
|
setError(null);
|
||||||
}}
|
}}
|
||||||
disabled={uploading}
|
disabled={uploading || !isSessionComplete}
|
||||||
className="h-11 bg-muted/20 file:mr-3 file:py-1.5 file:px-3 file:rounded-md file:border-0 file:bg-primary/10 file:text-primary file:font-medium file:text-xs hover:file:bg-primary/20"
|
className="h-11 bg-muted/20 file:mr-3 file:py-1.5 file:px-3 file:rounded-md file:border-0 file:bg-primary/10 file:text-primary file:font-medium file:text-xs"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Select Method */}
|
{/* Select Method */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="select-method" className="text-sm font-semibold">
|
<Label htmlFor="select-method" className="text-sm font-semibold">
|
||||||
Select Method
|
Analysis Method
|
||||||
</Label>
|
</Label>
|
||||||
<Select
|
<Select
|
||||||
value={selectMethod}
|
value={selectMethod}
|
||||||
onValueChange={setSelectMethod}
|
onValueChange={setSelectMethod}
|
||||||
disabled={uploading}
|
disabled={uploading || !isSessionComplete}
|
||||||
>
|
>
|
||||||
<SelectTrigger id="select-method" className="h-11">
|
<SelectTrigger id="select-method" className="h-11 bg-muted/20">
|
||||||
<SelectValue placeholder="Select method" />
|
<SelectValue placeholder="Select method" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@@ -276,31 +231,40 @@ export default function UploadPage() {
|
|||||||
|
|
||||||
{/* Error Display */}
|
{/* Error Display */}
|
||||||
{error && (
|
{error && (
|
||||||
<div className="p-4 rounded-md bg-destructive/10 border border-destructive/20 text-destructive text-sm leading-relaxed whitespace-pre-line">
|
<div className="p-4 rounded-md bg-destructive/5 border border-destructive/20 text-destructive text-sm font-medium animate-in fade-in slide-in-from-top-1">
|
||||||
{error}
|
{error}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Upload Button */}
|
{/* Primary Action Button */}
|
||||||
|
<div className="pt-2">
|
||||||
<Button
|
<Button
|
||||||
onClick={handleUpload}
|
onClick={handleUpload}
|
||||||
disabled={!file || uploading}
|
disabled={!isFormValid || uploading}
|
||||||
className="w-full h-14 text-base font-bold uppercase tracking-wide"
|
className="w-full h-14 font-extrabold uppercase tracking-wider"
|
||||||
size="lg"
|
|
||||||
>
|
>
|
||||||
{uploading ? (
|
{uploading ? (
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-3">
|
||||||
<Loader2 className="h-5 w-5 animate-spin" />
|
<Loader2 className="h-5 w-5 animate-spin" />
|
||||||
<span>Processing...</span>
|
<span>Processing Upload...</span>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
'Upload and Process'
|
<div className="flex items-center gap-2">
|
||||||
|
<span>Upload & Process Analysis</span>
|
||||||
|
<ChevronRight className="h-5 w-5" />
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
</Reveal>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-12">
|
||||||
|
<Reveal delay={0.4}>
|
||||||
<PoweredBy />
|
<PoweredBy />
|
||||||
|
</Reveal>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const data = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'New Analysis',
|
title: 'New Analysis',
|
||||||
url: ROUTES.NEW_ANALYSIS,
|
url: ROUTES.UPLOAD,
|
||||||
icon: Plus,
|
icon: Plus,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect, useRef } from 'react';
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
@@ -17,12 +17,23 @@ import { Project, Package as PackageType, Chainage, SessionContext } from '@/typ
|
|||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
type ProjectSelectionSectionProps = {
|
type ProjectSelectionSectionProps = {
|
||||||
onSelectionComplete: (session: SessionContext) => void;
|
onSelectionComplete?: (session: SessionContext) => void;
|
||||||
|
onSelectionChange?: (session: SessionContext | null) => void;
|
||||||
|
asStep?: boolean;
|
||||||
|
hideButton?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function ProjectSelectionSection({ onSelectionComplete }: ProjectSelectionSectionProps) {
|
let globalProjectsCache: Project[] | null = null;
|
||||||
|
let projectsPromise: Promise<Project[]> | null = null;
|
||||||
|
|
||||||
|
export function ProjectSelectionSection({
|
||||||
|
onSelectionComplete,
|
||||||
|
onSelectionChange,
|
||||||
|
asStep = false,
|
||||||
|
hideButton = false
|
||||||
|
}: ProjectSelectionSectionProps) {
|
||||||
// Data states
|
// Data states
|
||||||
const [projects, setProjects] = useState<Project[]>([]);
|
const [projects, setProjects] = useState<Project[]>(globalProjectsCache || []);
|
||||||
const [packages, setPackages] = useState<PackageType[]>([]);
|
const [packages, setPackages] = useState<PackageType[]>([]);
|
||||||
const [chainages, setChainages] = useState<Chainage[]>([]);
|
const [chainages, setChainages] = useState<Chainage[]>([]);
|
||||||
|
|
||||||
@@ -32,7 +43,7 @@ export function ProjectSelectionSection({ onSelectionComplete }: ProjectSelectio
|
|||||||
const [selectedChainage, setSelectedChainage] = useState<Chainage | null>(null);
|
const [selectedChainage, setSelectedChainage] = useState<Chainage | null>(null);
|
||||||
|
|
||||||
// Loading states
|
// Loading states
|
||||||
const [loadingProjects, setLoadingProjects] = useState(true);
|
const [loadingProjects, setLoadingProjects] = useState(!globalProjectsCache);
|
||||||
const [loadingPackages, setLoadingPackages] = useState(false);
|
const [loadingPackages, setLoadingPackages] = useState(false);
|
||||||
const [loadingChainages, setLoadingChainages] = useState(false);
|
const [loadingChainages, setLoadingChainages] = useState(false);
|
||||||
|
|
||||||
@@ -41,20 +52,48 @@ export function ProjectSelectionSection({ onSelectionComplete }: ProjectSelectio
|
|||||||
|
|
||||||
// Load projects on mount
|
// Load projects on mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
let isMounted = true;
|
||||||
|
|
||||||
const loadProjects = async () => {
|
const loadProjects = async () => {
|
||||||
try {
|
// Use cache if we already have it
|
||||||
setLoadingProjects(true);
|
if (globalProjectsCache) {
|
||||||
setError(null);
|
if (isMounted) {
|
||||||
const data = await projectService.getProjects();
|
setProjects(globalProjectsCache);
|
||||||
setProjects(data.items);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to load projects:', err);
|
|
||||||
setError('Failed to load projects. Please check if the backend is running.');
|
|
||||||
} finally {
|
|
||||||
setLoadingProjects(false);
|
setLoadingProjects(false);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a fetch is already in flight, reuse that promise
|
||||||
|
if (!projectsPromise) {
|
||||||
|
projectsPromise = projectService.getProjects().then(data => {
|
||||||
|
globalProjectsCache = data.items;
|
||||||
|
return data.items;
|
||||||
|
}).catch(err => {
|
||||||
|
projectsPromise = null; // Reset on error to allow retry
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
setLoadingProjects(true);
|
||||||
|
const data = await projectsPromise;
|
||||||
|
if (isMounted) {
|
||||||
|
setProjects(data);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (isMounted) {
|
||||||
|
setError('Failed to load projects. Please check connection.');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (isMounted) {
|
||||||
|
setLoadingProjects(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
loadProjects();
|
loadProjects();
|
||||||
|
return () => { isMounted = false; };
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Load packages when project changes
|
// Load packages when project changes
|
||||||
@@ -65,6 +104,7 @@ export function ProjectSelectionSection({ onSelectionComplete }: ProjectSelectio
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let isMounted = true;
|
||||||
const loadPackages = async () => {
|
const loadPackages = async () => {
|
||||||
try {
|
try {
|
||||||
setLoadingPackages(true);
|
setLoadingPackages(true);
|
||||||
@@ -73,15 +113,22 @@ export function ProjectSelectionSection({ onSelectionComplete }: ProjectSelectio
|
|||||||
setSelectedChainage(null);
|
setSelectedChainage(null);
|
||||||
setChainages([]);
|
setChainages([]);
|
||||||
const data = await packageService.getPackagesByProject(selectedProject.id);
|
const data = await packageService.getPackagesByProject(selectedProject.id);
|
||||||
|
if (isMounted) {
|
||||||
setPackages(data.items);
|
setPackages(data.items);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (isMounted) {
|
||||||
console.error('Failed to load packages:', err);
|
console.error('Failed to load packages:', err);
|
||||||
setError('Failed to load packages for the selected project.');
|
setError('Failed to load packages for the selected project.');
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
if (isMounted) {
|
||||||
setLoadingPackages(false);
|
setLoadingPackages(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
loadPackages();
|
loadPackages();
|
||||||
|
return () => { isMounted = false; };
|
||||||
}, [selectedProject]);
|
}, [selectedProject]);
|
||||||
|
|
||||||
// Load chainages when package changes
|
// Load chainages when package changes
|
||||||
@@ -92,21 +139,29 @@ export function ProjectSelectionSection({ onSelectionComplete }: ProjectSelectio
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let isMounted = true;
|
||||||
const loadChainages = async () => {
|
const loadChainages = async () => {
|
||||||
try {
|
try {
|
||||||
setLoadingChainages(true);
|
setLoadingChainages(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
setSelectedChainage(null);
|
setSelectedChainage(null);
|
||||||
const data = await chainageService.getChainagesByPackage(selectedPackage.id);
|
const data = await chainageService.getChainagesByPackage(selectedPackage.id);
|
||||||
|
if (isMounted) {
|
||||||
setChainages(data.items);
|
setChainages(data.items);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (isMounted) {
|
||||||
console.error('Failed to load chainages:', err);
|
console.error('Failed to load chainages:', err);
|
||||||
setError('Failed to load chainages for the selected package.');
|
setError('Failed to load chainages for the selected package.');
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
if (isMounted) {
|
||||||
setLoadingChainages(false);
|
setLoadingChainages(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
loadChainages();
|
loadChainages();
|
||||||
|
return () => { isMounted = false; };
|
||||||
}, [selectedPackage]);
|
}, [selectedPackage]);
|
||||||
|
|
||||||
const handleProjectChange = (projectId: string) => {
|
const handleProjectChange = (projectId: string) => {
|
||||||
@@ -124,8 +179,38 @@ export function ProjectSelectionSection({ onSelectionComplete }: ProjectSelectio
|
|||||||
setSelectedChainage(chainage);
|
setSelectedChainage(chainage);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleProceed = () => {
|
// Cache the last reported state to prevent infinite loops
|
||||||
|
const lastReportedIdRef = useRef<string | null>(null);
|
||||||
|
|
||||||
|
// Handle change reporting
|
||||||
|
useEffect(() => {
|
||||||
|
if (onSelectionChange) {
|
||||||
|
const currentIds = selectedProject && selectedPackage && selectedChainage
|
||||||
|
? `${selectedProject.id}-${selectedPackage.id}-${selectedChainage.id}`
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (currentIds !== lastReportedIdRef.current) {
|
||||||
|
lastReportedIdRef.current = currentIds;
|
||||||
|
|
||||||
if (selectedProject && selectedPackage && selectedChainage) {
|
if (selectedProject && selectedPackage && selectedChainage) {
|
||||||
|
onSelectionChange({
|
||||||
|
projectId: selectedProject.id,
|
||||||
|
projectName: selectedProject.name,
|
||||||
|
packageId: selectedPackage.id,
|
||||||
|
packageName: selectedPackage.name,
|
||||||
|
chainageId: selectedChainage.id,
|
||||||
|
chainageName: selectedChainage.segment_name,
|
||||||
|
chainageDirection: selectedChainage.direction,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
onSelectionChange(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [selectedProject, selectedPackage, selectedChainage, onSelectionChange]);
|
||||||
|
|
||||||
|
const handleProceed = () => {
|
||||||
|
if (selectedProject && selectedPackage && selectedChainage && onSelectionComplete) {
|
||||||
onSelectionComplete({
|
onSelectionComplete({
|
||||||
projectId: selectedProject.id,
|
projectId: selectedProject.id,
|
||||||
projectName: selectedProject.name,
|
projectName: selectedProject.name,
|
||||||
@@ -148,70 +233,16 @@ export function ProjectSelectionSection({ onSelectionComplete }: ProjectSelectio
|
|||||||
return 'pending';
|
return 'pending';
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
const content = (
|
||||||
<Card className="overflow-hidden">
|
<>
|
||||||
<CardHeader className="pb-6">
|
|
||||||
<div className="flex flex-col gap-6">
|
|
||||||
<div>
|
|
||||||
<CardTitle className="text-2xl font-bold">Select Project Chainage</CardTitle>
|
|
||||||
<CardDescription className="mt-2 text-base">
|
|
||||||
Select Project, Package & Chainage to begin intelligent road analysis.
|
|
||||||
</CardDescription>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Step Progress Indicator */}
|
|
||||||
<div className="flex items-center justify-center pt-2">
|
|
||||||
{[1, 2, 3].map((step, index) => {
|
|
||||||
const status = getStepStatus(step);
|
|
||||||
const labels = ['Project', 'Package', 'Chainage'];
|
|
||||||
return (
|
|
||||||
<div key={step} className="flex items-center">
|
|
||||||
<div className="flex flex-col items-center">
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'w-10 h-10 rounded-full flex items-center justify-center text-sm font-semibold transition-all',
|
|
||||||
status === 'completed'
|
|
||||||
? 'bg-primary text-primary-foreground'
|
|
||||||
: status === 'active'
|
|
||||||
? 'bg-primary text-primary-foreground ring-4 ring-primary/10'
|
|
||||||
: 'bg-muted text-muted-foreground',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{status === 'completed' ? <Check className="h-5 w-5" /> : step}
|
|
||||||
</div>
|
|
||||||
<span
|
|
||||||
className={cn(
|
|
||||||
'text-xs mt-2 font-medium',
|
|
||||||
status === 'pending' ? 'text-muted-foreground/60' : 'text-foreground',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{labels[index]}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{index < 2 && (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'w-16 h-0.5 mx-2 mb-6 rounded-full',
|
|
||||||
getStepStatus(step + 1) !== 'pending' ? 'bg-primary' : 'bg-border',
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardHeader>
|
|
||||||
|
|
||||||
<CardContent className="space-y-8">
|
|
||||||
{/* Error Display */}
|
{/* Error Display */}
|
||||||
{error && (
|
{error && (
|
||||||
<div className="p-4 rounded-md bg-destructive/10 border border-destructive/20 text-destructive text-sm">
|
<div className="p-4 rounded-md bg-destructive/10 border border-destructive/20 text-destructive text-sm mb-6">
|
||||||
{error}
|
{error}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
|
||||||
{/* Project Dropdown */}
|
{/* Project Dropdown */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="project" className="text-sm font-semibold">
|
<Label htmlFor="project" className="text-sm font-semibold">
|
||||||
@@ -321,9 +352,9 @@ export function ProjectSelectionSection({ onSelectionComplete }: ProjectSelectio
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Selected Summary */}
|
{/* Selected Summary - Only if not asStep or if specifically desired */}
|
||||||
{isComplete && (
|
{!asStep && isComplete && (
|
||||||
<div className="px-4 py-3 rounded-md bg-secondary/50 border text-sm">
|
<div className="px-4 py-3 rounded-md bg-secondary/50 border text-sm mb-8">
|
||||||
<div className="flex items-center gap-2 flex-wrap text-muted-foreground">
|
<div className="flex items-center gap-2 flex-wrap text-muted-foreground">
|
||||||
<span className="font-semibold text-foreground">Selection:</span>
|
<span className="font-semibold text-foreground">Selection:</span>
|
||||||
<span className="text-foreground">{selectedProject?.name}</span>
|
<span className="text-foreground">{selectedProject?.name}</span>
|
||||||
@@ -346,14 +377,80 @@ export function ProjectSelectionSection({ onSelectionComplete }: ProjectSelectio
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Proceed Button */}
|
{/* Proceed Button */}
|
||||||
|
{!hideButton && (
|
||||||
<Button
|
<Button
|
||||||
onClick={handleProceed}
|
onClick={handleProceed}
|
||||||
disabled={!isComplete}
|
disabled={!isComplete}
|
||||||
className="w-full h-12 text-base font-bold uppercase tracking-wide"
|
className="w-full h-14 text-base font-bold uppercase tracking-wider"
|
||||||
size="lg"
|
size="lg"
|
||||||
>
|
>
|
||||||
{isComplete ? 'Proceed to Upload' : 'Select all fields to proceed'}
|
{isComplete ? 'Proceed to Upload' : 'Select all fields to proceed'}
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (asStep) {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="overflow-hidden">
|
||||||
|
<CardHeader className="pb-6">
|
||||||
|
<div className="flex flex-col gap-6">
|
||||||
|
<div>
|
||||||
|
<CardTitle className="text-2xl font-bold">Select Project Chainage</CardTitle>
|
||||||
|
<CardDescription className="mt-2 text-base">
|
||||||
|
Select Project, Package & Chainage to begin intelligent road analysis.
|
||||||
|
</CardDescription>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Step Progress Indicator */}
|
||||||
|
<div className="flex items-center justify-center pt-2">
|
||||||
|
{[1, 2, 3].map((step, index) => {
|
||||||
|
const status = getStepStatus(step);
|
||||||
|
const labels = ['Project', 'Package', 'Chainage'];
|
||||||
|
return (
|
||||||
|
<div key={step} className="flex items-center">
|
||||||
|
<div className="flex flex-col items-center">
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'w-10 h-10 rounded-full flex items-center justify-center text-sm font-semibold transition-all',
|
||||||
|
status === 'completed'
|
||||||
|
? 'bg-primary text-primary-foreground'
|
||||||
|
: status === 'active'
|
||||||
|
? 'bg-primary text-primary-foreground ring-4 ring-primary/10'
|
||||||
|
: 'bg-muted text-muted-foreground',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{status === 'completed' ? <Check className="h-5 w-5" /> : step}
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
'text-xs mt-2 font-medium',
|
||||||
|
status === 'pending' ? 'text-muted-foreground/60' : 'text-foreground',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{labels[index]}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{index < 2 && (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'w-16 h-0.5 mx-2 mb-6 rounded-full',
|
||||||
|
getStepStatus(step + 1) !== 'pending' ? 'bg-primary' : 'bg-border',
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
|
||||||
|
<CardContent className="pt-0">
|
||||||
|
{content}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
66
src/components/ui/stepper.tsx
Normal file
66
src/components/ui/stepper.tsx
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { Check } from 'lucide-react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
interface StepperProps {
|
||||||
|
steps: {
|
||||||
|
title: string;
|
||||||
|
description?: string;
|
||||||
|
}[];
|
||||||
|
activeStep: number;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Stepper({ steps, activeStep, className }: StepperProps) {
|
||||||
|
return (
|
||||||
|
<div className={cn('w-full', className)}>
|
||||||
|
<div className="relative flex justify-between">
|
||||||
|
{/* Connection Lines */}
|
||||||
|
<div className="absolute top-5 left-0 right-0 h-0.5 bg-muted -z-10" />
|
||||||
|
<div
|
||||||
|
className="absolute top-5 left-0 h-0.5 bg-primary transition-all duration-500 -z-10"
|
||||||
|
style={{ width: `${(activeStep / (steps.length - 1)) * 100}%` }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{steps.map((step, index) => {
|
||||||
|
const isActive = index === activeStep;
|
||||||
|
const isCompleted = index < activeStep;
|
||||||
|
const isPending = index > activeStep;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={step.title} className="flex flex-col items-center flex-1">
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'w-10 h-10 rounded-full flex items-center justify-center text-sm font-semibold transition-all duration-300 border-2',
|
||||||
|
isActive
|
||||||
|
? 'bg-primary border-primary text-primary-foreground ring-4 ring-primary/10 scale-110'
|
||||||
|
: isCompleted
|
||||||
|
? 'bg-primary border-primary text-primary-foreground'
|
||||||
|
: 'bg-background border-muted text-muted-foreground',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{isCompleted ? <Check className="h-5 w-5" /> : <span>{index + 1}</span>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-4 text-center px-2">
|
||||||
|
<p
|
||||||
|
className={cn(
|
||||||
|
'text-sm font-bold transition-colors',
|
||||||
|
isActive ? 'text-foreground' : 'text-muted-foreground',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{step.title}
|
||||||
|
</p>
|
||||||
|
{step.description && (
|
||||||
|
<p className="text-[11px] text-muted-foreground mt-1 line-clamp-1 max-w-[120px] mx-auto hidden md:block">
|
||||||
|
{step.description}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ export const ROUTES = {
|
|||||||
PACKAGE: '/package',
|
PACKAGE: '/package',
|
||||||
CHAINAGE: '/chainage',
|
CHAINAGE: '/chainage',
|
||||||
ACCOUNT: '/account',
|
ACCOUNT: '/account',
|
||||||
NEW_ANALYSIS: '/new-analysis',
|
|
||||||
UPLOAD: '/upload',
|
UPLOAD: '/upload',
|
||||||
RESULTS: '/results',
|
RESULTS: '/results',
|
||||||
} as const;
|
} as const;
|
||||||
|
|||||||
Reference in New Issue
Block a user