|
1 | 1 | <script lang="ts"> |
2 | 2 | import { getRelativeTimeDisplay } from '$lib/utils/dateUtils'; |
3 | | - import type { EventWithCoordinates } from '$lib/stores/pins'; |
4 | 3 | import type { Map as MaplibreMap } from 'maplibre-gl'; |
5 | 4 | import FloatingPanel from './FloatingPanel.svelte'; |
| 5 | + import type { EventsResponse } from '$lib/pocketbase/generated-types'; |
| 6 | + import { onDestroy, onMount } from 'svelte'; |
| 7 | + import { eventsStore } from '$lib/stores/events'; |
6 | 8 |
|
7 | 9 | export let map: MaplibreMap | undefined; |
8 | | - export let pins: EventWithCoordinates[] = []; |
9 | 10 | export let collapsed = true; |
| 11 | + let events: EventsResponse[] = []; |
| 12 | + let unsubscribe: () => void; |
10 | 13 |
|
11 | | - // Sort events by date (closest first) |
12 | | - $: sortedEvents = [...pins].sort((a, b) => { |
13 | | - const dateA = new Date(a.begin); |
14 | | - const dateB = new Date(b.begin); |
15 | | - return dateA.getTime() - dateB.getTime(); |
| 14 | + // Subscribe to events store |
| 15 | + onMount(() => { |
| 16 | + unsubscribe = eventsStore.subscribeEventsForBounds((value) => { |
| 17 | + events = value; |
| 18 | + }); |
16 | 19 | }); |
17 | 20 |
|
| 21 | + onDestroy(() => { |
| 22 | + if (unsubscribe) unsubscribe(); |
| 23 | + }); |
| 24 | +
|
| 25 | + // Group events by Kinds of events not terminated with kind not unknown or not movie |
| 26 | + $: groupedEvents = events. |
| 27 | + filter((event) => getRelativeTimeDisplay(event.begin, event.end).status !== 'Terminé'). |
| 28 | + filter((event) => event.kind !== 'unknown' && event.kind !== 'movie'). |
| 29 | + reduce((acc, event) => { |
| 30 | + acc[event.kind] = [...(acc[event.kind] || []), event]; |
| 31 | + return acc; |
| 32 | + }, {} as Record<string, EventsResponse[]>); |
| 33 | +
|
18 | 34 | // Function to toggle sidebar and update map padding |
19 | 35 | function toggleSidebar() { |
20 | 36 | collapsed = !collapsed; |
|
43 | 59 | <div class="sidebar {collapsed ? 'collapsed' : ''}"> |
44 | 60 | <FloatingPanel withAnimation scrollable className="sidebar-floating-panel"> |
45 | 61 | <div class="sidebar-inner-content"> |
46 | | - <h2 class="sidebar-title">Événements</h2> |
| 62 | + <h2 class="sidebar-title">Suggestions</h2> |
47 | 63 | <div class="events-list"> |
48 | | - {#if sortedEvents.length > 0} |
49 | | - {#each sortedEvents as event} |
| 64 | + {#if events.length > 0} |
| 65 | + {#each Object.keys(groupedEvents) as kind} |
| 66 | + <h3 class="kind-title">{kind.charAt(0).toUpperCase() + kind.slice(1)}</h3> |
| 67 | + {#each groupedEvents[kind] as event} |
50 | 68 | <button |
51 | 69 | class="event-item" |
52 | 70 | onclick={() => { |
53 | 71 | if (map) { |
54 | | - const coordinates = event.getCoordinates(); |
| 72 | + const coordinates = { lat: event.loc.lat, lon: event.loc.lon }; |
55 | 73 | map.flyTo({ |
56 | 74 | center: coordinates, |
57 | 75 | speed: 1.2, |
58 | 76 | curve: 1.4, |
| 77 | + zoom: 15, |
59 | 78 | essential: true |
60 | 79 | }); |
61 | 80 | } |
62 | 81 | }} |
63 | 82 | > |
| 83 | + {#if event.img} |
| 84 | + <img src={event.img} alt={event.name} class="event-img" /> |
| 85 | + {/if} |
64 | 86 | <div class="event-name">{event.name}</div> |
65 | | - <div class="event-time">{getRelativeTimeDisplay(event.begin, event.end)}</div> |
| 87 | + <div class="event-time">{getRelativeTimeDisplay(event.begin, event.end).status}</div> |
66 | 88 | </button> |
67 | 89 | {/each} |
| 90 | + {/each} |
68 | 91 | {:else} |
69 | 92 | <div class="no-events-message"> |
70 | 93 | Aucun évènement dans cette zone |
|
262 | 285 | } |
263 | 286 | } |
264 | 287 |
|
| 288 | + .kind-title { |
| 289 | + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; |
| 290 | + font-size: 20px; |
| 291 | + font-weight: 700; |
| 292 | + color: #000; |
| 293 | + } |
| 294 | +
|
265 | 295 | .event-item:hover { |
266 | 296 | background-color: rgba(255, 255, 255, 0.7); |
267 | 297 | transform: translateY(-2px) scale(1.01); |
|
273 | 303 | background-color: rgba(255, 255, 255, 0.8); |
274 | 304 | } |
275 | 305 |
|
| 306 | + .event-img { |
| 307 | + display: inline-block; |
| 308 | + width: 20%; |
| 309 | + } |
| 310 | +
|
276 | 311 | .event-name { |
| 312 | + display: inline-block; |
| 313 | + width: 60%; |
277 | 314 | font-weight: 600; |
278 | 315 | font-size: 17px; |
279 | 316 | margin-bottom: 10px; |
|
321 | 358 | animation: fadeIn 0.4s ease-out; |
322 | 359 | transition: all 0.3s ease; |
323 | 360 | } |
| 361 | +
|
324 | 362 | </style> |
0 commit comments