Skip to content
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
30 changes: 16 additions & 14 deletions src/api/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ClassPaginationParams } from "@/types/data";
* @returns {Promise<{ data?: { id: string }; error?: string }>} - The response from the server
*/
export const createClass = async (
newClass: ClassInfo
newClass: ClassInfo,
): Promise<{ id?: string; error?: string }> => {
try {
const response = await fetch(`${CLASS_ENDPOINT}/`, {
Expand Down Expand Up @@ -44,7 +44,7 @@ export const createClass = async (

export const updateClass = async (
classId: string,
updates: Partial<ClassInfo>
updates: Partial<ClassInfo>,
): Promise<{ id?: string; error?: string }> => {
try {
const response = await fetch(`${CLASS_ENDPOINT}/${classId}`, {
Expand Down Expand Up @@ -77,7 +77,7 @@ export const updateClass = async (
};

export const deleteClass = async (
classId: string
classId: string,
): Promise<{ success?: boolean; error?: string }> => {
try {
const response = await fetch(`${CLASS_ENDPOINT}/${classId}`, {
Expand Down Expand Up @@ -116,7 +116,7 @@ export const deleteClass = async (
*/
export const getClassesByInstructor = async (
instructorId: string,
includeStudents: boolean = false
includeStudents: boolean = false,
): Promise<{ data?: ClassData[]; error?: string }> => {
try {
const url = new URL(`${CLASS_ENDPOINT}/instructor/${instructorId}`);
Expand Down Expand Up @@ -188,7 +188,7 @@ export async function getClassesbyStudent(studentId: string): Promise<{
*/
export const registerUserClass = async (
userId: string,
classId: string
classId: string,
): Promise<{ success: boolean; error?: string }> => {
try {
const response = await fetch(`${CLASS_ENDPOINT}/register`, {
Expand Down Expand Up @@ -219,7 +219,7 @@ export const registerUserClass = async (

export const unregisterUserClass = async (
userId: string,
classId: string
classId: string,
): Promise<{ success: boolean; error?: string }> => {
try {
const response = await fetch(`${CLASS_ENDPOINT}/unregister`, {
Expand Down Expand Up @@ -252,7 +252,7 @@ export const unregisterUserClass = async (
* @returns {Promise<{ data?: UserActivityLogItem[]; error?: string }>} - The response from the server or an error message.
*/
export async function getClassActivityByInstructorId(
instructorId: string
instructorId: string,
): Promise<{ data: ActivityLogResponse; error?: string }> {
console.log("Fetching class activity for instructor:", instructorId);

Expand All @@ -279,6 +279,8 @@ export async function getClassActivityByInstructorId(
return { data: [] };
}

console.log("Log data", JSON.stringify(logs, null, 2));

return { data: logs };
} catch (err) {
return {
Expand All @@ -298,7 +300,7 @@ export async function getClassActivityByInstructorId(
export const updateStudentEnrollmentStatus = async (
classId: string,
studentId: string,
newStatus: EnrollmentStatus
newStatus: EnrollmentStatus,
): Promise<{ success: boolean; error?: string }> => {
try {
const response = await fetch(`${CLASS_ENDPOINT}/enrollment-status`, {
Expand Down Expand Up @@ -342,7 +344,7 @@ interface PaginatedClassResponse {
}

export async function getAllClasses(
params: ClassPaginationParams = {}
params: ClassPaginationParams = {},
): Promise<{
data?: PaginatedClassResponse;
error?: string;
Expand Down Expand Up @@ -392,7 +394,7 @@ export async function getAllClasses(
export async function updateClassStudentsSettings(
classId: string,
studentIds: string[],
settings: UserSettings
settings: UserSettings,
): Promise<{ data?: boolean; error?: string }> {
try {
const response = await fetch(
Expand All @@ -404,7 +406,7 @@ export async function updateClassStudentsSettings(
studentIds,
settings,
}),
}
},
);

const data = await response.json();
Expand All @@ -429,7 +431,7 @@ export async function getClassById(
includeStudents?: boolean;
userId?: string;
includeAllStatuses?: boolean;
}
},
): Promise<{
data?: ClassData;
error?: string;
Expand All @@ -440,7 +442,7 @@ export async function getClassById(
if (options?.includeStudents) {
searchParams.append(
"includeStudents",
options.includeStudents.toString()
options.includeStudents.toString(),
);
}

Expand All @@ -451,7 +453,7 @@ export async function getClassById(
if (options?.includeAllStatuses) {
searchParams.append(
"includeAllStatuses",
options.includeAllStatuses.toString()
options.includeAllStatuses.toString(),
);
}

Expand Down
39 changes: 5 additions & 34 deletions src/components/TypingLogsDownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type TypingLogData = {
correct_line: string | null;
incorrect_line: string | null;
shown_bug: boolean | null;
bug_percentage: number | null; // Add this field
line_suggestions_group?: {
filename: string | null;
language: string | null;
Expand All @@ -33,9 +34,6 @@ const TypingLogsDownloadButton = ({
}: TypingLogsDownloadButtonProps) => {
const [typingData, setTypingData] = useState<any[]>([]);
const [loading, setLoading] = useState(false);
const [userSettings, setUserSettings] = useState<{
bug_percentage: number;
} | null>(null);

const focusEvents = [
"TYPING",
Expand All @@ -46,32 +44,6 @@ const TypingLogsDownloadButton = ({
"SUGGESTION_GENERATE",
];

useEffect(() => {
const fetchUserSettings = async () => {
if (!userId) return;

try {
const { data, error } = await supabase
.from("user_settings")
.select("bug_percentage")
.eq("user_id", userId)
.single();

if (error) {
console.warn("Error fetching user settings:", error);
setUserSettings({ bug_percentage: 40 }); // Default fallback
} else {
setUserSettings(data);
}
} catch (err) {
console.error("Error fetching user settings:", err);
setUserSettings({ bug_percentage: 40 }); // Default fallback
}
};

fetchUserSettings();
}, [userId]);

useEffect(() => {
const fetchTypingData = async () => {
if (!userId) return;
Expand Down Expand Up @@ -101,6 +73,7 @@ const TypingLogsDownloadButton = ({
correct_line,
incorrect_line,
shown_bug,
bug_percentage,
line_suggestions_group:group_id (
filename,
language
Expand Down Expand Up @@ -152,7 +125,7 @@ const TypingLogsDownloadButton = ({
"Correct Line": log.line_suggestions?.correct_line || "N/A",
"Incorrect Line": log.line_suggestions?.incorrect_line || "N/A",
"Bug Shown": log.line_suggestions?.shown_bug ?? "N/A",
"Bug Percentage": userSettings?.bug_percentage ?? "N/A",
"Bug Percentage": log.line_suggestions?.bug_percentage ?? "N/A", // Changed this line
Filename:
log.line_suggestions?.line_suggestions_group?.filename || "N/A",
Language:
Expand All @@ -168,10 +141,8 @@ const TypingLogsDownloadButton = ({
}
};

if (userSettings !== null) {
fetchTypingData();
}
}, [userId, user, userSettings]);
fetchTypingData();
}, [userId, user]); // Removed userSettings dependency

const filename = user?.pid
? `typing-logs-${user.firstName}-${user.pid}`
Expand Down
2 changes: 1 addition & 1 deletion src/pages/classes/hooks/useClassData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function useClassData(
userId?: string;
includeAllStatuses?: boolean;
enabled?: boolean;
}
},
) {
return useQuery({
queryKey: ["class", classId, options?.includeStudents, options?.userId],
Expand Down
2 changes: 0 additions & 2 deletions src/pages/dashboard/hooks/useClassActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ export const useClassActivity = (
await getClassActivityByInstructorId(instructorId);
if (error || !data) throw new Error(error);

console.log("Fetched class activity logs:", data);

return data as ActivityLogResponse;
},
enabled: !!instructorId,
Expand Down
24 changes: 12 additions & 12 deletions src/pages/dashboard/ui/views/admin/ClassStatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import { Button } from "@/components/ui/button";
const ClassStatView = ({}) => {
const { instructorId, classId } = useParams();

const { data } = useClassData(classId);

console.log("Class data", JSON.stringify(data, null, 2));
const { data } = useClassData(classId, {
includeStudents: true,
includeAllStatuses: false,
});

const [showModel, setShowModel] = useState<boolean>(false);

const { classActivity, progressData, loading } = useClassActivity(
instructorId,
classId,
UserMode.LINE_BY_LINE,
);

console.log("classActivity", JSON.stringify(classActivity, null, 2));

const formatDataForDownload = useMemo(() => {
return classActivity.map((activity, index) => ({
"No.": index + 1,
Expand All @@ -40,6 +40,13 @@ const ClassStatView = ({}) => {
}, [classActivity, classId]);
return (
<div>
<div className="flex justify-end items-center py-4">
<DownloadFormattedFile
data={formatDataForDownload}
filename={`class-activity-all-${new Date().toISOString().split("T")[0]}`}
/>
</div>

<div className="flex justify-between items-center mb-6 border-b pb-3">
<h1 className="text-4xl md:text-5xl font-extrabold text-text leading-tight">
{data?.classTitle}
Expand Down Expand Up @@ -67,13 +74,6 @@ const ClassStatView = ({}) => {
showLearningProgress={false}
/>

<div className="flex justify-end items-center pt-6">
<DownloadFormattedFile
data={formatDataForDownload}
filename={`class-activity-all-${new Date().toISOString().split("T")[0]}`}
/>
</div>

{showModel && data && (
<ClassDetailsCard
classData={data}
Expand Down
3 changes: 2 additions & 1 deletion src/types/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const ACCEPT_EVENTS = [
"SUGGESTION_ACCEPT",
"SUGGESTION_LINE_ACCEPT",
"SUGGESTION_SELECTION_ACCEPT",
"SUGGESTION_TAB_ACCEPT",
];

export const REJECT_EVENTS = ["SUGGESTION_REJECT", "SUGGESTION_LINE_REJECT"];
Expand All @@ -17,7 +18,7 @@ export const getEventsForMode = (mode: UserMode) => {
};
case UserMode.LINE_BY_LINE:
return {
accept: ["SUGGESTION_LINE_ACCEPT"],
accept: ["SUGGESTION_LINE_ACCEPT", "SUGGESTION_TAB_ACCEPT"],
reject: ["SUGGESTION_LINE_REJECT"],
};
case UserMode.CODE_SELECTION:
Expand Down