Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Feat/77 event popup #92

Merged
merged 6 commits into from
Mar 28, 2024
Merged

Feat/77 event popup #92

merged 6 commits into from
Mar 28, 2024

Conversation

AitorRD
Copy link
Contributor

@AitorRD AitorRD commented Mar 18, 2024

Añadidio:

  • Integración con la API del backend
  • Añadido el popup del evento con datos y enlace a detalles

@AitorRD AitorRD added code Tasks related to coding frontend Issues related to frontend development labels Mar 18, 2024
@AitorRD AitorRD added this to the S2 milestone Mar 18, 2024
@AitorRD AitorRD linked an issue Mar 18, 2024 that may be closed by this pull request
@AitorRD AitorRD self-assigned this Mar 18, 2024
Copy link

cloudflare-workers-and-pages bot commented Mar 19, 2024

Deploying ocial-app with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4bd6584
Status: ✅  Deploy successful!
Preview URL: https://9100cd01.ocial-app.pages.dev
Branch Preview URL: https://feat-77-event-popup.ocial-app.pages.dev

View logs

@AitorRD AitorRD force-pushed the feat/77-event-popup branch from bc16d05 to bb38934 Compare March 19, 2024 11:17
const { t } = useI18n();
const { data: eventList } = await useEvent(EventApi, 'eventListList')();

console.log(eventList.value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(eventList.value);

Comment on lines 73 to 77
throw new Error(`Categoría desconocida: ${categoryName}`);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto quizás mejor usar console.error para que no pete el componente entero (o manejar la excepción en alguna otra parte de forma elegantemente)

Comment on lines 78 to 86
const categoryIconMap: { [key in CategoryEnum]: string } = {
[CategoryEnum.NUMBER_0]: Azul,
[CategoryEnum.NUMBER_1]: Verde,
[CategoryEnum.NUMBER_2]: Rojo,
[CategoryEnum.NUMBER_3]: Morado,
[CategoryEnum.NUMBER_4]: Amarillo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Para que lo sepas, no bloqueante) Ahora mismo en back está arreglado ya (necesito que se mergee ispp-2324-ocial/backend#56 para que sea 100% automático)

Cuando se actualice, CategoryEnum tendrá las categorías reales y no NUMBER_X

@@ -62,18 +100,29 @@ onBeforeUnmount(() => {
*/
function setMarkers(): void {
if (mapInstance.value) {
for (const mapMarker of props.markers) {
for (const event of eventList.value) {
const category = event.category === undefined ? CategoryEnum.NUMBER_0 : getCategoryEnum(event.category.toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aquí igual en vez de tener esto, puedes hacer que el parámetro categoryName sea opcional (categoryName?: string) y en default devuelves el CategoryEnum.NUMBER_O.

Comment on lines 112 to 125
const popupContent = `
<div>
<strong>${t('Evento')}:</strong> ${event.name}<br>
<strong>${t('Lugar')}:</strong> ${event.place}<br>
<strong>${t('Fecha')}:</strong> ${event.date}<br>
<strong>${t('Hora')}:</strong> ${eventHour}<br>
<strong>${t('Capacidad')}:</strong> ${event.capacity}<br>
<a href="/detalles/${event.id}">${t('Ver detalles')}</a>
</div>
`;

marker([event.latitude, event.longitude], { icon: customIcon })
.addTo(mapInstance.value)
.bindPopup(popupContent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto no hay alguna otra forma en Leaflet de saberlo mediante una clase o algo?

Podríamos envolver todo esto con Teleport:
https://vuejs.org/guide/built-ins/teleport.html#teleport

Y cuando un usuario abra un popup, activar el Teleport al elemento del popup que sea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He añadido he importado ahora un Popup del propio leaflet que se puede añadir y cambiar cuando añadamos las valoraciones se me ocurre

const { t } = useI18n();
const { data: eventList } = await useEvent(EventApi, 'eventListList')();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si ya hacemos el fetch de los datos en el componente padre, por qué es necesario repetirlo aquí?

Comment on lines 115 to 124
const popupContent = document.createElement('div');

popupContent.innerHTML = `
<strong>${t('Evento')}:</strong> ${event.name}<br>
<strong>${t('Lugar')}:</strong> ${event.place}<br>
<strong>${t('Fecha')}:</strong> ${event.date}<br>
<strong>${t('Hora')}:</strong> ${eventHour}<br>
<strong>${t('Capacidad')}:</strong> ${event.capacity}<br>
<a href="/detalles/${event.id}">${t('Ver detalles')}</a>
`;
Copy link
Contributor

@ferferga ferferga Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo esto debe de estar gestionado por Vue, no manual. Hay que extraer la lógica de los popups, de forma que solo pueda haber un marcador activo en todo el mapa y no ilimitados.

  • Guarda en un array todos los marcadores que tenga el mapa y si están activos o inactivos
  • Haz un computed que te derive si uno de los marcadores está activo
  • Haz que el div en el template se monte (v-if) si dicho computed devuelve verdadero
  • Usa template refs para acceder al elemento: https://vuejs.org/guide/essentials/template-refs.html#template-refs
  • Crea un watcher que trackee dicho ref (de esta forma sabes si está montado/desmontado correctamente)
  • Cuando dicho watcher sea verdadero, el ref lo aplicas al popup, cuando sea falso, lo eliminas y ya tienes toda la lógica del popup extraída

Como te puse en los otros comentarios, otra opcion es usar Teleport.

Aunque este hilo no tiene solución (porque el que lo publicó no sabía que el montaje/desmontaje de los componentes de Vue es asíncrono y por eso necesitas un watcher), aquí tienes más idea: https://stackoverflow.com/questions/72548373/using-a-vue3-component-as-a-leaflet-popup

@ferferga ferferga self-assigned this Mar 20, 2024
@ferferga ferferga force-pushed the feat/77-event-popup branch from 0d92b5d to c40570f Compare March 20, 2024 22:29
@AitorRD AitorRD force-pushed the feat/77-event-popup branch from c40570f to 0d92b5d Compare March 28, 2024 16:10
@ferferga ferferga force-pushed the feat/77-event-popup branch from 0d92b5d to 9d248ac Compare March 28, 2024 18:51
ferferga
ferferga previously approved these changes Mar 28, 2024
Copy link
Contributor

@ferferga ferferga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AitorRD Lo mergeo ya pero falta:

  • Adaptar nuevos cambios en la API (concretamente lo de la fecha)
  • Hacer referencia a la ruta final correcta de la página de detalles de eventos
  • Extraer la lógica de obtener la ubicación a una store, haré un issue sobre eso más tarde.
  • Añadir mejores estilos al popup

Also removed unnecessary console.log from login middleware

Signed-off-by: GitHub <[email protected]>
@ferferga ferferga force-pushed the feat/77-event-popup branch from d9ec330 to 4bd6584 Compare March 28, 2024 19:22
Copy link

Quality Gate Passed Quality Gate passed

Issues
3 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@ferferga ferferga enabled auto-merge (rebase) March 28, 2024 19:24
@ferferga ferferga merged commit 9c98462 into develop Mar 28, 2024
11 of 12 checks passed
@ferferga ferferga deleted the feat/77-event-popup branch March 28, 2024 19:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
code Tasks related to coding frontend Issues related to frontend development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FEATURE: Pop-up de Evento
2 participants