Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error - create trial twice & task card % logic #284

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/taskCard/taskCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ interface TaskCardProps {
const TaskCard = ({ task }: TaskCardProps) => {
const completionRate = useMemo(() => {
const num = parseInt(task.completed_trials as string) || 0;
const calculatedRate = Math.floor((num / (task.trial_count ?? 1)) * 100);
const calculatedRate = Math.floor(
(num / (task.target_max_attempts ?? 1)) * 100
);
return calculatedRate;
}, [task.completed_trials, task.trial_count]);
}, [task.completed_trials, task.target_max_attempts]);

const getDateStyle = () => {
//New or done should be green
Expand All @@ -56,7 +58,9 @@ const TaskCard = ({ task }: TaskCardProps) => {
? "NEW"
: completionRate >= 100
? "DONE"
: `DUE: ${task.due_date ? format(task.due_date, "MM-dd-yyyy") : ""}`}
: `DUE: ${
task.due_date ? format(task.due_date, "MM-dd-yyyy") : "N/A"
}`}
</div>
<div className={$taskCard.profile}>
{/* <Image src={task.profile_img} height={50} width={50} alt="Student's profile picture."/> */}
Expand Down
6 changes: 5 additions & 1 deletion src/pages/benchmarks/[benchmark_id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const BenchmarkPage = () => {
const [currentTrialIdx, setCurrentTrialIdx] = useState(0);
const currentTrial = task?.trials[currentTrialIdx] || null;

const [trialAdded, setTrialAdded] = useState(false);

const hasInputChanged =
currentTrial?.notes !== notesInputValue ||
currentTrial?.success !== successInputValue ||
Expand Down Expand Up @@ -103,6 +105,7 @@ const BenchmarkPage = () => {
// Creates a new data collection instance (if there are none in progress)
useEffect(() => {
if (
!trialAdded &&
!addTrialMutation.isLoading &&
!taskIsLoading &&
task &&
Expand All @@ -115,8 +118,9 @@ const BenchmarkPage = () => {
unsuccess: 0,
notes: "",
});
setTrialAdded(true);
}
}, [task, addTrialMutation, taskIsLoading]);
}, [task, addTrialMutation, taskIsLoading, trialAdded]);

const handleUpdate = (updates: DataUpdate) => {
//Can only update if we're on the most recent trial
Expand Down
Loading