@@ -6,8 +6,12 @@ import {
66} from "@/api" ;
77import {
88 Button ,
9+ Fab ,
910 Grid ,
10- Typography
11+ Typography ,
12+ useMediaQuery ,
13+ useTheme ,
14+ Zoom
1115} from "@mui/material" ;
1216import { FC , useEffect , useState } from "react" ;
1317import Timeline from '@mui/lab/Timeline' ;
@@ -27,6 +31,7 @@ import CourseTaskExperimental from "../Tasks/CourseTaskExperimental";
2731import { DotLottieReact } from "@lottiefiles/dotlottie-react" ;
2832import EditIcon from "@mui/icons-material/Edit" ;
2933import ErrorIcon from '@mui/icons-material/Error' ;
34+ import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward' ;
3035import Lodash from "lodash" ;
3136
3237interface ICourseExperimentalProps {
@@ -55,6 +60,13 @@ interface ICourseExperimentalState {
5560export const CourseExperimental : FC < ICourseExperimentalProps > = ( props ) => {
5661 const [ hideDeferred , setHideDeferred ] = useState < boolean > ( false )
5762
63+ // Определяем разрешение экрана пользователя
64+ const theme = useTheme ( ) ;
65+ const isMobile = useMediaQuery ( theme . breakpoints . down ( 'md' ) ) ;
66+
67+ // Состояние для кнопки "Наверх"
68+ const [ showScrollButton , setShowScrollButton ] = useState ( false ) ;
69+
5870 const homeworks = props . homeworks . slice ( ) . reverse ( ) . filter ( x => ! hideDeferred || ! x . isDeferred )
5971 const { isMentor, studentSolutions, isStudentAccepted, userId, selectedHomeworkId, courseFilesInfo} = props
6072
@@ -72,6 +84,28 @@ export const CourseExperimental: FC<ICourseExperimentalProps> = (props) => {
7284 } ) )
7385 } , [ hideDeferred ] )
7486
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+
75109 const initialEditMode = state . initialEditMode
76110 const { id, isHomework} = state . selectedItem
77111
@@ -383,7 +417,10 @@ export const CourseExperimental: FC<ICourseExperimentalProps> = (props) => {
383417 < Grid item xs = { 12 } sm = { 12 } md = { 4 } lg = { 4 } order = { { xs : 2 , sm : 2 , md : 1 , lg : 1 } } >
384418 < Timeline style = { { overflow : 'auto' , paddingLeft : 0 , paddingRight : 8 } }
385419 sx = { {
386- maxHeight : '75vh' ,
420+ maxHeight : {
421+ xs : 'none' ,
422+ md : '75vh'
423+ } ,
387424 '&::-webkit-scrollbar' : {
388425 width : "3px" ,
389426 } ,
@@ -498,5 +535,24 @@ export const CourseExperimental: FC<ICourseExperimentalProps> = (props) => {
498535 < Grid item sx = { { display : { xs : 'flex' , md : 'none' } } } order = { { xs : 3 , sm : 3 } } >
499536 { renderGif ( ) }
500537 </ 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 >
501557 </ Grid >
502558}
0 commit comments