11import React from "react" ;
2- import { CourseViewModel , HomeworkViewModel , StatisticsCourseMatesModel } from "../../api/" ;
2+ import { CourseViewModel , HomeworkViewModel , ResultString , StatisticsCourseMatesModel } from "../../api/" ;
33import { Table , TableBody , TableCell , TableContainer , TableHead , TableRow } from "@material-ui/core" ;
44import StudentStatsCell from "../Tasks/StudentStatsCell" ;
5- import { Alert , MenuItem , Select , TextField } from "@mui/material" ;
5+ import { Alert , Button , Grid , MenuItem , Select , TextField } from "@mui/material" ;
66import apiSingleton from "../../api/ApiSingleton" ;
77
88interface IStudentStatsProps {
@@ -16,7 +16,7 @@ interface IStudentStatsProps {
1616interface IStudentStatsState {
1717 searched : string
1818 googleDocUrl : string
19- sheetTitles : string [ ]
19+ sheetTitles : ResultString | undefined
2020}
2121
2222class StudentStats extends React . Component < IStudentStatsProps , IStudentStatsState > {
@@ -25,11 +25,11 @@ class StudentStats extends React.Component<IStudentStatsProps, IStudentStatsStat
2525 this . state = {
2626 searched : "" ,
2727 googleDocUrl : "" ,
28- sheetTitles : [ ]
28+ sheetTitles : undefined
2929 }
30-
3130 }
3231
32+ //TODO: throttling
3333 private handleGoogleDocUrlChange = async ( value : string ) => {
3434 const titles = await apiSingleton . statisticsApi . apiStatisticsGetSheetTitlesPost ( { url : value } )
3535 this . setState ( { googleDocUrl : value , sheetTitles : titles } ) ;
@@ -105,17 +105,46 @@ class StudentStats extends React.Component<IStudentStatsProps, IStudentStatsStat
105105 </ TableBody >
106106 </ Table >
107107 </ TableContainer >
108- < TextField fullWidth label = { "Ссылка на Google Docs" } value = { googleDocUrl }
109- onChange = { event => {
110- event . persist ( )
111- this . handleGoogleDocUrlChange ( event . target . value )
112- } } />
113- { googleDocUrl && < Select
114- labelId = "demo-simple-select-label"
115- id = "demo-simple-select"
116- label = "Course"
117- >
118- { sheetTitles . map ( ( title , i ) => < MenuItem value = { i } > { title } </ MenuItem > ) } </ Select > }
108+ < Grid container spacing = { 1 } style = { { marginTop : 15 } } >
109+ < Grid item >
110+ < Alert severity = "info" variant = { "standard" } >
111+ Для загрузки таблицы необходимо разрешить доступ на редактирование по ссылке для Google Docs
112+ страницы
113+ </ Alert >
114+ </ Grid >
115+ < Grid container item spacing = { 1 } alignItems = { "center" } >
116+ < Grid item >
117+ < TextField size = { "small" } fullWidth label = { "Ссылка на Google Docs" } value = { googleDocUrl }
118+ onChange = { event => {
119+ event . persist ( )
120+ this . handleGoogleDocUrlChange ( event . target . value )
121+ } } />
122+ </ Grid >
123+ { sheetTitles && ! sheetTitles . succeeded && < Grid item >
124+ < Alert severity = "error" >
125+ { sheetTitles ! . errors ! [ 0 ] }
126+ </ Alert >
127+ </ Grid > }
128+ { sheetTitles && sheetTitles . value && sheetTitles . value . length > 0 && < Grid item >
129+ < Select
130+ size = { "small" }
131+ id = "demo-simple-select"
132+ label = "Sheet"
133+ value = { 0 }
134+ >
135+ { sheetTitles . value . map ( ( title , i ) => < MenuItem value = { i } > { title } </ MenuItem > ) }
136+ </ Select >
137+ </ Grid > }
138+ { sheetTitles && sheetTitles . succeeded && < Grid item >
139+ < Button fullWidth
140+ variant = "text"
141+ color = "primary"
142+ type = "button" >
143+ Загрузить
144+ </ Button >
145+ </ Grid > }
146+ </ Grid >
147+ </ Grid >
119148 </ div >
120149 ) ;
121150 }
0 commit comments