@@ -6,8 +6,12 @@ import {
6
6
} from "@/api" ;
7
7
import {
8
8
Button ,
9
+ Fab ,
9
10
Grid ,
10
- Typography
11
+ Typography ,
12
+ useMediaQuery ,
13
+ useTheme ,
14
+ Zoom
11
15
} from "@mui/material" ;
12
16
import { FC , useEffect , useState } from "react" ;
13
17
import Timeline from '@mui/lab/Timeline' ;
@@ -27,6 +31,7 @@ import CourseTaskExperimental from "../Tasks/CourseTaskExperimental";
27
31
import { DotLottieReact } from "@lottiefiles/dotlottie-react" ;
28
32
import EditIcon from "@mui/icons-material/Edit" ;
29
33
import ErrorIcon from '@mui/icons-material/Error' ;
34
+ import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward' ;
30
35
import Lodash from "lodash" ;
31
36
32
37
interface ICourseExperimentalProps {
@@ -55,6 +60,13 @@ interface ICourseExperimentalState {
55
60
export const CourseExperimental : FC < ICourseExperimentalProps > = ( props ) => {
56
61
const [ hideDeferred , setHideDeferred ] = useState < boolean > ( false )
57
62
63
+ // Определяем разрешение экрана пользователя
64
+ const theme = useTheme ( ) ;
65
+ const isMobile = useMediaQuery ( theme . breakpoints . down ( 'md' ) ) ;
66
+
67
+ // Состояние для кнопки "Наверх"
68
+ const [ showScrollButton , setShowScrollButton ] = useState ( false ) ;
69
+
58
70
const homeworks = props . homeworks . slice ( ) . reverse ( ) . filter ( x => ! hideDeferred || ! x . isDeferred )
59
71
const { isMentor, studentSolutions, isStudentAccepted, userId, selectedHomeworkId, courseFilesInfo} = props
60
72
@@ -72,6 +84,28 @@ export const CourseExperimental: FC<ICourseExperimentalProps> = (props) => {
72
84
} ) )
73
85
} , [ hideDeferred ] )
74
86
87
+ // Обработчик прокрутки страницы
88
+ useEffect ( ( ) => {
89
+ const handleScroll = ( ) => {
90
+ // Показывать кнопку при прокрутке ниже 400px
91
+ const shouldShow = window . scrollY > 400 ;
92
+ if ( shouldShow !== showScrollButton ) {
93
+ setShowScrollButton ( shouldShow ) ;
94
+ }
95
+ } ;
96
+
97
+ window . addEventListener ( 'scroll' , handleScroll ) ;
98
+ return ( ) => window . removeEventListener ( 'scroll' , handleScroll ) ;
99
+ } , [ showScrollButton ] ) ;
100
+
101
+ // Функция прокрутки вверх
102
+ const scrollToTop = ( ) => {
103
+ window . scrollTo ( {
104
+ top : 90 ,
105
+ behavior : 'instant'
106
+ } ) ;
107
+ } ;
108
+
75
109
const initialEditMode = state . initialEditMode
76
110
const { id, isHomework} = state . selectedItem
77
111
@@ -383,7 +417,10 @@ export const CourseExperimental: FC<ICourseExperimentalProps> = (props) => {
383
417
< Grid item xs = { 12 } sm = { 12 } md = { 4 } lg = { 4 } order = { { xs : 2 , sm : 2 , md : 1 , lg : 1 } } >
384
418
< Timeline style = { { overflow : 'auto' , paddingLeft : 0 , paddingRight : 8 } }
385
419
sx = { {
386
- maxHeight : '75vh' ,
420
+ maxHeight : {
421
+ xs : 'none' ,
422
+ md : '75vh'
423
+ } ,
387
424
'&::-webkit-scrollbar' : {
388
425
width : "3px" ,
389
426
} ,
@@ -498,5 +535,24 @@ export const CourseExperimental: FC<ICourseExperimentalProps> = (props) => {
498
535
< Grid item sx = { { display : { xs : 'flex' , md : 'none' } } } order = { { xs : 3 , sm : 3 } } >
499
536
{ renderGif ( ) }
500
537
</ Grid >
538
+
539
+ { /* Кнопка "Наверх" для мобильных устройств */ }
540
+ < Zoom in = { showScrollButton && isMobile } >
541
+ < Fab
542
+ size = "small"
543
+ color = "primary"
544
+ aria-label = "up"
545
+ onClick = { scrollToTop }
546
+ sx = { {
547
+ position : 'fixed' ,
548
+ bottom : 25 ,
549
+ right : 25 ,
550
+ display : { xs : 'flex' , md : 'none' } ,
551
+ zIndex : 1000
552
+ } }
553
+ >
554
+ < ArrowUpwardIcon />
555
+ </ Fab >
556
+ </ Zoom >
501
557
</ Grid >
502
558
}
0 commit comments