Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/src/packages/frontend/course/handouts/handout-student-list.tsx
Views: 923
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { useIntl } from "react-intl";6import { redux, useRedux } from "@cocalc/frontend/app-framework";7import { useMemo } from "react";8import ScrollableList from "@cocalc/frontend/components/scrollable-list";9import { trunc_middle } from "@cocalc/util/misc";10import type { UserMap } from "../../todo-types";11import type { CourseActions } from "../actions";12import type {13CourseStore,14HandoutRecord,15SortDescription,16StudentsMap,17} from "../store";18import * as util from "../util";19import { StudentHandoutInfoHeader } from "./handout-info-header";20import { StudentHandoutInfo } from "./handouts-info-panel";2122interface StudentListForHandoutProps {23frame_id?: string;24name: string;25user_map: UserMap;26students: StudentsMap;27handout: HandoutRecord;28actions: CourseActions;29}3031export function StudentListForHandout({32frame_id,33name,34user_map,35students,36handout,37actions,38}: StudentListForHandoutProps) {39const intl = useIntl();40const active_student_sort: SortDescription = useRedux(41name,42"active_student_sort",43);44const student_list = useMemo(() => {45const v0 = util.parse_students(students, user_map, redux, intl);4647// Remove deleted students48const v1: any[] = [];49for (const x of v0) {50if (!x.deleted) {51v1.push(x);52}53}54v1.sort(util.pick_student_sorter(active_student_sort.toJS()));55const student_list: string[] = v1.map((x) => x.student_id);56return student_list;57}, [students, user_map, active_student_sort]);5859function get_store(): CourseStore {60const store = redux.getStore(name);61if (store == null) throw Error("store must be defined");62return store as unknown as CourseStore;63}6465function render_students() {66return (67<ScrollableList68virtualize69rowCount={student_list.length}70rowRenderer={({ key }) => render_student_info(key)}71rowKey={(index) => student_list[index]}72cacheId={`course-handout-${handout.get("handout_id")}-${73actions.name74}-${frame_id}`}75/>76);77}7879function render_student_info(student_id: string) {80const info = get_store().student_handout_info(81student_id,82handout.get("handout_id"),83);84return (85<StudentHandoutInfo86key={student_id}87actions={actions}88info={info}89title={trunc_middle(get_store().get_student_name(student_id), 40)}90/>91);92}9394return (95<div style={{ height: "70vh", display: "flex", flexDirection: "column" }}>96<StudentHandoutInfoHeader key="header" title="Student" />97{render_students()}98</div>99);100}101102103