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

574 display images on map #592

Merged
merged 23 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dd38ae0
add basic map with images for location tags to discover view
LinoH5 Jun 26, 2023
64c7c3b
cobine sub locations instead of not showing them
LinoH5 Jun 26, 2023
17a1284
Merge remote-tracking branch 'origin/staging' into 574-display-images…
LinoH5 Jun 26, 2023
9e22594
fix saving tab selection in local storage
LinoH5 Jun 28, 2023
a4fe63e
prevent map from overlaying bottom bar on mobile
LinoH5 Jun 28, 2023
d88628f
add support for full size map
LinoH5 Jun 28, 2023
589ce35
reduce duplicate code, internationalization
LinoH5 Jun 28, 2023
548d8af
allow to zoom deeper into map
LinoH5 Jul 1, 2023
eb0d9de
store map zoom and center in history, to restore map state
LinoH5 Jul 1, 2023
741a121
Merge remote-tracking branch 'origin/staging' into 574-display-images…
LinoH5 Jul 2, 2023
0156f22
remove duplicate coordinates attribute in FlatTag interface
LinoH5 Jul 2, 2023
fa96130
refactoring
LinoH5 Jul 2, 2023
c22b995
try to fix tests
LinoH5 Jul 2, 2023
86b81b0
try to fix last failing test
LinoH5 Jul 2, 2023
f064c24
requested changes
LinoH5 Jul 2, 2023
387e1e7
custom resover stuff
LinoH5 Jul 3, 2023
49c2fde
fix fetching error
LinoH5 Jul 4, 2023
bb3952a
fix something-went-wrong message being shown for a split second
LinoH5 Jul 4, 2023
6188b4b
requested change remove unnecessary line of code
LinoH5 Jul 4, 2023
5169190
Merge remote-tracking branch 'origin/staging' into 574-display-images…
LinoH5 Jul 4, 2023
6951a5e
fix loading of decades
LinoH5 Jul 4, 2023
114ebfd
fix test
LinoH5 Jul 4, 2023
443d83b
fix tests
LinoH5 Jul 5, 2023
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
5 changes: 3 additions & 2 deletions projects/bp-gallery/cypress/e2e/discover.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ describe('Discover View', () => {
});

