Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LocationService(
if (userEntity.role.value >= RoleType.STAFF.value) {
tokenToLocationMapping[locationDto.token] =
LocationEntity(
id = 0,
id = userEntity.id,
userId = userEntity.id,
userName = userEntity.fullName,
alias = userEntity.alias,
Expand Down Expand Up @@ -113,16 +113,23 @@ class LocationService(
.forEach { token ->
tokenToLocationMapping[token]?.let {
val user = userRepository.findByCmschId(startupPropertyConfig.profileQrPrefix + token)
it.userId = user.get().id
it.userName = user.get().fullName
it.alias = user.get().alias
it.groupName = user.get().groupName
if (user.isPresent) {
val u = user.get()
it.id = u.id
it.userId = u.id
it.userName = u.fullName
it.alias = u.alias
it.groupName = u.groupName
}
}
}
}

fun findLocationsOfGroup(groupId: Int): List<LocationEntity> {
return tokenToLocationMapping.values.filter { it.id == groupId }
return tokenToLocationMapping.values.filter {
val user = userRepository.findById(it.userId)
user.isPresent && user.get().group?.id == groupId
}
Comment on lines 128 to +138
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}

fun findLocationsOfGroupName(group: String): List<MapMarker> {
Expand Down
45 changes: 29 additions & 16 deletions frontend/src/common-components/map/MapContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
import { l } from '@/util/language'
import { type MapDataItemView, MapMarkerShape } from '@/util/views/map.view'
import { Map, Marker, ZoomControl } from 'pigeon-maps'
import { useEffect } from 'react'
import { useEffect, useMemo } from 'react'
import { useGeolocated } from 'react-geolocated'
import { MapMarker } from './MapMarker'

interface MapContentProps {
showUserLocation: boolean
mapData: MapDataItemView[]
className?: string
height?: number
}

export function MapContent({ showUserLocation, mapData }: MapContentProps) {
export function MapContent({ showUserLocation, mapData, className, height = 400 }: MapContentProps) {

Check warning on line 16 in frontend/src/common-components/map/MapContent.tsx

View check run for this annotation

SonarQubeCloud / [cmsch-frontend] SonarCloud Code Analysis

Mark the props of the component as read-only.

See more on https://sonarcloud.io/project/issues?id=kir-dev_cmsch-frontend&issues=AZ6TDOO2C5Shn-UEFcr1&open=AZ6TDOO2C5Shn-UEFcr1&pullRequest=1037
const { toast } = useToast()

const { coords, getPosition, isGeolocationAvailable, isGeolocationEnabled } = useGeolocated({
Expand All @@ -22,7 +24,16 @@
suppressLocationOnMount: true,
watchPosition: showUserLocation
})
const center: [number, number] = coords ? [coords.latitude, coords.longitude] : [47.47303, 19.0531]

const markersCenter = useMemo(() => {
if (!mapData || mapData.length === 0) return null
const latSum = mapData.reduce((acc, curr) => acc + curr.latitude, 0)
const lonSum = mapData.reduce((acc, curr) => acc + curr.longitude, 0)
return [latSum / mapData.length, lonSum / mapData.length] as [number, number]
}, [mapData])

const fallbackCenter: [number, number] = markersCenter ?? [47.47303, 19.0531]
const center: [number, number] = showUserLocation && coords ? [coords.latitude, coords.longitude] : fallbackCenter

useEffect(() => {
if (showUserLocation) getPosition()
Expand All @@ -35,19 +46,21 @@
}, [showUserLocation, isGeolocationAvailable, isGeolocationEnabled, toast])

return (
<Map center={center} provider={OsmProvider} height={400} dprs={[1, 2]}>
<ZoomControl />
{mapData.map((mapDataItem) => (
<Marker hover key={mapDataItem.displayName} width={200} height={3} anchor={[mapDataItem.latitude, mapDataItem.longitude]}>
<MapMarker color={mapDataItem.markerColor} text={mapDataItem.displayName} markerShape={mapDataItem.markerShape} />
</Marker>
))}
{coords && (
<Marker hover width={200} height={3} anchor={[coords.latitude, coords.longitude]}>
<MapMarker color="lightblue" text="Te" markerShape={MapMarkerShape.PERSON} />
</Marker>
)}
</Map>
<div className={className}>
<Map center={center} provider={OsmProvider} height={height} dprs={[1, 2]}>
<ZoomControl />
{mapData.map((mapDataItem) => (
<Marker hover key={mapDataItem.displayName} width={200} height={3} anchor={[mapDataItem.latitude, mapDataItem.longitude]}>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
<MapMarker color={mapDataItem.markerColor} text={mapDataItem.displayName} markerShape={mapDataItem.markerShape} />
</Marker>
))}
{showUserLocation && coords && (
<Marker hover width={200} height={3} anchor={[coords.latitude, coords.longitude]}>
<MapMarker color="lightblue" text="Te" markerShape={MapMarkerShape.PERSON} />
</Marker>
)}
</Map>
</div>
)
}

Expand Down
56 changes: 49 additions & 7 deletions frontend/src/pages/map/map.page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { useConfigContext } from '@/api/contexts/config/ConfigContext'
import { useLocationQuery } from '@/api/hooks/location/useLocationQuery'
import { KirDevLogo } from '@/assets/kir-dev-logo'
import { CmschPage } from '@/common-components/layout/CmschPage'
import { MapContent } from '@/common-components/map/MapContent'
import Markdown from '@/common-components/Markdown'
import { Checkbox } from '@/components/ui/checkbox'
import { Label } from '@/components/ui/label'
import { cn } from '@/lib/utils'
import { l } from '@/util/language'
import { X } from 'lucide-react'
import { useState } from 'react'

export default function MapPage() {
const [showUserLocation, setShowUserLocation] = useState(false)
const [fullScreen, setFullScreen] = useState(false)
Comment on lines 14 to +16
const locationQuery = useLocationQuery()
const component = useConfigContext()?.components?.location
const config = useConfigContext()
const component = config?.components?.location
const devWebsiteUrl = config?.components?.footer?.devWebsiteUrl || 'https://kir-dev.hu/project/cmsch'

return (
<CmschPage title={component?.title || 'Térkép'}>
Expand All @@ -21,13 +27,49 @@
<Markdown text={component.topMessage} />
</div>
)}
<div className="flex items-center space-x-2 my-3">
<Checkbox id="show-user-location" checked={showUserLocation} onCheckedChange={(checked) => setShowUserLocation(!!checked)} />
<Label htmlFor="show-user-location" className="cursor-pointer">
{l('location-show-own')}
</Label>
<div className="flex flex-wrap items-center gap-4 my-3">
<div className="flex items-center space-x-2">
<Checkbox id="show-user-location" checked={showUserLocation} onCheckedChange={(checked) => setShowUserLocation(!!checked)} />
<Label htmlFor="show-user-location" className="cursor-pointer">
{l('location-show-own')}
</Label>
</div>
<div className="flex items-center space-x-2">
<Checkbox id="full-screen" checked={fullScreen} onCheckedChange={(checked) => setFullScreen(!!checked)} />
<Label htmlFor="full-screen" className="cursor-pointer">
{'Teljes képernyő'}
</Label>
Comment on lines +48 to +51
</div>
</div>
<div className={fullScreen ? 'fixed inset-0 z-50 bg-white' : ''}>
{fullScreen && (
<>
<button
onClick={() => setFullScreen(false)}
className="absolute top-4 right-4 z-50 bg-black/50 hover:bg-black/70 text-white p-2 rounded-full shadow-lg transition-colors"
aria-label="Bezárás"
>
<X size={24} />
Comment on lines +57 to +62
</button>
<div
className={cn(
'absolute bottom-4 left-4 z-50 bg-white/80 dark:bg-zinc-950/80',
'backdrop-blur-xs p-2 rounded-lg shadow-md transition-colors flex items-center justify-center'
)}
>
<a href={devWebsiteUrl} target="_blank" rel="noreferrer" className="block hover:opacity-80 transition-opacity">
<KirDevLogo className="w-16 h-auto" />
</a>
</div>
</>
)}
<MapContent
mapData={locationQuery.data ?? []}
showUserLocation={showUserLocation}
className={fullScreen ? 'h-screen w-screen' : ''}
height={fullScreen ? (typeof window !== 'undefined' ? window.innerHeight : 800) : 400}

Check warning on line 70 in frontend/src/pages/map/map.page.tsx

View check run for this annotation

SonarQubeCloud / [cmsch-frontend] SonarCloud Code Analysis

Extract this nested ternary operation into an independent statement.

See more on https://sonarcloud.io/project/issues?id=kir-dev_cmsch-frontend&issues=AZ6TDOOcC5Shn-UEFcrz&open=AZ6TDOOcC5Shn-UEFcrz&pullRequest=1037

Check warning on line 70 in frontend/src/pages/map/map.page.tsx

View check run for this annotation

SonarQubeCloud / [cmsch-frontend] SonarCloud Code Analysis

Prefer `globalThis.window` over `window`.

See more on https://sonarcloud.io/project/issues?id=kir-dev_cmsch-frontend&issues=AZ6TDOOcC5Shn-UEFcr0&open=AZ6TDOOcC5Shn-UEFcr0&pullRequest=1037

Check warning on line 70 in frontend/src/pages/map/map.page.tsx

View check run for this annotation

SonarQubeCloud / [cmsch-frontend] SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=kir-dev_cmsch-frontend&issues=AZ6TDOOcC5Shn-UEFcry&open=AZ6TDOOcC5Shn-UEFcry&pullRequest=1037
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
/>
Comment on lines +76 to +81
</div>
<MapContent mapData={locationQuery.data ?? []} showUserLocation={showUserLocation} />
<p className="mt-4">{l('location-description')}</p>
<p>{l('location-privacy')}</p>
{component?.bottomMessage && (
Expand Down
Loading