Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search: show CategoryPanel after search #196

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pages/category/[[...key]].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '../../src/components/App/App';
2 changes: 2 additions & 0 deletions src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { FeaturePreview } from '../FeaturePreview/FeaturePreview';
import { TitleAndMetaTags } from '../../helpers/TitleAndMetaTags';
import { InstallDialog } from '../HomepagePanel/InstallDialog';
import { setIntlForSSR } from '../../services/intl';
import { CategoryPanel } from '../CategoryPanel/CategoryPanel';

const usePersistMapView = () => {
const { view } = useMapStateContext();
Expand Down Expand Up @@ -72,6 +73,7 @@ const IndexWithProviders = () => {
<SearchBox />
<Loading />
{featureShown && <FeaturePanel />}
{router.pathname === '/category/[[...key]]' && <CategoryPanel />}
<HomepagePanel />
{router.pathname === '/install' && <InstallDialog />}
<Map />
Expand Down
81 changes: 81 additions & 0 deletions src/components/CategoryPanel/CategoryPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React from 'react';
import styled from 'styled-components';
import { useRouter } from 'next/router';
import {
List,
ListItem,
ListItemIcon,
ListItemProps,
ListItemText,
Typography,
} from '@material-ui/core';
import {
PanelFooter,
PanelScrollbars,
PanelWrapper,
} from '../utils/PanelHelpers';
import { ClosePanelButton } from '../utils/ClosePanelButton';
import { presets } from '../../services/tagging/data';
import { getPresetTranslation } from '../../services/tagging/translations';

export const Content = styled.div`
padding: 20px 2em 0 2em;

a.maptiler {
display: block;
color: inherit;
text-align: center;
margin: 1em 0;

strong {
color: ${({ theme }) => theme.palette.link};
font-weight: normal;
}

&:hover {
text-decoration: none;

& strong {
text-decoration: underline;
}
}
}
`;

function ListItemLink(props: ListItemProps<'a', { button?: true }>) {
return <ListItem button component="a" {...props} />; // eslint-disable-line react/jsx-props-no-spreading
}

export const CategoryPanel = () => {
const router = useRouter();
const { key } = router.query;
const preset = presets[Array.isArray(key) ? key.join('/') : key];
if (!preset) {
return null;
}

const { presetKey, name } = preset;
const heading = getPresetTranslation(presetKey) ?? name ?? presetKey;

return (
<PanelWrapper>
<PanelScrollbars>
<ClosePanelButton right onClick={() => {}} />
<Content>
<Typography variant="h5" gutterBottom>
Hledání: {heading}
</Typography>
</Content>

<List component="nav" aria-label="main mailbox folders">
<ListItemLink href="/asdf">
<ListItemIcon>AA</ListItemIcon>
<ListItemText primary="Inbox" />
</ListItemLink>
</List>

<PanelFooter />
</PanelScrollbars>
</PanelWrapper>
);
};
4 changes: 4 additions & 0 deletions src/components/SearchBox/onSelectedFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export const onSelectedFactory =
setOverpassLoading(true);
}, 300);

// change url to /category, fetching will be done there
console.log(option.preset.presetForSearch, 'asdf'); // eslint-disable-line no-console
Router.push(`/category/${option.preset.presetForSearch.key}`);

performOverpassSearch(bbox, tags)
.then((geojson) => {
const count = geojson.features.length;
Expand Down
2 changes: 2 additions & 0 deletions src/services/intl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MessagesType, TranslationId } from './types';
import { isBrowser, isServer } from '../components/helpers';
import { getServerIntl } from './intlServer';
import { publishDbgObject } from '../utils';
import { fetchSchemaTranslations } from './tagging/translations'; // eslint-disable-line import/no-cycle

type Values = { [variable: string]: string | number };

Expand Down Expand Up @@ -71,6 +72,7 @@ if (isBrowser()) {
export const setIntlForSSR = async (ctx) => {
if (isServer()) {
setIntl(await getServerIntl(ctx));
await fetchSchemaTranslations(); // TODO import cycle
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/services/tagging/translations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fetchJson } from '../fetch';
import { Field } from './types/Fields';
import { intl } from '../intl';
import { intl } from '../intl'; // eslint-disable-line import/no-cycle
import { publishDbgObject } from '../../utils';

// https://cdn.jsdelivr.net/npm/@openstreetmap/id-tagging-schema@6.1.0/dist/translations/en.min.json
Expand Down