it('shows "Orte" tag overview', () => {
cy.get('.overview-selection-container:eq(1)').contains('Orte').click();
// check for basic components (title, show more button)
cy.get('.overview-container:eq(3)')
cy.get('.overview-selection-container:eq(1)')
.children()
.should('contain.text', 'Orte')
.and('contain.text', 'Mehr anzeigen');

// check if it contains first 6 verified locations
cy.get('.overview-container:eq(3) .overview-collection-grid-container .items')
cy.get('.overview-selection-container:eq(1) .overview-collection-grid-container .items')
.should('contain.text', 'VERIFIZIERTER TESTORT 1')
.and('contain.text', 'VERIFIZIERTER TESTORT 2')
.and('contain.text', 'VERIFIZIERTER TESTORT 3')
Expand Down
7 changes: 5 additions & 2 deletions projects/bp-gallery/cypress/e2e/show-more.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ describe('Navigation to Show More View from Discover View', () => {
});

it('works for "Orte"', () => {
cy.get('.overview-container:contains(Orte)').contains('Mehr anzeigen').click();
cy.get('.overview-selection-container:eq(1)').contains('Orte').click();
cy.get('.overview-selection-container:contains(Orte)').contains('Mehr anzeigen').click();
urlIs('/show-more/location');
});

it('works for single locations', () => {
cy.get('.overview-selection-container:eq(1)').contains('Orte').click();
// IDs of the six locations shown in tag overview
const targetIDs = [7, 8, 9, 10, 11, 13];
// iterate over the six locations shown in tag overview
//for (const targetID of targetIDs) {
targetIDs.forEach((targetID, index) => {
cy.get(
`.overview-container:contains(Orte) .overview-collection-grid-container .items .item:eq(${index})`
`.overview-selection-container:contains(Orte) .overview-collection-grid-container .items .item:eq(${index})`
).click();
urlIs(`/show-more/location/${targetID}`);
cy.go(-1); // is a bit faster using cy.go(-1) instead of cy.visit('/discover)
Expand All @@ -57,6 +59,7 @@ describe('Navigation to Show More View from Discover View', () => {
});

it('works for single keywords', () => {
cy.scrollTo('bottom');
// IDs of the six keywords shown in tag overview
const targetIDs = [9, 10, 11, 13, 14, 15];
// iterate over the six keywords shown in tag overview
Expand Down
3 changes: 3 additions & 0 deletions projects/bp-gallery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@sentry/react": "^7.24.2",
"@tailwindcss/line-clamp": "^0.4.2",
"@types/apollo-upload-client": "^17.0.2",
"@types/leaflet.markercluster": "^1.5.1",
"apollo-upload-client": "^17.0.0",
"bp-graphql": "../bp-graphql",
"dayjs": "^1.11.7",
Expand All @@ -32,6 +33,7 @@
"isomorphic-dompurify": "^0.24.0",
"jodit-react": "^1.3.31",
"leaflet": "^1.9.3",
"leaflet.markercluster": "^1.5.3",
"lodash": "^4.17.21",
"meilisearch": "^0.33.0",
"nanoid": "^4.0.2",
Expand All @@ -46,6 +48,7 @@
"react-html-parser": "^2.0.2",
"react-i18next": "^11.13.0",
"react-leaflet": "^4.2.1",
"react-leaflet-cluster": "^2.1.0",
"react-perfect-scrollbar": "^1.5.8",
"react-router-config": "^5.1.1",
"react-router-dom": "^5.3.0",
Expand Down
35 changes: 18 additions & 17 deletions projects/bp-gallery/src/components/common/OverviewContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { MobileContext } from '../provider/MobileProvider';
export interface OverviewContainerTab {
title: string;
icon: ReactElement<IconProps>;
desktopText?: string;
content: ReactElement;
}

Expand All @@ -18,20 +17,20 @@ export enum OverviewContainerPosition {

type SelectedTabsData = {
start?: number;
discover?: number;
discover?: { [tabID: string]: number | undefined };
archives?: { [archiveID: string]: number | undefined };
};

const OverviewContainer = ({
tabs,
defaultTabIndex = 0,
overviewPosition,
archiveID,
tabID,
}: {
tabs: OverviewContainerTab[];
defaultTabIndex?: number;
overviewPosition: OverviewContainerPosition;
archiveID?: string;
tabID?: string;
}) => {
const { isMobile } = useContext(MobileContext);
const [selectedTabs, setSelectedTabs] = useStorageState<SelectedTabsData>(
Expand All @@ -40,34 +39,36 @@ const OverviewContainer = ({
localStorage
);

const tabIndex = useMemo(
() =>
overviewPosition === OverviewContainerPosition.ARCHIVE_VIEW
? archiveID
? (selectedTabs[overviewPosition] ?? { [archiveID]: defaultTabIndex })[archiveID] ??
const tabIndex = useMemo(() => {
const temporaryTabIndex =
overviewPosition !== OverviewContainerPosition.START_VIEW
? tabID
? (selectedTabs[overviewPosition] ?? { [tabID]: defaultTabIndex })[tabID] ??
defaultTabIndex
: defaultTabIndex
: selectedTabs[overviewPosition] ?? defaultTabIndex,
[overviewPosition, archiveID, selectedTabs, defaultTabIndex]
);
: selectedTabs[overviewPosition] ?? defaultTabIndex;
return 0 <= temporaryTabIndex && temporaryTabIndex < tabs.length
? temporaryTabIndex
: defaultTabIndex;
}, [overviewPosition, tabID, selectedTabs, defaultTabIndex, tabs.length]);

const setTabIndex = useCallback(
(tabIndex: number) => {
if (overviewPosition !== OverviewContainerPosition.ARCHIVE_VIEW) {
if (overviewPosition === OverviewContainerPosition.START_VIEW) {
setSelectedTabs(selectedTabs => ({ ...selectedTabs, [overviewPosition]: tabIndex }));
return;
}
if (archiveID) {
if (tabID) {
setSelectedTabs(selectedTabs => ({
...selectedTabs,
[overviewPosition]: {
...selectedTabs[overviewPosition],
[archiveID]: tabIndex,
[tabID]: tabIndex,
},
}));
}
},
[overviewPosition, archiveID, setSelectedTabs]
[overviewPosition, tabID, setSelectedTabs]
);
const clampedTabIndex = Math.min(tabIndex, tabs.length - 1);
return (
Expand All @@ -83,7 +84,7 @@ const OverviewContainer = ({
>
{tabs.map((tab, index) => (
<Tooltip key={index} title={tab.title}>
<Tab icon={isMobile ? tab.icon : tab.desktopText ?? tab.title} />
{isMobile ? <Tab icon={tab.icon} /> : <Tab label={tab.title} />}
</Tooltip>
))}
</Tabs>
Expand Down
74 changes: 74 additions & 0 deletions projects/bp-gallery/src/components/common/PictureMap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { LatLng, Map } from 'leaflet';
import { useMemo, useRef, useState } from 'react';
import { useSimplifiedQueryResponseData } from '../../graphql/queryUtils';
import { useVisit } from '../../helpers/history';
import useGetTagsWithThumbnail from '../../hooks/get-tags-with-thumbnail.hook';
import { FlatPicture, FlatTag, TagType, Thumbnail } from '../../types/additionalFlatTypes';
import Loading from './Loading';
import PictureMapView from './PictureMapView';

export const BAD_HARZBURG_COORDINATES = new LatLng(51.8392573, 10.5279953);

Check warning on line 10 in projects/bp-gallery/src/components/common/PictureMap.tsx

View workflow job for this annotation

GitHub Actions / Lint bp-gallery (14.x)

Fast refresh only works when a file only export components. Use a new file to share constant or functions between components

Check warning on line 10 in projects/bp-gallery/src/components/common/PictureMap.tsx

View workflow job for this annotation

GitHub Actions / Run E2E Tests (16.x)

Fast refresh only works when a file only export components. Use a new file to share constant or functions between components

Check warning on line 10 in projects/bp-gallery/src/components/common/PictureMap.tsx

View workflow job for this annotation

GitHub Actions / Run E2E Tests (16.x)

Fast refresh only works when a file only export components. Use a new file to share constant or functions between components
LinoH5 marked this conversation as resolved.
Show resolved Hide resolved

const PictureMap = () => {
const { location } = useVisit();

const initialMapValues = useMemo(() => {
return location.state?.mapState ?? { center: BAD_HARZBURG_COORDINATES, zoom: 10 };
}, [location.state?.mapState]);

const [isMaximized, setIsMaximized] = useState<boolean>(location.state?.open ?? false);
const map = useRef<Map>(null);

const { data, loading } = useGetTagsWithThumbnail(
LinoH5 marked this conversation as resolved.
Show resolved Hide resolved
{},
{},
TagType.LOCATION,
['name:asc'],
undefined,
'cache-first',
true
);

const flattened = useSimplifiedQueryResponseData(data);
const flattenedTags:
| (FlatTag & {
thumbnail: Thumbnail[];
pictures: FlatPicture[];
verified_pictures: FlatPicture[];
})[]
LinoH5 marked this conversation as resolved.
Show resolved Hide resolved
| undefined = flattened ? Object.values(flattened)[0] : undefined;

const localMap = useMemo(
() => (
<PictureMapView
isMaximized={isMaximized}
setIsMaximized={setIsMaximized}
initialMapValues={{
center: map.current?.getCenter() ?? initialMapValues.center,
zoom: map.current?.getZoom() ?? initialMapValues.zoom,
}}
locations={flattenedTags}
widthStyle='w-full'
heightStyle={isMaximized ? 'h-full' : 'h-[500px]'}
map={map}
/>
),
[flattenedTags, initialMapValues.center, initialMapValues.zoom, isMaximized]
);

if (loading) {
return <Loading />;
} else {
return (
<>
{isMaximized ? (
<div className='w-full h-full overflow-hidden fixed left-0 top-0 z-[999]'>{localMap}</div>
) : (
localMap
)}
</>
);
}
};

export default PictureMap;
Loading
Loading