mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-22 23:17:09 +00:00
added expired solution bar
This commit is contained in:
@@ -9,6 +9,8 @@ import FileSolution from './components/FileSolution';
|
||||
import CodeSolution from './components/CodeSolution';
|
||||
import ActionButtons from './components/ActionButtons';
|
||||
import SolutionHistorySheet from './components/SolutionHistorySheet';
|
||||
import { AlertTriangle, ArrowRight } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
interface TaskSolutionProps {
|
||||
task: Task;
|
||||
@@ -17,6 +19,7 @@ interface TaskSolutionProps {
|
||||
selectedFile: File | null;
|
||||
setSelectedFile: (file: File | null) => void;
|
||||
onSubmit: () => void;
|
||||
isSubmitting?: boolean;
|
||||
}
|
||||
|
||||
const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||
@@ -26,6 +29,7 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||
selectedFile,
|
||||
setSelectedFile,
|
||||
onSubmit,
|
||||
isSubmitting = false
|
||||
}) => {
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const [isHistoryOpen, setIsHistoryOpen] = useState(false);
|
||||
@@ -41,6 +45,16 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||
});
|
||||
|
||||
const solutionHistory = solutionsQuery.data || [];
|
||||
|
||||
const getLatestSolution = () => {
|
||||
return solutionHistory.length > 0 ? solutionHistory[solutionHistory.length - 1] : null;
|
||||
};
|
||||
|
||||
const isOutdatedSolution = () => {
|
||||
if (!displayedSolution || solutionHistory.length === 0) return false;
|
||||
const latestSolution = getLatestSolution();
|
||||
return latestSolution?.id !== displayedSolution.id;
|
||||
};
|
||||
|
||||
// Set initial solution to the last one (most recent) when solutions are loaded
|
||||
useEffect(() => {
|
||||
@@ -111,12 +125,19 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||
|
||||
const handleSolutionSelect = (solution: Solution) => {
|
||||
setDisplayedSolution(solution);
|
||||
console.log(displayedSolution)
|
||||
};
|
||||
|
||||
const handleClearExistingFile = () => {
|
||||
setSelectedSolutionUrl(null);
|
||||
};
|
||||
|
||||
// Function to switch to the latest solution
|
||||
const goToLatestSolution = () => {
|
||||
const latestSolution = getLatestSolution();
|
||||
if (latestSolution) {
|
||||
setDisplayedSolution(latestSolution);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="md:w-[500px] flex flex-col gap-4">
|
||||
@@ -128,6 +149,25 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Outdated solution warning */}
|
||||
{isOutdatedSolution() && (
|
||||
<div className="bg-amber-50 border border-amber-200 rounded-lg p-3 flex justify-between items-center">
|
||||
<div className="flex items-center text-amber-800">
|
||||
<AlertTriangle size={18} className="mr-2 text-amber-500" />
|
||||
<span className="font-hse-sans text-sm">Устаревшая посылка</span>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-blue-600 hover:text-blue-700 hover:bg-blue-50 flex items-center"
|
||||
onClick={goToLatestSolution}
|
||||
>
|
||||
<span className="mr-1">К последней</span>
|
||||
<ArrowRight size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{task.type === TaskType.INPUT && (
|
||||
<InputSolution
|
||||
answer={answer}
|
||||
@@ -142,6 +182,7 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||
fileInputRef={fileInputRef}
|
||||
existingFileUrl={selectedSolutionUrl}
|
||||
onClearExistingFile={handleClearExistingFile}
|
||||
isLoading={isSubmitting}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -163,6 +204,7 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||
solutions={solutionHistory}
|
||||
maxPoints={task.points}
|
||||
onSolutionSelect={handleSolutionSelect}
|
||||
currentSolutionId={displayedSolution?.id}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user