-
-
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
18 changed files
with
400 additions
and
145 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import Router from 'next/router'; | ||
import { | ||
TableHead, | ||
TableRow, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableContainer, | ||
Paper, | ||
} from '@mui/material'; | ||
import { t } from '../../../services/intl'; | ||
import { getAllTicks } from '../../../services/ticks'; | ||
import { TickItem } from './TickItem'; | ||
import { fetchJson } from '../../../services/fetch'; | ||
import { | ||
getOverpassUrl, | ||
overpassGeomToGeojson, | ||
} from '../../../services/overpassSearch'; | ||
import { getApiId, getShortId } from '../../../services/helpers'; | ||
import { getRouteGrade } from './utils/grades/routeGrade'; | ||
import { ClosePanelButton } from '../../utils/ClosePanelButton'; | ||
import { | ||
PanelContent, | ||
PanelScrollbars, | ||
PanelSidePadding, | ||
PanelWrapper, | ||
} from '../../utils/PanelHelpers'; | ||
import { ClientOnly } from '../../helpers'; | ||
import { useUserSettingsContext } from '../../utils/UserSettingsContext'; | ||
|
||
export const MyTicksPage = () => { | ||
const [myTicksData, setMyTicksData] = useState({}); | ||
const allTicks = getAllTicks(); | ||
const { userSettings } = useUserSettingsContext(); | ||
|
||
const getOverpassData = async () => { | ||
const queryTicks = allTicks | ||
.map(({ osmId }) => { | ||
if (!osmId) return ''; | ||
const { id } = getApiId(osmId); | ||
return `node(${id});`; | ||
}) | ||
.join(''); | ||
const query = `[out:json];(${queryTicks});out body qt;`; | ||
const overpass = await fetchJson(getOverpassUrl(query)); | ||
|
||
const features = overpassGeomToGeojson(overpass); | ||
|
||
const data = Object.keys(features).reduce((acc, key) => { | ||
const feature = features[key]; | ||
return { | ||
...acc, | ||
[getShortId(feature.osmMeta)]: feature.tags, | ||
}; | ||
}, {}); | ||
setMyTicksData(data); | ||
}; | ||
|
||
useEffect(() => { | ||
getOverpassData(); | ||
}, []); | ||
|
||
const handleClose = () => { | ||
Router.push(`/`); | ||
}; | ||
|
||
return ( | ||
<ClientOnly> | ||
<PanelWrapper> | ||
<PanelContent> | ||
<PanelScrollbars> | ||
<ClosePanelButton right onClick={handleClose} /> | ||
<PanelSidePadding> | ||
<h1>{t('my_ticks.title')}</h1> | ||
</PanelSidePadding> | ||
<TableContainer component={Paper}> | ||
<Table size="small"> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell>Name</TableCell> | ||
<TableCell>Grade</TableCell> | ||
<TableCell>Style</TableCell> | ||
<TableCell>Date</TableCell> | ||
<TableCell> </TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{allTicks.map((tick, index) => { | ||
const tickData = myTicksData[tick.osmId]; | ||
const name = tickData?.name; | ||
const grade = getRouteGrade( | ||
tickData, | ||
userSettings['climbing.gradeSystem'], | ||
); | ||
|
||
return ( | ||
<TickItem | ||
key={`${tick.osmId}-${tick.date}`} | ||
name={name} | ||
grade={grade} | ||
gradeSystem={userSettings['climbing.gradeSystem']} | ||
tick={tick} | ||
index={index} | ||
isNameVisible | ||
/> | ||
); | ||
})} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
</PanelScrollbars> | ||
</PanelContent> | ||
</PanelWrapper> | ||
</ClientOnly> | ||
); | ||
}; |
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
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
22 changes: 22 additions & 0 deletions
22
src/components/FeaturePanel/Climbing/RouteList/MyRouteTicks.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,22 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { findTicks } from '../../../../services/ticks'; | ||
import { PanelLabel } from '../PanelLabel'; | ||
import { TickItem } from '../TickItem'; | ||
|
||
const Container = styled.div` | ||
margin-bottom: 20px; | ||
`; | ||
export const MyRouteTicks = ({ osmId }) => { | ||
const ticks = findTicks(osmId); | ||
if (ticks.length === 0) return null; | ||
|
||
return ( | ||
<Container> | ||
<PanelLabel>Ticks:</PanelLabel> | ||
{ticks.map((tick, index) => ( | ||
<TickItem tick={tick} index={index} /> | ||
))} | ||
</Container> | ||
); | ||
}; |
74 changes: 0 additions & 74 deletions
74
src/components/FeaturePanel/Climbing/RouteList/MyTicks.tsx
This file was deleted.
Oops, something went wrong.
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.