Skip to content

Commit

Permalink
Scroll down on thesis row click to show thesis details
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksTeresh committed Sep 30, 2024
1 parent ec3f5b8 commit 033319f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/client/components/ThesisPage/ThesesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const PAGE_SIZE = 25

const ThesesPage = () => {
const apiRef = useGridApiRef()
const footerRef = useRef<HTMLDivElement>(null)
const { t, i18n } = useTranslation()
const { language } = i18n as { language: TranslationLanguage }
const { user, isLoading: loggedInUserLoading } = useLoggedInUser()
Expand Down Expand Up @@ -100,6 +101,12 @@ const ThesesPage = () => {
}
}, [user.thesesTableFilters])

useEffect(() => {
if (rowSelectionModel.length > 0) {
footerRef.current?.scrollIntoView({ behavior: 'smooth' })
}
}, [rowSelectionModel])

const columns: GridColDef<Thesis>[] = [
{
field: 'programId',
Expand Down Expand Up @@ -256,9 +263,9 @@ const ThesesPage = () => {
paginationModel={paginationModel}
onPaginationModelChange={(newModel) => setPaginationModel(newModel)}
rowSelectionModel={rowSelectionModel}
onRowSelectionModelChange={(newSelection: GridRowSelectionModel) =>
onRowSelectionModelChange={(newSelection: GridRowSelectionModel) => {
setRowSelectionModel(newSelection)
}
}}
localeText={
dataGridLocale.components.MuiDataGrid.defaultProps.localeText
}
Expand All @@ -274,6 +281,7 @@ const ThesesPage = () => {
showOnlyOwnTheses,
},
footer: {
footerRef,
rowSelectionModel,
handleEditThesis: initializeThesisEdit,
handleDeleteThesis: initializeThesisDelete,
Expand Down
5 changes: 3 additions & 2 deletions src/client/components/ThesisPage/ViewThesisFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ const PreviewSkeleton = () => (
const ViewThesisFooter = (
props: GridSlotProps['footer'] & ThesisFooterProps
) => {
const { rowSelectionModel, handleEditThesis, handleDeleteThesis } = props
const { rowSelectionModel, footerRef, handleEditThesis, handleDeleteThesis } =
props

const { t } = useTranslation()
const { thesis, isLoading: thesisLoading } = useSingleThesis(
Expand All @@ -366,7 +367,7 @@ const ViewThesisFooter = (

return (
<>
<GridFooter />
<GridFooter ref={footerRef} />
{thesis ? (
<Box sx={{ m: 2 }}>
<Stack
Expand Down
2 changes: 2 additions & 0 deletions src/client/types.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MutableRefObject } from 'react'
import { User } from '@backend/types'
import { GridRowSelectionModel } from '@mui/x-data-grid/models/gridRowSelectionModel'

Expand All @@ -17,6 +18,7 @@ export interface SupervisorSelection {
}

export interface ThesisFooterProps {
footerRef: MutableRefObject<HTMLDivElement>
rowSelectionModel: GridRowSelectionModel[]
handleEditThesis: () => void
handleDeleteThesis: () => void
Expand Down

0 comments on commit 033319f

Please sign in to comment.