-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
322 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '../src/components/App/App'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
256 changes: 256 additions & 0 deletions
256
src/components/FeaturePanel/Climbing/ClimbingGradesTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,256 @@ | ||
import React, { useState } from 'react'; | ||
import { | ||
AppBar, | ||
Chip, | ||
Dialog, | ||
DialogContent, | ||
IconButton, | ||
Paper, | ||
Stack, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableContainer, | ||
TableFooter, | ||
TableHead, | ||
TableRow, | ||
Toolbar, | ||
Tooltip, | ||
Typography, | ||
} from '@mui/material'; | ||
|
||
import { ClimbingCragDialogHeader } from './ClimbingCragDialogHeader'; | ||
import { ClimbingView } from './ClimbingView'; | ||
import { GRADE_SYSTEMS, GRADE_TABLE } from './utils/grades/gradeData'; | ||
import CloseIcon from '@mui/icons-material/Close'; | ||
import zip from 'lodash/zip'; | ||
import styled from '@emotion/styled'; | ||
import { useTheme } from '@emotion/react'; | ||
import { deleteFromArray } from './utils/array'; | ||
import { getGradeSystemName } from './utils/grades/routeGrade'; | ||
import { convertHexToRgba } from '../../utils/colorUtils'; | ||
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; | ||
import { useFeatureContext } from '../../utils/FeatureContext'; | ||
import Router from 'next/router'; | ||
import { getUrlOsmId } from '../../../services/helpers'; | ||
import { useMobileMode } from '../../helpers'; | ||
import { t } from '../../../services/intl'; | ||
|
||
const Thead = styled.thead` | ||
position: sticky; | ||
top: 0px; | ||
background: black; | ||
`; | ||
|
||
const Th = styled.th` | ||
padding: 4px; | ||
`; | ||
// const Table = styled.table``; | ||
|
||
const Td = styled.td<{ $isClicked: boolean }>` | ||
padding: 4px; | ||
cursor: pointer; | ||
${({ $isClicked }) => $isClicked && `background-color: rgba(0, 0, 0, 0.2)`} | ||
&:hover { | ||
background-color: rgba(0, 0, 0, 0.8); | ||
} | ||
`; | ||
|
||
export const ClimbingGradesTable = () => { | ||
const [clickedItem, setClickedItem] = React.useState<{ | ||
row: number | undefined; | ||
column: number | undefined; | ||
}>({ row: undefined, column: undefined }); | ||
const isMobileMode = useMobileMode(); | ||
|
||
const [visibleGradeSystems, setVisibleGradeSystems] = useState( | ||
GRADE_SYSTEMS.reduce((acc, { key }) => ({ ...acc, [key]: true }), {}), | ||
); | ||
|
||
const { feature } = useFeatureContext(); | ||
|
||
const theme = useTheme(); | ||
const handleClose = () => { | ||
Router.push( | ||
`/${feature?.osmMeta ? getUrlOsmId(feature.osmMeta) : ''}${window.location.hash}`, | ||
); | ||
}; | ||
|
||
const transposedTable = zip(...Object.values(GRADE_TABLE)); | ||
|
||
const getRowBackgroundColor = (rowIndex) => { | ||
return clickedItem.row === rowIndex | ||
? convertHexToRgba(theme.palette.primary.main, 0.1) | ||
: 'transparent'; | ||
}; | ||
|
||
const getCellColors = (columnIndex, rowIndex) => { | ||
if (clickedItem.row === rowIndex && clickedItem.column === columnIndex) { | ||
return { | ||
backgroundColor: convertHexToRgba(theme.palette.primary.main, 0.5), | ||
color: theme.palette.getContrastText(theme.palette.primary.main), | ||
fontWeight: 'bold', | ||
}; | ||
} | ||
if (clickedItem.column === columnIndex) { | ||
return { | ||
backgroundColor: convertHexToRgba(theme.palette.primary.main, 0.1), | ||
}; | ||
} | ||
return { backgroundColor: 'transparent' }; | ||
}; | ||
|
||
const columns = Object.keys(visibleGradeSystems).filter( | ||
(gradeSystemKey) => visibleGradeSystems[gradeSystemKey], | ||
); | ||
|
||
const hiddenGradeSystems = GRADE_SYSTEMS.filter( | ||
(gradeSystem) => !visibleGradeSystems[gradeSystem.key], | ||
); | ||
|
||
return ( | ||
<Dialog maxWidth="xl" open onClose={handleClose} fullScreen> | ||
<AppBar position="static" color="transparent"> | ||
<Toolbar> | ||
<Stack | ||
direction="row" | ||
spacing={1} | ||
justifyContent="space-between" | ||
width="100%" | ||
> | ||
<Typography noWrap variant="h6" component="div"> | ||
{t('climbing_grade_table.title')} | ||
</Typography> | ||
<IconButton color="primary" edge="end" onClick={handleClose}> | ||
<CloseIcon fontSize="small" /> | ||
</IconButton> | ||
</Stack> | ||
</Toolbar> | ||
</AppBar> | ||
|
||
<TableContainer component={Paper} sx={{ maxHeight: '100vh' }}> | ||
<Table stickyHeader size="small"> | ||
<TableHead> | ||
<TableRow> | ||
{columns.map((gradeSystemKey) => { | ||
const grade = GRADE_SYSTEMS.find( | ||
(item) => item.key === gradeSystemKey, | ||
); | ||
return ( | ||
<TableCell | ||
sx={{ cursor: 'help' }} | ||
key={`header-cell-${gradeSystemKey}`} | ||
> | ||
<Stack direction="row" spacing={1}> | ||
<Tooltip | ||
arrow | ||
title={grade.description} | ||
placement="right" | ||
> | ||
<Stack direction="row" spacing={2} alignItems="center"> | ||
<Typography variant="caption" fontWeight={900}> | ||
{grade.name} | ||
</Typography> | ||
|
||
<InfoOutlinedIcon | ||
fontSize="small" | ||
color="secondary" | ||
/> | ||
</Stack> | ||
</Tooltip> | ||
<IconButton | ||
size="small" | ||
color="secondary" | ||
onClick={() => | ||
setVisibleGradeSystems({ | ||
...visibleGradeSystems, | ||
[grade.key]: false, | ||
}) | ||
} | ||
> | ||
<CloseIcon /> | ||
</IconButton> | ||
</Stack> | ||
</TableCell> | ||
); | ||
})} | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{transposedTable.map((grades, rowIndex) => ( | ||
<TableRow | ||
key={`row-${rowIndex}`} | ||
sx={{ | ||
'&:last-child td, &:last-child th': { border: 0 }, | ||
backgroundColor: getRowBackgroundColor(rowIndex), | ||
}} | ||
> | ||
{grades | ||
.filter((_, columnIndex) => { | ||
return Object.values(visibleGradeSystems)[columnIndex]; | ||
}) | ||
.map((grade, columnIndex) => ( | ||
<TableCell | ||
key={`cell-${rowIndex}-${columnIndex}-${grade}`} | ||
onClick={() => { | ||
setClickedItem({ | ||
column: columnIndex, | ||
row: rowIndex, | ||
}); | ||
}} | ||
sx={{ | ||
...getCellColors(columnIndex, rowIndex), | ||
fontFamily: 'Courier, monospace', | ||
'&:hover': { | ||
cursor: 'pointer', | ||
backgroundColor: convertHexToRgba( | ||
theme.palette.primary.main, | ||
0.3, | ||
), | ||
}, | ||
}} | ||
> | ||
{grade} | ||
</TableCell> | ||
))} | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
{hiddenGradeSystems.length > 0 && ( | ||
<TableFooter> | ||
<TableRow> | ||
<TableCell colSpan={columns.length}> | ||
<Stack direction="row" spacing={1}> | ||
<Typography | ||
variant="caption" | ||
sx={{ mr: 2, mt: 1, alignSelf: 'center' }} | ||
> | ||
{t('climbing_grade_table.show')} | ||
</Typography> | ||
{hiddenGradeSystems.map((gradeSystem) => { | ||
return ( | ||
<Chip | ||
key={`chip-${gradeSystem.key}`} | ||
size="small" | ||
label={gradeSystem.name} | ||
variant="outlined" | ||
onClick={() => { | ||
setVisibleGradeSystems({ | ||
...visibleGradeSystems, | ||
[gradeSystem.key]: true, | ||
}); | ||
}} | ||
/> | ||
); | ||
})} | ||
</Stack> | ||
</TableCell> | ||
</TableRow> | ||
</TableFooter> | ||
)} | ||
</Table> | ||
</TableContainer> | ||
</Dialog> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.