Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/course/handouts/handout-student-list.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { redux } from "@cocalc/frontend/app-framework";6import { useMemo } from "react";7import ScrollableList from "@cocalc/frontend/components/scrollable-list";8import { cmp, trunc_middle } from "@cocalc/util/misc";9import { UserMap } from "../../todo-types";10import { CourseActions } from "../actions";11import { CourseStore, HandoutRecord, StudentsMap } from "../store";12import * as util from "../util";13import { StudentHandoutInfoHeader } from "./handout-info-header";14import { StudentHandoutInfo } from "./handouts-info-panel";1516interface StudentListForHandoutProps {17frame_id?: string;18name: string;19user_map: UserMap;20students: StudentsMap;21handout: HandoutRecord;22actions: CourseActions;23}2425export function StudentListForHandout({26frame_id,27name,28user_map,29students,30handout,31actions,32}: StudentListForHandoutProps) {33const student_list = useMemo(() => {34const v0: any[] = util.immutable_to_list(students, "student_id");3536// Remove deleted students37const v1: any[] = [];38for (const x of v0) {39if (!x.deleted) v1.push(x);40const user = user_map.get(x.account_id);41if (user != null) {42const first_name = user.get("first_name", "");43const last_name = user.get("last_name", "");44x.sort = (last_name + " " + first_name).toLowerCase();45} else if (x.email_address != null) {46x.sort = x.email_address.toLowerCase();47}48}49v1.sort((a, b) => cmp(a.sort, b.sort));50const student_list: string[] = v1.map((x) => x.student_id);51return student_list;52}, [students, user_map]);5354function get_store(): CourseStore {55const store = redux.getStore(name);56if (store == null) throw Error("store must be defined");57return store as unknown as CourseStore;58}5960function render_students() {61return (62<ScrollableList63virtualize64rowCount={student_list.length}65rowRenderer={({ key }) => render_student_info(key)}66rowKey={(index) => student_list[index]}67cacheId={`course-handout-${handout.get("handout_id")}-${68actions.name69}-${frame_id}`}70/>71);72}7374function render_student_info(student_id: string) {75const info = get_store().student_handout_info(76student_id,77handout.get("handout_id"),78);79return (80<StudentHandoutInfo81key={student_id}82actions={actions}83info={info}84title={trunc_middle(get_store().get_student_name(student_id), 40)}85/>86);87}8889return (90<div style={{ height: "70vh", display: "flex", flexDirection: "column" }}>91<StudentHandoutInfoHeader key="header" title="Student" />92{render_students()}93</div>94);95}969798