-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
424 additions
and
146 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 { TickRow } from './TickRow'; | ||
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>{t('my_ticks.route_name')}</TableCell> | ||
<TableCell>{t('my_ticks.route_grade')}</TableCell> | ||
<TableCell>{t('my_ticks.route_style')}</TableCell> | ||
<TableCell>{t('my_ticks.route_date')}</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 ( | ||
<TickRow | ||
key={`${tick.osmId}-${tick.date}`} | ||
name={name} | ||
grade={grade} | ||
gradeSystem={userSettings['climbing.gradeSystem']} | ||
tick={tick} | ||
index={index} | ||
isNameVisible | ||
isReadOnly | ||
/> | ||
); | ||
})} | ||
</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
23 changes: 23 additions & 0 deletions
23
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,23 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { findTicks } from '../../../../services/ticks'; | ||
import { PanelLabel } from '../PanelLabel'; | ||
import { TickRow } from '../TickRow'; | ||
|
||
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) => ( | ||
<TickRow 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.